forked from noxious/client
Cache improvement
This commit is contained in:
parent
dbb4cae154
commit
79fa54b1bb
@ -21,7 +21,17 @@ export async function downloadCache<T extends { id: string; updatedAt: Date }>(e
|
|||||||
}
|
}
|
||||||
|
|
||||||
const items = response.data ?? []
|
const items = response.data ?? []
|
||||||
|
const serverItemIds = new Set(items.map((item) => item.id))
|
||||||
|
|
||||||
|
// Remove items that don't exist on server
|
||||||
|
const existingItems = await storage.getAll()
|
||||||
|
for (const existingItem of existingItems) {
|
||||||
|
if (!serverItemIds.has(existingItem.id)) {
|
||||||
|
await storage.delete(existingItem.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update or add new items
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
let overwrite = false
|
let overwrite = false
|
||||||
const existingItem = await storage.getById(item.id)
|
const existingItem = await storage.getById(item.id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user