mirror of
https://github.com/Dasemu/X-GeoBlock.git
synced 2026-11-26 23:36:11 +00:00
feat: add location picker and persistent cache
This commit is contained in:
1 parent
fcea6cf7b7
commit
3811ae9cfc
16 files changed
+163
-39
No files matched your search
+1
-10
@@ -45,14 +45,12 @@ async function lookupUserInternal(username, key) {
|
||||
const stored = await extensionApi.storage.local.get(CACHE_KEY);
|
||||
const cache = stored[CACHE_KEY] || {};
|
||||
const cached = cache[key];
|
||||
const ttl = Math.max(1, Number(settings.cacheTtlHours) || 168) * 60 * 60 * 1000;
|
||||
if (cached && Date.now() - cached.checkedAt < ttl) {
|
||||
if (cached) {
|
||||
return decision(cached, settings, true);
|
||||
}
|
||||
|
||||
const result = await enqueue(() => fetchAbout(username));
|
||||
cache[key] = { ...result, checkedAt: Date.now() };
|
||||
pruneCache(cache);
|
||||
await extensionApi.storage.local.set({ [CACHE_KEY]: cache });
|
||||
return decision(cache[key], settings, false);
|
||||
}
|
||||
@@ -105,10 +103,3 @@ async function ensureOffscreenDocument() {
|
||||
justification: "Parse the account About page without opening a visible tab."
|
||||
});
|
||||
}
|
||||
|
||||
function pruneCache(cache) {
|
||||
const entries = Object.entries(cache);
|
||||
if (entries.length <= 2000) return;
|
||||
entries.sort((a, b) => (b[1].checkedAt || 0) - (a[1].checkedAt || 0));
|
||||
for (const [key] of entries.slice(1500)) delete cache[key];
|
||||
}
|
||||
Reference in new issue
Block a user