From 566bfae9391a6f0b81c4db9140755937ea78068b Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 12 Oct 2022 11:35:23 +0100 Subject: [PATCH] Tweaks to pagination --- syncapi/routing/routing.go | 7 ++++--- syncapi/storage/postgres/relations_table.go | 4 ++-- syncapi/storage/shared/storage_sync.go | 2 +- syncapi/storage/sqlite3/relations_table.go | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/syncapi/routing/routing.go b/syncapi/routing/routing.go index 3217c72c3..115925942 100644 --- a/syncapi/routing/routing.go +++ b/syncapi/routing/routing.go @@ -45,6 +45,7 @@ func Setup( lazyLoadCache caching.LazyLoadCache, fts *fulltext.Search, ) { + v1mux := csMux.PathPrefix("/v1/").Subrouter() v3mux := csMux.PathPrefix("/{apiversion:(?:r0|v3)}/").Subrouter() // TODO: Add AS support for all handlers below. @@ -110,7 +111,7 @@ func Setup( }), ).Methods(http.MethodGet, http.MethodOptions) - v3mux.Handle("/rooms/{roomId}/relations/{eventId}", + v1mux.Handle("/rooms/{roomId}/relations/{eventId}", httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse { vars, err := httputil.URLDecodeMapValues(mux.Vars(req)) if err != nil { @@ -124,7 +125,7 @@ func Setup( }), ).Methods(http.MethodGet, http.MethodOptions) - v3mux.Handle("/rooms/{roomId}/relations/{eventId}/{relType}", + v1mux.Handle("/rooms/{roomId}/relations/{eventId}/{relType}", httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse { vars, err := httputil.URLDecodeMapValues(mux.Vars(req)) if err != nil { @@ -138,7 +139,7 @@ func Setup( }), ).Methods(http.MethodGet, http.MethodOptions) - v3mux.Handle("/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}", + v1mux.Handle("/rooms/{roomId}/relations/{eventId}/{relType}/{eventType}", httputil.MakeAuthAPI(gomatrixserverlib.Join, userAPI, func(req *http.Request, device *userapi.Device) util.JSONResponse { vars, err := httputil.URLDecodeMapValues(mux.Vars(req)) if err != nil { diff --git a/syncapi/storage/postgres/relations_table.go b/syncapi/storage/postgres/relations_table.go index 0b2be7632..934fddbf0 100644 --- a/syncapi/storage/postgres/relations_table.go +++ b/syncapi/storage/postgres/relations_table.go @@ -50,12 +50,12 @@ const deleteRelationSQL = "" + const selectRelationsInRangeSQL = "" + "SELECT id, room_id, child_event_id, rel_type FROM syncapi_relations" + - " WHERE room_id = $1 AND event_id = $2 AND id >= $3 AND id <= $4" + + " WHERE room_id = $1 AND event_id = $2 AND id > $3 AND id <= $4" + " ORDER BY id DESC LIMIT $5" const selectRelationsByTypeInRangeSQL = "" + "SELECT id, room_id, child_event_id, rel_type FROM syncapi_relations" + - " WHERE room_id = $1 AND event_id = $2 AND rel_type = $3 AND id >= $4 AND id <= $5" + + " WHERE room_id = $1 AND event_id = $2 AND rel_type = $3 AND id > $4 AND id <= $5" + " ORDER BY id DESC LIMIT $6" const selectMaxRelationIDSQL = "" + diff --git a/syncapi/storage/shared/storage_sync.go b/syncapi/storage/shared/storage_sync.go index 19e95d655..a42ceb79d 100644 --- a/syncapi/storage/shared/storage_sync.go +++ b/syncapi/storage/shared/storage_sync.go @@ -636,7 +636,7 @@ func (d *DatabaseTransaction) RelationsFor(ctx context.Context, roomID, eventID, // If there were no entries returned, there were no relations, so stop at this point. if len(entries) == 0 { - return nil, "", "", nil + return clientEvents, "", "", nil } // Otherwise, let's try and work out what sensible prev_batch and next_batch values diff --git a/syncapi/storage/sqlite3/relations_table.go b/syncapi/storage/sqlite3/relations_table.go index e5a1fad62..4f25777ea 100644 --- a/syncapi/storage/sqlite3/relations_table.go +++ b/syncapi/storage/sqlite3/relations_table.go @@ -48,12 +48,12 @@ const deleteRelationSQL = "" + const selectRelationsInRangeSQL = "" + "SELECT id, room_id, child_event_id, rel_type FROM syncapi_relations" + - " WHERE room_id = $1 AND event_id = $2 AND id >= $3 AND id <= $4" + + " WHERE room_id = $1 AND event_id = $2 AND id > $3 AND id <= $4" + " ORDER BY id DESC LIMIT $5" const selectRelationsByTypeInRangeSQL = "" + "SELECT id, room_id, child_event_id, rel_type FROM syncapi_relations" + - " WHERE room_id = $1 AND event_id = $2 AND rel_type = $3 AND id >= $4 AND id <= $5" + + " WHERE room_id = $1 AND event_id = $2 AND rel_type = $3 AND id > $4 AND id <= $5" + " ORDER BY id DESC LIMIT $6" const selectMaxRelationIDSQL = "" +