diff options
author | Kegsay <kegan@matrix.org> | 2020-07-30 14:52:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-30 14:52:21 +0100 |
commit | a2174d3294841dbdf201bde76de3ffc44399fcbc (patch) | |
tree | 64f5c0d7dee038960941a937dd84631d53c1e9a9 /keyserver/storage/sqlite3/key_changes_table.go | |
parent | 9355fb5ac8c911bdbde6dcc0f279f716d8a8f60b (diff) |
Implement /keys/changes (#1232)
* Implement /keys/changes
And refactor QueryKeyChanges to accept a `to` offset.
* Unbreak tests
* Sort keys when serialising log tokens
Diffstat (limited to 'keyserver/storage/sqlite3/key_changes_table.go')
-rw-r--r-- | keyserver/storage/sqlite3/key_changes_table.go | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/keyserver/storage/sqlite3/key_changes_table.go b/keyserver/storage/sqlite3/key_changes_table.go index b830214d..32721eae 100644 --- a/keyserver/storage/sqlite3/key_changes_table.go +++ b/keyserver/storage/sqlite3/key_changes_table.go @@ -17,7 +17,9 @@ package sqlite3 import ( "context" "database/sql" + "math" + "github.com/Shopify/sarama" "github.com/matrix-org/dendrite/internal" "github.com/matrix-org/dendrite/keyserver/storage/tables" ) @@ -45,7 +47,7 @@ const upsertKeyChangeSQL = "" + // select the highest offset for each user in the range. The grouping by user gives distinct entries and then we just // take the max offset value as the latest offset. const selectKeyChangesSQL = "" + - "SELECT user_id, MAX(offset) FROM keyserver_key_changes WHERE partition = $1 AND offset > $2 GROUP BY user_id" + "SELECT user_id, MAX(offset) FROM keyserver_key_changes WHERE partition = $1 AND offset > $2 AND offset <= $3 GROUP BY user_id" type keyChangesStatements struct { db *sql.DB @@ -76,9 +78,12 @@ func (s *keyChangesStatements) InsertKeyChange(ctx context.Context, partition in } func (s *keyChangesStatements) SelectKeyChanges( - ctx context.Context, partition int32, fromOffset int64, + ctx context.Context, partition int32, fromOffset, toOffset int64, ) (userIDs []string, latestOffset int64, err error) { - rows, err := s.selectKeyChangesStmt.QueryContext(ctx, partition, fromOffset) + if toOffset == sarama.OffsetNewest { + toOffset = math.MaxInt64 + } + rows, err := s.selectKeyChangesStmt.QueryContext(ctx, partition, fromOffset, toOffset) if err != nil { return nil, 0, err } |