Make dufflepud optional, fetch zappers/handles directly

This commit is contained in:
Jon Staab
2024-09-05 15:26:45 -07:00
parent ed7efac977
commit 18db1421a9
6 changed files with 130 additions and 37 deletions
+22 -4
View File
@@ -17,13 +17,31 @@ export const collection = <T, LoadArgs extends any[]>({
const indexStore = withGetter(derived(store, $items => indexBy(getKey, $items)))
const getItem = (key: string) => indexStore.get().get(key)
const pending = new Map<string, Promise<Maybe<T>>>()
const loadAttempts = new Map<string, number>()
const loadItem = async (key: string, ...args: LoadArgs) => {
const item = indexStore.get().get(key)
const delta = item ? 3600 : 30
const item = undefined//indexStore.get().get(key)
const freshness = getFreshness(name, key)
if (getFreshness(name, key) > now() - delta) {
return item
if (name === 'zappers' && key === '6e468422dfb74a5738702a8823b9b28168abab8655faacb6853cd0ee15deee93') {
console.log(item)
}
// If we have an item, reload anyway if it's stale. If not, retry with exponential backoff
if (item) {
loadAttempts.delete(key)
if (freshness > now() - 3600) {
return item
}
} else {
const attempt = loadAttempts.get(key) || 0
if (freshness > now() - Math.pow(2, attempt)) {
return undefined
}
loadAttempts.set(key, attempt + 1)
}
if (pending.has(key)) {