More indexedDB cleanup

This commit is contained in:
wvffle 2022-10-28 22:15:15 +00:00 committed by Georg Krause
parent eba18cede3
commit cb5e6f1848
No known key found for this signature in database
GPG Key ID: 2970D504B2183D22
1 changed files with 10 additions and 2 deletions

View File

@ -53,6 +53,7 @@ watchEffect(async () => {
if (fetchingTracks.value) return
const allTracks = new Set(tracks.value)
const removedIds = new Set<number>()
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<QueueTrack[]>(() => {