diff --git a/syncapi/storage/postgres/relations_table.go b/syncapi/storage/postgres/relations_table.go index e46b450bf..5ed8059fb 100644 --- a/syncapi/storage/postgres/relations_table.go +++ b/syncapi/storage/postgres/relations_table.go @@ -46,7 +46,7 @@ const insertRelationSQL = "" + " RETURNING id" const deleteRelationSQL = "" + - "DELETE FROM syncapi_relations WHERE event_id = $1" + "DELETE FROM syncapi_relations WHERE room_id = $1 AND child_event_id = $2" const selectRelationsInRangeSQL = "" + "SELECT id, room_id, child_event_id, rel_type FROM syncapi_relations" + @@ -103,11 +103,11 @@ func (s *relationsStatements) InsertRelation( } func (s *relationsStatements) DeleteRelation( - ctx context.Context, txn *sql.Tx, roomID, eventID, childEventID, relType string, + ctx context.Context, txn *sql.Tx, roomID, childEventID string, ) error { stmt := sqlutil.TxStmt(txn, s.deleteRelationStmt) _, err := stmt.ExecContext( - ctx, roomID, eventID, childEventID, relType, + ctx, roomID, childEventID, ) return err } diff --git a/syncapi/storage/shared/storage_consumer.go b/syncapi/storage/shared/storage_consumer.go index f921db4b4..0d4169dc3 100644 --- a/syncapi/storage/shared/storage_consumer.go +++ b/syncapi/storage/shared/storage_consumer.go @@ -598,10 +598,9 @@ func (d *Database) UpdateRelations(ctx context.Context, event *gomatrixserverlib } return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error { var err error - if event.Redacted() { + if event.Type() == gomatrixserverlib.MRoomRedaction { err = d.Relations.DeleteRelation( - ctx, txn, event.RoomID(), content.Relations.EventID, - event.EventID(), content.Relations.RelationType, + ctx, txn, event.RoomID(), event.Redacts(), ) } else { _, err = d.Relations.InsertRelation( diff --git a/syncapi/storage/tables/interface.go b/syncapi/storage/tables/interface.go index 2d6cd9357..a227f4563 100644 --- a/syncapi/storage/tables/interface.go +++ b/syncapi/storage/tables/interface.go @@ -209,7 +209,7 @@ type Presence interface { type Relations interface { InsertRelation(ctx context.Context, txn *sql.Tx, roomID, eventID, childEventID, relType string) (streamPos types.StreamPosition, err error) - DeleteRelation(ctx context.Context, txn *sql.Tx, roomID, eventID, childEventID, relType string) error + DeleteRelation(ctx context.Context, txn *sql.Tx, roomID, childEventID string) error SelectRelationsInRange(ctx context.Context, txn *sql.Tx, roomID, eventID, relType string, r types.Range) (map[string][]string, types.StreamPosition, error) SelectMaxRelationID(ctx context.Context, txn *sql.Tx) (id int64, err error) }