aboutsummaryrefslogtreecommitdiff
path: root/syncapi/storage/postgres/current_room_state_table.go
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2021-02-04 12:20:37 +0000
committerGitHub <noreply@github.com>2021-02-04 12:20:37 +0000
commit6e44450cc9b541e5e79b7e601462fd3d3cf35fe5 (patch)
tree51378b118262a7fffad7122fde7b475ff95eb3e4 /syncapi/storage/postgres/current_room_state_table.go
parent6099379ea48cf47f9570e9bc51aba4bb3fa8c066 (diff)
Don't re-request state events that are already in the timeline (#1739)
* Don't request state events if we already have the timeline events (Postgres only) * Rename variable * nocyclo * Add SQLite * Tweaks * Revert query change * Don't dedupe if asking for full state * Update query
Diffstat (limited to 'syncapi/storage/postgres/current_room_state_table.go')
-rw-r--r--syncapi/storage/postgres/current_room_state_table.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/syncapi/storage/postgres/current_room_state_table.go b/syncapi/storage/postgres/current_room_state_table.go
index 77e1e363..ee649c16 100644
--- a/syncapi/storage/postgres/current_room_state_table.go
+++ b/syncapi/storage/postgres/current_room_state_table.go
@@ -84,7 +84,8 @@ const selectCurrentStateSQL = "" +
" AND ( $4::text[] IS NULL OR type LIKE ANY($4) )" +
" AND ( $5::text[] IS NULL OR NOT(type LIKE ANY($5)) )" +
" AND ( $6::bool IS NULL OR contains_url = $6 )" +
- " LIMIT $7"
+ " AND (event_id = ANY($7)) IS NOT TRUE" +
+ " LIMIT $8"
const selectJoinedUsersSQL = "" +
"SELECT room_id, state_key FROM syncapi_current_room_state WHERE type = 'm.room.member' AND membership = 'join'"
@@ -197,6 +198,7 @@ func (s *currentRoomStateStatements) SelectRoomIDsWithMembership(
func (s *currentRoomStateStatements) SelectCurrentState(
ctx context.Context, txn *sql.Tx, roomID string,
stateFilter *gomatrixserverlib.StateFilter,
+ excludeEventIDs []string,
) ([]*gomatrixserverlib.HeaderedEvent, error) {
stmt := sqlutil.TxStmt(txn, s.selectCurrentStateStmt)
rows, err := stmt.QueryContext(ctx, roomID,
@@ -205,6 +207,7 @@ func (s *currentRoomStateStatements) SelectCurrentState(
pq.StringArray(filterConvertTypeWildcardToSQL(stateFilter.Types)),
pq.StringArray(filterConvertTypeWildcardToSQL(stateFilter.NotTypes)),
stateFilter.ContainsURL,
+ pq.StringArray(excludeEventIDs),
stateFilter.Limit,
)
if err != nil {