Try that again

This commit is contained in:
Neil Alexander 2022-09-12 11:00:00 +01:00
parent ee4d8d6de7
commit 35f417627d
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -682,22 +682,22 @@ func (d *Database) storeEvent(
// any other so this is fine. If we ever update GetLatestEventsForUpdate or NewLatestEventsUpdater // any other so this is fine. If we ever update GetLatestEventsForUpdate or NewLatestEventsUpdater
// to do writes however then this will need to go inside `Writer.Do`. // to do writes however then this will need to go inside `Writer.Do`.
succeeded := false succeeded := false
if err = d.Writer.Do(nil, nil, func(txn *sql.Tx) error { if updater == nil {
if updater == nil { var roomInfo *types.RoomInfo
var roomInfo *types.RoomInfo roomInfo, err = d.roomInfo(ctx, txn, event.RoomID())
roomInfo, err = d.roomInfo(ctx, txn, event.RoomID()) if err != nil {
if err != nil { return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("d.RoomInfo: %w", err)
return fmt.Errorf("d.RoomInfo: %w", err)
}
if roomInfo == nil && len(prevEvents) > 0 {
return fmt.Errorf("expected room %q to exist", event.RoomID())
}
updater, err = d.GetRoomUpdater(ctx, roomInfo)
if err != nil {
return fmt.Errorf("GetRoomUpdater: %w", err)
}
defer sqlutil.EndTransactionWithCheck(updater, &succeeded, &err)
} }
if roomInfo == nil && len(prevEvents) > 0 {
return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("expected room %q to exist", event.RoomID())
}
updater, err = d.GetRoomUpdater(ctx, roomInfo)
if err != nil {
return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("GetRoomUpdater: %w", err)
}
defer sqlutil.EndTransactionWithCheck(updater, &succeeded, &err)
}
if err = d.Writer.Do(nil, nil, func(_ *sql.Tx) error {
if err = updater.StorePreviousEvents(eventNID, prevEvents); err != nil { if err = updater.StorePreviousEvents(eventNID, prevEvents); err != nil {
return fmt.Errorf("updater.StorePreviousEvents: %w", err) return fmt.Errorf("updater.StorePreviousEvents: %w", err)
} }