fix: reset wasCleared on each DataStore edit retry in clearAlbumSelectionsIfMatches

DataStore's edit lambda can be retried when a concurrent write conflict
is detected. wasCleared was captured from the outer scope and never reset
between retries, so a true from a failed first attempt could leak into the
final return value even if the condition no longer held on the retry.
Added wasCleared = false at the top of the lambda so each attempt starts
from a clean state.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Anthonyy232andClaude Sonnet 4.6 committed 2026-03-28 14:06:12 -07:00
1 parent 73ca207301
commit 8f357f8767
1 file changed
+3
@@ -358,6 +358,9 @@ class PreferencesManager @Inject constructor(
suspend fun clearAlbumSelectionsIfMatches(albumId: String): Boolean {
var wasCleared = false
dataStore.edit { prefs ->
// Reset on each attempt — DataStore may retry the lambda on concurrent write conflicts
wasCleared = false
val homeAlbumId = prefs[stringPreferencesKey(PreferenceKeys.HOME_ALBUM_ID)]
val lockAlbumId = prefs[stringPreferencesKey(PreferenceKeys.LOCK_ALBUM_ID)]
val liveAlbumId = prefs[stringPreferencesKey(PreferenceKeys.LIVE_ALBUM_ID)]