Purge the room entry too

This commit is contained in:
Neil Alexander 2022-08-22 12:05:38 +01:00
parent b56011514b
commit 4c4de0dfc6
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
4 changed files with 22 additions and 0 deletions

View file

@ -82,6 +82,9 @@ const bulkSelectRoomIDsSQL = "" +
const bulkSelectRoomNIDsSQL = "" + const bulkSelectRoomNIDsSQL = "" +
"SELECT room_nid FROM roomserver_rooms WHERE room_id = ANY($1)" "SELECT room_nid FROM roomserver_rooms WHERE room_id = ANY($1)"
const purgeRoomSQL = "" +
"DELETE FROM roomserver_rooms WHERE room_nid = $1"
type roomStatements struct { type roomStatements struct {
insertRoomNIDStmt *sql.Stmt insertRoomNIDStmt *sql.Stmt
selectRoomNIDStmt *sql.Stmt selectRoomNIDStmt *sql.Stmt
@ -93,6 +96,7 @@ type roomStatements struct {
selectRoomIDsStmt *sql.Stmt selectRoomIDsStmt *sql.Stmt
bulkSelectRoomIDsStmt *sql.Stmt bulkSelectRoomIDsStmt *sql.Stmt
bulkSelectRoomNIDsStmt *sql.Stmt bulkSelectRoomNIDsStmt *sql.Stmt
purgeRoomStmt *sql.Stmt
} }
func CreateRoomsTable(db *sql.DB) error { func CreateRoomsTable(db *sql.DB) error {
@ -114,6 +118,7 @@ func PrepareRoomsTable(db *sql.DB) (tables.Rooms, error) {
{&s.selectRoomIDsStmt, selectRoomIDsSQL}, {&s.selectRoomIDsStmt, selectRoomIDsSQL},
{&s.bulkSelectRoomIDsStmt, bulkSelectRoomIDsSQL}, {&s.bulkSelectRoomIDsStmt, bulkSelectRoomIDsSQL},
{&s.bulkSelectRoomNIDsStmt, bulkSelectRoomNIDsSQL}, {&s.bulkSelectRoomNIDsStmt, bulkSelectRoomNIDsSQL},
{&s.purgeRoomStmt, purgeRoomSQL},
}.Prepare(db) }.Prepare(db)
} }
@ -288,6 +293,13 @@ func (s *roomStatements) BulkSelectRoomNIDs(ctx context.Context, txn *sql.Tx, ro
return roomNIDs, nil return roomNIDs, nil
} }
func (s *roomStatements) PurgeRoom(
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
) error {
_, err := sqlutil.TxStmt(txn, s.purgeRoomStmt).ExecContext(ctx, roomNID)
return err
}
func roomNIDsAsArray(roomNIDs []types.RoomNID) pq.Int64Array { func roomNIDsAsArray(roomNIDs []types.RoomNID) pq.Int64Array {
nids := make([]int64, len(roomNIDs)) nids := make([]int64, len(roomNIDs))
for i := range roomNIDs { for i := range roomNIDs {

View file

@ -1390,6 +1390,9 @@ func (d *Database) PurgeRoom(ctx context.Context, roomID string) error {
if err := d.EventsTable.PurgeEvents(ctx, txn, roomNID); err != nil { if err := d.EventsTable.PurgeEvents(ctx, txn, roomNID); err != nil {
return fmt.Errorf("failed to purge events: %w", err) return fmt.Errorf("failed to purge events: %w", err)
} }
if err := d.RoomsTable.PurgeRoom(ctx, txn, roomNID); err != nil {
return fmt.Errorf("failed to purge room: %w", err)
}
return nil return nil
}) })
} }

View file

@ -309,3 +309,9 @@ func (s *roomStatements) BulkSelectRoomNIDs(ctx context.Context, txn *sql.Tx, ro
} }
return roomNIDs, nil return roomNIDs, nil
} }
func (s *roomStatements) PurgeRoom(
ctx context.Context, txn *sql.Tx, roomNID types.RoomNID,
) error {
return fmt.Errorf("not implemented on SQLite")
}

View file

@ -82,6 +82,7 @@ type Rooms interface {
SelectRoomIDsWithEvents(ctx context.Context, txn *sql.Tx) ([]string, error) SelectRoomIDsWithEvents(ctx context.Context, txn *sql.Tx) ([]string, error)
BulkSelectRoomIDs(ctx context.Context, txn *sql.Tx, roomNIDs []types.RoomNID) ([]string, error) BulkSelectRoomIDs(ctx context.Context, txn *sql.Tx, roomNIDs []types.RoomNID) ([]string, error)
BulkSelectRoomNIDs(ctx context.Context, txn *sql.Tx, roomIDs []string) ([]types.RoomNID, error) BulkSelectRoomNIDs(ctx context.Context, txn *sql.Tx, roomIDs []string) ([]types.RoomNID, error)
PurgeRoom(ctx context.Context, txn *sql.Tx, roomNID types.RoomNID) error
} }
type StateSnapshot interface { type StateSnapshot interface {