Skip to content

Commit

Permalink
better worker
Browse files Browse the repository at this point in the history
  • Loading branch information
theetherGit committed Sep 10, 2023
1 parent 9e3a28b commit 9ffce72
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/lib/workers/favoriteUpdateChecker.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import {db} from "$lib/db";

const fetchUpdate = async (manga: any) => {
const response = await fetch(`/api/manga?id=${manga.id}&slug=${manga.slug}`);
if (response.ok) {
const manga = (await response.json()).manga;
db.favouriteManga.update(manga.id, {
lastUpdated: new Date(manga['last_chapter_created_at'])
})
}
};

onmessage = async (e) => {
const favManga = await db.favouriteManga.toArray();
if (favManga.length) {
for (const manga of favManga) {
const response = await fetch(`/api/manga?id=${manga.id}&slug=${manga.slug}`);
if (response.ok) {
const manga = (await response.json()).manga;
db.favouriteManga.update(manga.id, {
lastUpdated: new Date(manga['last_chapter_created_at'])
})
}
fetchUpdate(manga)
}
}
};
Expand Down

0 comments on commit 9ffce72

Please sign in to comment.