mirror of
https://github.com/multipleof4/ntfy.git
synced 2026-10-15 16:07:55 +00:00
Fix race and a small issue with the access cache
This commit is contained in:
+12
-1
@@ -987,7 +987,7 @@ func (a *Manager) ReservationOwner(topic string) (string, error) {
|
||||
// It returns the list of topics whose reservations were removed. The read and removal are
|
||||
// performed atomically in a single transaction to avoid issues with stale replica data.
|
||||
func (a *Manager) RemoveExcessReservations(username string, limit int64) ([]string, error) {
|
||||
return db.QueryTx(a.db, func(tx *sql.Tx) ([]string, error) {
|
||||
removedTopics, err := db.QueryTx(a.db, func(tx *sql.Tx) ([]string, error) {
|
||||
reservations, err := a.reservationsTx(tx, username)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -1005,6 +1005,17 @@ func (a *Manager) RemoveExcessReservations(username string, limit int64) ([]stri
|
||||
}
|
||||
return removedTopics, nil
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(removedTopics) > 0 {
|
||||
// removeReservationAccessTx deletes rows owned by this user and the
|
||||
// matching Everyone rows, so we refresh the access cache.
|
||||
if err := a.maybeReloadAccessCache(username, Everyone); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return removedTopics, nil
|
||||
}
|
||||
|
||||
// otherAccessCount returns the number of access entries for the given topic that are not owned by the user
|
||||
|
||||
Reference in New Issue
Block a user