mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-16 10:33:11 -06:00
Try to wire in relation updates
This commit is contained in:
parent
a5f6da72f3
commit
303155beba
|
|
@ -271,6 +271,13 @@ func (s *OutputRoomEventConsumer) onNewRoomEvent(
|
|||
return err
|
||||
}
|
||||
|
||||
if err = s.db.UpdateRelations(ctx, ev); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"event_id": ev.EventID(),
|
||||
"type": ev.Type(),
|
||||
}).WithError(err).Warn("Failed to update relations")
|
||||
}
|
||||
|
||||
s.pduStream.Advance(pduPos)
|
||||
s.notifier.OnNewEvent(ev, ev.RoomID(), nil, types.StreamingToken{PDUPosition: pduPos})
|
||||
|
||||
|
|
|
|||
|
|
@ -174,6 +174,7 @@ type Database interface {
|
|||
StoreReceipt(ctx context.Context, roomId, receiptType, userId, eventId string, timestamp gomatrixserverlib.Timestamp) (pos types.StreamPosition, err error)
|
||||
UpdateIgnoresForUser(ctx context.Context, userID string, ignores *types.IgnoredUsers) error
|
||||
ReIndex(ctx context.Context, limit, afterID int64) (map[int64]gomatrixserverlib.HeaderedEvent, error)
|
||||
UpdateRelations(ctx context.Context, event *gomatrixserverlib.HeaderedEvent) error
|
||||
}
|
||||
|
||||
type Presence interface {
|
||||
|
|
|
|||
|
|
@ -39,7 +39,9 @@ CREATE TABLE IF NOT EXISTS syncapi_relations (
|
|||
const insertRelationSQL = "" +
|
||||
"INSERT INTO syncapi_relations (" +
|
||||
" room_id, event_id, child_event_id, rel_type" +
|
||||
") VALUES ($1, $2, $3, $4) RETURNING id"
|
||||
") VALUES ($1, $2, $3, $4) " +
|
||||
" ON CONFLICT syncapi_relations_unique DO UPDATE SET event_id=EXCLUDED.event_id" +
|
||||
" RETURNING id"
|
||||
|
||||
const deleteRelationSQL = "" +
|
||||
"DELETE FROM syncapi_relations WHERE event_id = $1"
|
||||
|
|
|
|||
|
|
@ -98,6 +98,10 @@ func NewDatabase(base *base.BaseDendrite, dbProperties *config.DatabaseOptions)
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
relations, err := NewPostgresRelationsTable(d.db)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// apply migrations which need multiple tables
|
||||
m := sqlutil.NewMigrator(d.db)
|
||||
|
|
@ -129,6 +133,7 @@ func NewDatabase(base *base.BaseDendrite, dbProperties *config.DatabaseOptions)
|
|||
NotificationData: notificationData,
|
||||
Ignores: ignores,
|
||||
Presence: presence,
|
||||
Relations: relations,
|
||||
}
|
||||
return &d, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ type Database struct {
|
|||
NotificationData tables.NotificationData
|
||||
Ignores tables.Ignores
|
||||
Presence tables.Presence
|
||||
Relations tables.Relations
|
||||
}
|
||||
|
||||
func (d *Database) NewDatabaseSnapshot(ctx context.Context) (*DatabaseTransaction, error) {
|
||||
|
|
@ -579,10 +580,27 @@ func (d *Database) SelectMembershipForUser(ctx context.Context, roomID, userID s
|
|||
return d.Memberships.SelectMembershipForUser(ctx, nil, roomID, userID, pos)
|
||||
}
|
||||
|
||||
func (s *Database) ReIndex(ctx context.Context, limit, afterID int64) (map[int64]gomatrixserverlib.HeaderedEvent, error) {
|
||||
return s.OutputEvents.ReIndex(ctx, nil, limit, afterID, []string{
|
||||
func (d *Database) ReIndex(ctx context.Context, limit, afterID int64) (map[int64]gomatrixserverlib.HeaderedEvent, error) {
|
||||
return d.OutputEvents.ReIndex(ctx, nil, limit, afterID, []string{
|
||||
gomatrixserverlib.MRoomName,
|
||||
gomatrixserverlib.MRoomTopic,
|
||||
"m.room.message",
|
||||
})
|
||||
}
|
||||
|
||||
func (d *Database) UpdateRelations(ctx context.Context, event *gomatrixserverlib.HeaderedEvent) error {
|
||||
var content gomatrixserverlib.RelationContent
|
||||
if err := json.Unmarshal(event.Content(), &content); err != nil {
|
||||
return fmt.Errorf("json.Unmarshal: %w", err)
|
||||
}
|
||||
if content.Relations == nil {
|
||||
return nil
|
||||
}
|
||||
return d.Writer.Do(d.DB, nil, func(txn *sql.Tx) error {
|
||||
_, err := d.Relations.InsertRelation(
|
||||
ctx, txn, event.RoomID(), event.EventID(),
|
||||
content.Relations.EventID, content.Relations.RelationType,
|
||||
)
|
||||
return err
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue