Actually filter on room_nid; Update comment

This commit is contained in:
Till Faelligen 2023-06-07 14:07:57 +02:00
parent 2006683c6f
commit 50fd515331
No known key found for this signature in database
GPG key ID: ACCDC9606D472758
4 changed files with 7 additions and 5 deletions

View file

@ -204,7 +204,8 @@ type UserRoomKeys interface {
InsertUserRoomPublicKey(ctx context.Context, userID spec.UserID, roomID spec.RoomID, key ed25519.PublicKey) (result ed25519.PublicKey, err error) InsertUserRoomPublicKey(ctx context.Context, userID spec.UserID, roomID spec.RoomID, key ed25519.PublicKey) (result ed25519.PublicKey, err error)
// SelectUserRoomPrivateKey selects the private key for the given user and room combination // SelectUserRoomPrivateKey selects the private key for the given user and room combination
SelectUserRoomPrivateKey(ctx context.Context, userID spec.UserID, roomID spec.RoomID) (key ed25519.PrivateKey, err error) SelectUserRoomPrivateKey(ctx context.Context, userID spec.UserID, roomID spec.RoomID) (key ed25519.PrivateKey, err error)
// SelectUserIDsForPublicKeys selects all userIDs for the requested senderKeys. Returns a map from roomID -> map from publicKey to userID // SelectUserIDsForPublicKeys selects all userIDs for the requested senderKeys. Returns a map from roomID -> map from publicKey to userID.
// If a senderKey can't be found, it is omitted in the result.
SelectUserIDsForPublicKeys(ctx context.Context, publicKeys map[spec.RoomID][]ed25519.PublicKey) (map[spec.RoomID]map[string]string, error) SelectUserIDsForPublicKeys(ctx context.Context, publicKeys map[spec.RoomID][]ed25519.PublicKey) (map[spec.RoomID]map[string]string, error)
} }

View file

@ -51,7 +51,7 @@ const insertUserRoomPublicKeySQL = `
const selectUserRoomKeySQL = `SELECT pseudo_id_key FROM roomserver_user_room_keys WHERE user_nid = $1 AND room_nid = $2` const selectUserRoomKeySQL = `SELECT pseudo_id_key FROM roomserver_user_room_keys WHERE user_nid = $1 AND room_nid = $2`
const selectUserNIDsSQL = `SELECT user_nid, room_nid, pseudo_id_pub_key FROM roomserver_user_room_keys WHERE pseudo_id_pub_key = ANY($1)` const selectUserNIDsSQL = `SELECT user_nid, room_nid, pseudo_id_pub_key FROM roomserver_user_room_keys WHERE room_nid = ANY($1) AND pseudo_id_pub_key = ANY($2)`
type userRoomKeysStatements struct { type userRoomKeysStatements struct {
insertUserRoomPrivateKeyStmt *sql.Stmt insertUserRoomPrivateKeyStmt *sql.Stmt
@ -113,7 +113,7 @@ func (s *userRoomKeysStatements) BulkSelectUserNIDs(ctx context.Context, txn *sq
senders = append(senders, key) senders = append(senders, key)
} }
} }
rows, err := stmt.QueryContext(ctx, pq.Array(senders)) rows, err := stmt.QueryContext(ctx, pq.Array(roomNIDs), pq.Array(senders))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -1733,14 +1733,14 @@ func (d *Database) SelectUserIDsForPublicKeys(ctx context.Context, publicKeys ma
nids = append(nids, nid.EventStateKeyNID) nids = append(nids, nid.EventStateKeyNID)
} }
// get the userIDs // get the userIDs
nidMAP, seErr := d.EventStateKeys(ctx, nids) nidMap, seErr := d.EventStateKeys(ctx, nids)
if seErr != nil { if seErr != nil {
return seErr return seErr
} }
// build the result map (roomID -> map publicKey -> userID) // build the result map (roomID -> map publicKey -> userID)
for publicKey, userRoomKeyPair := range userRoomKeyPairMap { for publicKey, userRoomKeyPair := range userRoomKeyPairMap {
userID := nidMAP[userRoomKeyPair.EventStateKeyNID] userID := nidMap[userRoomKeyPair.EventStateKeyNID]
roomID := rooms[userRoomKeyPair.RoomNID] roomID := rooms[userRoomKeyPair.RoomNID]
resMap, exists := result[roomID] resMap, exists := result[roomID]
if !exists { if !exists {

View file

@ -194,6 +194,7 @@ type UserRoomKeys interface {
// SelectUserRoomPrivateKey selects the private key for the given user and room combination // SelectUserRoomPrivateKey selects the private key for the given user and room combination
SelectUserRoomPrivateKey(ctx context.Context, txn *sql.Tx, userNID types.EventStateKeyNID, roomNID types.RoomNID) (ed25519.PrivateKey, error) SelectUserRoomPrivateKey(ctx context.Context, txn *sql.Tx, userNID types.EventStateKeyNID, roomNID types.RoomNID) (ed25519.PrivateKey, error)
// BulkSelectUserNIDs selects all userIDs for the requested senderKeys. Returns a map from publicKey -> types.UserRoomKeyPair. // BulkSelectUserNIDs selects all userIDs for the requested senderKeys. Returns a map from publicKey -> types.UserRoomKeyPair.
// If a senderKey can't be found, it is omitted in the result.
BulkSelectUserNIDs(ctx context.Context, txn *sql.Tx, senderKeys map[types.RoomNID][]ed25519.PublicKey) (map[string]types.UserRoomKeyPair, error) BulkSelectUserNIDs(ctx context.Context, txn *sql.Tx, senderKeys map[types.RoomNID][]ed25519.PublicKey) (map[string]types.UserRoomKeyPair, error)
} }