diff options
author | Neil <neilalexanderr@gmail.com> | 2023-01-19 20:02:32 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-19 21:02:32 +0100 |
commit | 738686ae686004c5efa9fe2096502cdc426c6dd8 (patch) | |
tree | e5c8e31aea47167be61aa326982ad9db1a00c15e /federationapi/storage | |
parent | 67f5c5bc1e837bbdee14d7d3388984ed8960528a (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 'federationapi/storage')
-rw-r--r-- | federationapi/storage/interface.go | 2 | ||||
-rw-r--r-- | federationapi/storage/shared/storage.go | 15 |
2 files changed, 17 insertions, 0 deletions
diff --git a/federationapi/storage/interface.go b/federationapi/storage/interface.go index 276cd9a5..2b4d905f 100644 --- a/federationapi/storage/interface.go +++ b/federationapi/storage/interface.go @@ -71,4 +71,6 @@ type Database interface { GetNotaryKeys(ctx context.Context, serverName gomatrixserverlib.ServerName, optKeyIDs []gomatrixserverlib.KeyID) ([]gomatrixserverlib.ServerKeys, error) // DeleteExpiredEDUs cleans up expired EDUs DeleteExpiredEDUs(ctx context.Context) error + + PurgeRoom(ctx context.Context, roomID string) error } diff --git a/federationapi/storage/shared/storage.go b/federationapi/storage/shared/storage.go index 1e1ea9e1..6cda5572 100644 --- a/federationapi/storage/shared/storage.go +++ b/federationapi/storage/shared/storage.go @@ -259,3 +259,18 @@ func (d *Database) GetNotaryKeys( }) return sks, err } + +func (d *Database) PurgeRoom(ctx context.Context, roomID string) error { + return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error { + if err := d.FederationJoinedHosts.DeleteJoinedHostsForRoom(ctx, txn, roomID); err != nil { + return fmt.Errorf("failed to purge joined hosts: %w", err) + } + if err := d.FederationInboundPeeks.DeleteInboundPeeks(ctx, txn, roomID); err != nil { + return fmt.Errorf("failed to purge inbound peeks: %w", err) + } + if err := d.FederationOutboundPeeks.DeleteOutboundPeeks(ctx, txn, roomID); err != nil { + return fmt.Errorf("failed to purge outbound peeks: %w", err) + } + return nil + }) +} |