mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-02-12 05:54:29 -06:00
Hopefully fix panics for good in SQLite this time
This commit is contained in:
parent
885c70c31c
commit
d1baa305ae
|
@ -40,11 +40,6 @@ type Transaction interface {
|
|||
// You MUST check the error returned from this function to be sure that the transaction
|
||||
// was applied correctly. For example, 'database is locked' errors in sqlite will happen here.
|
||||
func EndTransaction(txn Transaction, succeeded *bool) error {
|
||||
if txn == nil {
|
||||
// Sometimes in SQLite mode we have nil transactions. If that's the case
|
||||
// then we are working outside of a transaction and should do nothing here.
|
||||
return nil
|
||||
}
|
||||
if *succeeded {
|
||||
return txn.Commit()
|
||||
} else {
|
||||
|
|
|
@ -61,6 +61,22 @@ func NewRoomUpdater(ctx context.Context, d *Database, txn *sql.Tx, roomInfo *typ
|
|||
}, nil
|
||||
}
|
||||
|
||||
// Implements sqlutil.Transaction
|
||||
func (u *RoomUpdater) Commit() error {
|
||||
if u.txn == nil { // SQLite mode probably
|
||||
return nil
|
||||
}
|
||||
return u.txn.Commit()
|
||||
}
|
||||
|
||||
// Implements sqlutil.Transaction
|
||||
func (u *RoomUpdater) Rollback() error {
|
||||
if u.txn == nil { // SQLite mode probably
|
||||
return nil
|
||||
}
|
||||
return u.txn.Commit()
|
||||
}
|
||||
|
||||
// RoomVersion implements types.RoomRecentEventsUpdater
|
||||
func (u *RoomUpdater) RoomVersion() (version gomatrixserverlib.RoomVersion) {
|
||||
return u.roomInfo.RoomVersion
|
||||
|
|
|
@ -649,7 +649,7 @@ func (d *Database) storeEvent(
|
|||
if err != nil {
|
||||
return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("GetRoomUpdater: %w", err)
|
||||
}
|
||||
defer sqlutil.EndTransactionWithCheck(updater.txn, &succeeded, &err)
|
||||
defer sqlutil.EndTransactionWithCheck(updater, &succeeded, &err)
|
||||
}
|
||||
if err = updater.StorePreviousEvents(eventNID, prevEvents); err != nil {
|
||||
return 0, 0, types.StateAtEvent{}, nil, "", fmt.Errorf("updater.StorePreviousEvents: %w", err)
|
||||
|
|
Loading…
Reference in a new issue