mirror of
https://github.com/matrix-org/dendrite.git
synced 2024-11-22 14:21:55 -06:00
Use the writer to get the room updater
This commit is contained in:
parent
0d74b296f1
commit
d08d319a9d
|
@ -105,14 +105,12 @@ func (u *RoomUpdater) CurrentStateSnapshotNID() types.StateSnapshotNID {
|
||||||
|
|
||||||
// StorePreviousEvents implements types.RoomRecentEventsUpdater - This must be called from a Writer
|
// StorePreviousEvents implements types.RoomRecentEventsUpdater - This must be called from a Writer
|
||||||
func (u *RoomUpdater) StorePreviousEvents(eventNID types.EventNID, previousEventReferences []gomatrixserverlib.EventReference) error {
|
func (u *RoomUpdater) StorePreviousEvents(eventNID types.EventNID, previousEventReferences []gomatrixserverlib.EventReference) error {
|
||||||
return u.d.Writer.Do(u.d.DB, u.txn, func(txn *sql.Tx) error {
|
for _, ref := range previousEventReferences {
|
||||||
for _, ref := range previousEventReferences {
|
if err := u.d.PrevEventsTable.InsertPreviousEvent(u.ctx, u.txn, ref.EventID, ref.EventSHA256, eventNID); err != nil {
|
||||||
if err := u.d.PrevEventsTable.InsertPreviousEvent(u.ctx, txn, ref.EventID, ref.EventSHA256, eventNID); err != nil {
|
return fmt.Errorf("u.d.PrevEventsTable.InsertPreviousEvent: %w", err)
|
||||||
return fmt.Errorf("u.d.PrevEventsTable.InsertPreviousEvent: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return nil
|
}
|
||||||
})
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *RoomUpdater) Events(
|
func (u *RoomUpdater) Events(
|
||||||
|
|
|
@ -680,13 +680,18 @@ func (d *Database) StoreEvent(
|
||||||
if roomInfo == nil && len(prevEvents) > 0 {
|
if roomInfo == nil && len(prevEvents) > 0 {
|
||||||
return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("expected room %q to exist", event.RoomID())
|
return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("expected room %q to exist", event.RoomID())
|
||||||
}
|
}
|
||||||
updater, err = d.GetRoomUpdater(ctx, roomInfo)
|
if err = d.Writer.Do(nil, nil, func(_ *sql.Tx) error {
|
||||||
if err != nil {
|
updater, err = d.GetRoomUpdater(ctx, roomInfo)
|
||||||
return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("GetRoomUpdater: %w", err)
|
if err != nil {
|
||||||
}
|
return fmt.Errorf("GetRoomUpdater: %w", err)
|
||||||
defer sqlutil.EndTransactionWithCheck(updater, &succeeded, &err)
|
}
|
||||||
if err = updater.StorePreviousEvents(eventNID, prevEvents); err != nil {
|
defer sqlutil.EndTransactionWithCheck(updater, &succeeded, &err)
|
||||||
return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("updater.StorePreviousEvents: %w", err)
|
if err = updater.StorePreviousEvents(eventNID, prevEvents); err != nil {
|
||||||
|
return fmt.Errorf("updater.StorePreviousEvents: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}); err != nil {
|
||||||
|
return 0, 0, types.StateAtEvent{}, nil, "", err
|
||||||
}
|
}
|
||||||
succeeded = true
|
succeeded = true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue