Rename Close to Commit and Rollback

This commit is contained in:
Mark Haines 2017-02-21 13:22:18 +00:00
parent d4563ef6d3
commit 75454c59ea
4 changed files with 12 additions and 9 deletions

View file

@ -35,7 +35,7 @@ type RoomEventDatabase interface {
// Set the state at an event.
SetState(eventNID types.EventNID, stateNID types.StateSnapshotNID) error
// Lookup the latest events in a room in preparation for an update.
// The RoomRecentEventsUpdater must be closed if this doesn't return an error.
// The RoomRecentEventsUpdater must have Commit or Rollback called on it if this doesn't return an error.
// If this returns an error then no further action is required.
GetLatestEventsForUpdate(roomNID types.RoomNID) ([]types.StateAtEventAndReference, types.RoomRecentEventsUpdater, error)
}

View file

@ -19,11 +19,11 @@ func updateLatestEvents(
// Commit if there wasn't an error.
// Set the returned err value if we encounter an error committing.
// This only works because err is a named return.
err = updater.Close(true)
err = updater.Commit()
} else {
// Ignore any error we get rolling back since we don't want to
// clobber the current error
updater.Close(false)
updater.Rollback()
}
}()

View file

@ -248,9 +248,10 @@ func (u *roomRecentEventsUpdater) SetLatestEvents(roomNID types.RoomNID, latest
return u.d.statements.updateLatestEventNIDs(u.txn, roomNID, eventNIDs)
}
func (u *roomRecentEventsUpdater) Close(commit bool) error {
if commit {
return u.txn.Commit()
}
func (u *roomRecentEventsUpdater) Commit() error {
return u.txn.Commit()
}
func (u *roomRecentEventsUpdater) Rollback() error {
return u.txn.Rollback()
}

View file

@ -136,6 +136,8 @@ type RoomRecentEventsUpdater interface {
IsReferenced(eventReference gomatrixserverlib.EventReference) (bool, error)
// Set the list of latest events for the room.
SetLatestEvents(roomNID RoomNID, latest []StateAtEventAndReference) error
// Commit or Rollback the transaction.
Close(commit bool) error
// Commit the transaction
Commit() error
// Rollback the transaction.
Rollback() error
}