From cb5e6f1848d451ef4fc1a1a6b9ff9b3c5043be87 Mon Sep 17 00:00:00 2001 From: wvffle Date: Fri, 28 Oct 2022 22:15:15 +0000 Subject: [PATCH] More indexedDB cleanup --- front/src/composables/audio/queue.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/front/src/composables/audio/queue.ts b/front/src/composables/audio/queue.ts index 00471f745..5516473c9 100644 --- a/front/src/composables/audio/queue.ts +++ b/front/src/composables/audio/queue.ts @@ -53,6 +53,7 @@ watchEffect(async () => { if (fetchingTracks.value) return const allTracks = new Set(tracks.value) + const removedIds = new Set() const addedIds = new Set(allTracks) for (const id of tracksById.keys()) { @@ -60,8 +61,8 @@ watchEffect(async () => { // Track in queue, so remove it from the new ids set addedIds.delete(id) } else { - // Track removed from queue, so remove it from the object - tracksById.delete(id) + // Track removed from queue, so remove it from the object and db later + removedIds.add(id) } } @@ -78,6 +79,13 @@ watchEffect(async () => { fetchingTracks.value = false } } + + if (removedIds.size > 0) { + await delMany([...removedIds]) + for (const id of removedIds) { + tracksById.delete(id) + } + } }) const queue = computed(() => {