snc: use local caches for resolving identifiers
Signed-off-by: Sumner Evans <sumner.evans@automattic.com>
This commit is contained in:
@@ -56,6 +56,7 @@ const (
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT (username) DO UPDATE SET entity_id=excluded.entity_id
|
||||
`
|
||||
getByUsernameQuery = "SELECT entity_id FROM telegram_username WHERE LOWER(username)=$1"
|
||||
clearUsernameQuery = `DELETE FROM telegram_username WHERE entity_id=$1`
|
||||
|
||||
// User Phone Number Queries
|
||||
@@ -196,6 +197,14 @@ func (s *ScopedStore) SetUsername(ctx context.Context, userID int64, username st
|
||||
return
|
||||
}
|
||||
|
||||
func (s *ScopedStore) GetUserIDByUsername(ctx context.Context, username string) (userID int64, err error) {
|
||||
err = s.db.QueryRow(ctx, getByUsernameQuery, username).Scan(&userID)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *ScopedStore) GetUserIDByPhoneNumber(ctx context.Context, phoneNumber string) (userID int64, err error) {
|
||||
err = s.db.QueryRow(ctx, getEntityIDForPhoneNumber, phoneNumber).Scan(&userID)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
|
||||
@@ -34,6 +34,7 @@ CREATE TABLE telegram_username (
|
||||
);
|
||||
|
||||
CREATE INDEX telegram_username_entity_idx ON telegram_username (entity_id);
|
||||
CREATE INDEX telegram_username_username_idx ON telegram_username (LOWER(username));
|
||||
|
||||
CREATE TABLE telegram_phone_number (
|
||||
phone_number TEXT NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user