aboutsummaryrefslogtreecommitdiff
path: root/syncapi/storage/postgres
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2022-04-28 16:12:40 +0200
committerGitHub <noreply@github.com>2022-04-28 15:12:40 +0100
commit21ee5b36a41f2cb3960f63ef6f19106d36312aae (patch)
tree6047bef017ef2716eadd59d14deb4d1936415a70 /syncapi/storage/postgres
parent8683ff78b1bee6b7c35e7befb9903c794a17510c (diff)
Limit presence in `/sync` responses (#2394)
* Use filter and limit presence count * More limiting * More limiting * Fix unit test * Also limit presence by last_active_ts * Update query, use "from" as the initial lastPos * Get 1000 presence events, they are filtered later Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Diffstat (limited to 'syncapi/storage/postgres')
-rw-r--r--syncapi/storage/postgres/presence_table.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/syncapi/storage/postgres/presence_table.go b/syncapi/storage/postgres/presence_table.go
index 9f1e37f7..7194afea 100644
--- a/syncapi/storage/postgres/presence_table.go
+++ b/syncapi/storage/postgres/presence_table.go
@@ -17,6 +17,7 @@ package postgres
import (
"context"
"database/sql"
+ "time"
"github.com/matrix-org/dendrite/internal"
"github.com/matrix-org/dendrite/internal/sqlutil"
@@ -72,7 +73,8 @@ const selectMaxPresenceSQL = "" +
const selectPresenceAfter = "" +
" SELECT id, user_id, presence, status_msg, last_active_ts" +
" FROM syncapi_presence" +
- " WHERE id > $1"
+ " WHERE id > $1 AND last_active_ts >= $2" +
+ " ORDER BY id ASC LIMIT $3"
type presenceStatements struct {
upsertPresenceStmt *sql.Stmt
@@ -144,11 +146,12 @@ func (p *presenceStatements) GetMaxPresenceID(ctx context.Context, txn *sql.Tx)
func (p *presenceStatements) GetPresenceAfter(
ctx context.Context, txn *sql.Tx,
after types.StreamPosition,
+ filter gomatrixserverlib.EventFilter,
) (presences map[string]*types.PresenceInternal, err error) {
presences = make(map[string]*types.PresenceInternal)
stmt := sqlutil.TxStmt(txn, p.selectPresenceAfterStmt)
-
- rows, err := stmt.QueryContext(ctx, after)
+ afterTS := gomatrixserverlib.AsTimestamp(time.Now().Add(time.Minute * -5))
+ rows, err := stmt.QueryContext(ctx, after, afterTS, filter.Limit)
if err != nil {
return nil, err
}