0.2.59 - Settings save fixes
This commit is contained in:
@@ -171,10 +171,18 @@ func (s *Store) SetUserPreferences(
|
||||
// Pruned here rather than on a schedule: this is the only writer, so it is the only
|
||||
// place the table can grow, and the acks of a revision nobody can see any more are
|
||||
// dead weight with it.
|
||||
//
|
||||
// The cutoff is worked out in Go rather than as `$2 - $3` in the statement. Postgres
|
||||
// has to infer a type for every placeholder, and two of them either side of an
|
||||
// operator give it nothing to infer from — it answers `operator is not unique:
|
||||
// unknown - unknown`, which failed the whole transaction and returned 500 to every
|
||||
// television trying to save a setting. Arithmetic on two parameters belongs on this
|
||||
// side of the wire.
|
||||
pruneBelow := next.Revision - preferenceHistoryLimit
|
||||
if _, err := tx.Exec(ctx, `
|
||||
DELETE FROM user_preference_revisions
|
||||
WHERE emby_user_id = $1 AND revision <= $2 - $3`,
|
||||
userID, next.Revision, preferenceHistoryLimit,
|
||||
WHERE emby_user_id = $1 AND revision <= $2`,
|
||||
userID, pruneBelow,
|
||||
); err != nil {
|
||||
return UserPreferences{}, fmt.Errorf("store: prune preference history: %w", err)
|
||||
}
|
||||
@@ -183,13 +191,13 @@ func (s *Store) SetUserPreferences(
|
||||
// described as "on revision 12" rather than as one that has never checked in.
|
||||
if _, err := tx.Exec(ctx, `
|
||||
DELETE FROM user_preference_acks stale
|
||||
WHERE stale.emby_user_id = $1 AND stale.revision <= $2 - $3
|
||||
WHERE stale.emby_user_id = $1 AND stale.revision <= $2
|
||||
AND EXISTS (
|
||||
SELECT 1 FROM user_preference_acks newer
|
||||
WHERE newer.emby_user_id = stale.emby_user_id
|
||||
AND newer.device_id = stale.device_id
|
||||
AND newer.revision > stale.revision)`,
|
||||
userID, next.Revision, preferenceHistoryLimit,
|
||||
userID, pruneBelow,
|
||||
); err != nil {
|
||||
return UserPreferences{}, fmt.Errorf("store: prune preference acks: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user