fix: prevent double asset update

This commit is contained in:
2026-03-20 22:41:24 +07:00 Unverified
parent 4cabdb5691
commit 25b2525f98
2 changed files with 18 additions and 6 deletions
+1 -2
View File
@@ -18,7 +18,7 @@ export class AssetManager {
const [avatars, weapons, relics] = await Promise.all([ const [avatars, weapons, relics] = await Promise.all([
getEnkaAvatarStore(), getEnkaAvatarStore(),
getEnkaWeaponStore(), getEnkaWeaponStore(),
await getEnkaRelicStore(), getEnkaRelicStore(),
]); ]);
return [ return [
...Object.values(avatars).flatMap((a) => [ ...Object.values(avatars).flatMap((a) => [
@@ -58,7 +58,6 @@ export class AssetManager {
.then((d) => write(join("store", hash(name).toString(36)), d)); .then((d) => write(join("store", hash(name).toString(36)), d));
console.log("All missing assets fetched and stored"); console.log("All missing assets fetched and stored");
this.purgeExtraAssets();
} }
async purgeExtraAssets() { async purgeExtraAssets() {
+17 -4
View File
@@ -39,11 +39,24 @@ const font = file(fontFile);
const iconFont = file(iconFontFile); const iconFont = file(iconFontFile);
const shade = file(shadeSvg); const shade = file(shadeSvg);
queueMicrotask(async () => { var purging = false;
assets.getMissingAssets();
setInterval(() => { queueMicrotask(() => {
assets.getMissingAssets(); if (purging) return;
purging = true;
assets.getMissingAssets().finally(() => (purging = false));
setInterval(async () => {
if (purging) return;
purging = true;
try {
await assets.getMissingAssets();
await assets.purgeExtraAssets();
} catch (e) {
console.error(e);
} finally {
purging = false;
}
}, 86400000); // refresh assets every 24 hours }, 86400000); // refresh assets every 24 hours
}); });