aboutsummaryrefslogtreecommitdiff
path: root/syncapi/storage/postgres/backwards_extremities_table.go
diff options
context:
space:
mode:
authorNeil <neilalexanderr@gmail.com>2023-01-19 20:02:32 +0000
committerGitHub <noreply@github.com>2023-01-19 21:02:32 +0100
commit738686ae686004c5efa9fe2096502cdc426c6dd8 (patch)
treee5c8e31aea47167be61aa326982ad9db1a00c15e /syncapi/storage/postgres/backwards_extremities_table.go
parent67f5c5bc1e837bbdee14d7d3388984ed8960528a (diff)
Add `/_dendrite/admin/purgeRoom/{roomID}` (#2662)
This adds a new admin endpoint `/_dendrite/admin/purgeRoom/{roomID}`. It completely erases all database entries for a given room ID. The roomserver will start by clearing all data for that room and then will generate an output event to notify downstream components (i.e. the sync API and federation API) to do the same. It does not currently clear media and it is currently not implemented for SQLite since it relies on SQL array operations right now. Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com> Co-authored-by: Till Faelligen <2353100+S7evinK@users.noreply.github.com>
Diffstat (limited to 'syncapi/storage/postgres/backwards_extremities_table.go')
-rw-r--r--syncapi/storage/postgres/backwards_extremities_table.go27
1 files changed, 17 insertions, 10 deletions
diff --git a/syncapi/storage/postgres/backwards_extremities_table.go b/syncapi/storage/postgres/backwards_extremities_table.go
index 8fc92091..c20d860a 100644
--- a/syncapi/storage/postgres/backwards_extremities_table.go
+++ b/syncapi/storage/postgres/backwards_extremities_table.go
@@ -47,10 +47,14 @@ const selectBackwardExtremitiesForRoomSQL = "" +
const deleteBackwardExtremitySQL = "" +
"DELETE FROM syncapi_backward_extremities WHERE room_id = $1 AND prev_event_id = $2"
+const purgeBackwardExtremitiesSQL = "" +
+ "DELETE FROM syncapi_backward_extremities WHERE room_id = $1"
+
type backwardExtremitiesStatements struct {
insertBackwardExtremityStmt *sql.Stmt
selectBackwardExtremitiesForRoomStmt *sql.Stmt
deleteBackwardExtremityStmt *sql.Stmt
+ purgeBackwardExtremitiesStmt *sql.Stmt
}
func NewPostgresBackwardsExtremitiesTable(db *sql.DB) (tables.BackwardsExtremities, error) {
@@ -59,16 +63,12 @@ func NewPostgresBackwardsExtremitiesTable(db *sql.DB) (tables.BackwardsExtremiti
if err != nil {
return nil, err
}
- if s.insertBackwardExtremityStmt, err = db.Prepare(insertBackwardExtremitySQL); err != nil {
- return nil, err
- }
- if s.selectBackwardExtremitiesForRoomStmt, err = db.Prepare(selectBackwardExtremitiesForRoomSQL); err != nil {
- return nil, err
- }
- if s.deleteBackwardExtremityStmt, err = db.Prepare(deleteBackwardExtremitySQL); err != nil {
- return nil, err
- }
- return s, nil
+ return s, sqlutil.StatementList{
+ {&s.insertBackwardExtremityStmt, insertBackwardExtremitySQL},
+ {&s.selectBackwardExtremitiesForRoomStmt, selectBackwardExtremitiesForRoomSQL},
+ {&s.deleteBackwardExtremityStmt, deleteBackwardExtremitySQL},
+ {&s.purgeBackwardExtremitiesStmt, purgeBackwardExtremitiesSQL},
+ }.Prepare(db)
}
func (s *backwardExtremitiesStatements) InsertsBackwardExtremity(
@@ -106,3 +106,10 @@ func (s *backwardExtremitiesStatements) DeleteBackwardExtremity(
_, err = sqlutil.TxStmt(txn, s.deleteBackwardExtremityStmt).ExecContext(ctx, roomID, knownEventID)
return
}
+
+func (s *backwardExtremitiesStatements) PurgeBackwardExtremities(
+ ctx context.Context, txn *sql.Tx, roomID string,
+) error {
+ _, err := sqlutil.TxStmt(txn, s.purgeBackwardExtremitiesStmt).ExecContext(ctx, roomID)
+ return err
+}