mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-23 14:51:56 -06:00
Purge the room entry too
This commit is contained in:
parent
b56011514b
commit
4c4de0dfc6
|
@ -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 {
|
||||||
|
|
|
@ -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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -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")
|
||||||
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue