feat: optimize cache update strategy
This commit is contained in:
@@ -1198,9 +1198,12 @@ class ClientService extends EventTarget {
|
|||||||
private async fetchReplaceableEventsFromBigRelays(pubkeys: string[], kind: number) {
|
private async fetchReplaceableEventsFromBigRelays(pubkeys: string[], kind: number) {
|
||||||
const events = await indexedDb.getManyReplaceableEvents(pubkeys, kind)
|
const events = await indexedDb.getManyReplaceableEvents(pubkeys, kind)
|
||||||
const nonExistingPubkeyIndexMap = new Map<string, number>()
|
const nonExistingPubkeyIndexMap = new Map<string, number>()
|
||||||
|
const existingPubkeys: string[] = []
|
||||||
pubkeys.forEach((pubkey, i) => {
|
pubkeys.forEach((pubkey, i) => {
|
||||||
if (events[i] === undefined) {
|
if (events[i] === undefined) {
|
||||||
nonExistingPubkeyIndexMap.set(pubkey, i)
|
nonExistingPubkeyIndexMap.set(pubkey, i)
|
||||||
|
} else {
|
||||||
|
existingPubkeys.push(pubkey)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const newEvents = await this.replaceableEventFromBigRelaysDataloader.loadMany(
|
const newEvents = await this.replaceableEventFromBigRelaysDataloader.loadMany(
|
||||||
@@ -1215,6 +1218,10 @@ class ClientService extends EventTarget {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.replaceableEventFromBigRelaysDataloader.loadMany(
|
||||||
|
existingPubkeys.map((pubkey) => ({ pubkey, kind }))
|
||||||
|
) // update cache in background
|
||||||
|
|
||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1306,6 +1313,7 @@ class ClientService extends EventTarget {
|
|||||||
private async fetchReplaceableEvent(pubkey: string, kind: number, d?: string) {
|
private async fetchReplaceableEvent(pubkey: string, kind: number, d?: string) {
|
||||||
const storedEvent = await indexedDb.getReplaceableEvent(pubkey, kind, d)
|
const storedEvent = await indexedDb.getReplaceableEvent(pubkey, kind, d)
|
||||||
if (storedEvent !== undefined) {
|
if (storedEvent !== undefined) {
|
||||||
|
this.replaceableEventDataLoader.load({ pubkey, kind, d }) // update cache in background
|
||||||
return storedEvent
|
return storedEvent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -497,19 +497,19 @@ class IndexedDbService {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: StoreNames.RELAY_LIST_EVENTS,
|
name: StoreNames.RELAY_LIST_EVENTS,
|
||||||
expirationTimestamp: Date.now() - 1000 * 60 * 60 * 24 // 1 day
|
expirationTimestamp: Date.now() - 1000 * 60 * 60 * 24 * 30 // 30 day
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: StoreNames.FOLLOW_LIST_EVENTS,
|
name: StoreNames.FOLLOW_LIST_EVENTS,
|
||||||
expirationTimestamp: Date.now() - 1000 * 60 * 60 * 24 // 1 day
|
expirationTimestamp: Date.now() - 1000 * 60 * 60 * 24 * 30 // 30 day
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: StoreNames.BLOSSOM_SERVER_LIST_EVENTS,
|
name: StoreNames.BLOSSOM_SERVER_LIST_EVENTS,
|
||||||
expirationTimestamp: Date.now() - 1000 * 60 * 60 * 24 // 1 days
|
expirationTimestamp: Date.now() - 1000 * 60 * 60 * 24 * 30 // 30 day
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: StoreNames.RELAY_INFOS,
|
name: StoreNames.RELAY_INFOS,
|
||||||
expirationTimestamp: Date.now() - 1000 * 60 * 60 * 24 // 1 days
|
expirationTimestamp: Date.now() - 1000 * 60 * 60 * 24 * 30 // 30 day
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: StoreNames.PIN_LIST_EVENTS,
|
name: StoreNames.PIN_LIST_EVENTS,
|
||||||
|
|||||||
Reference in New Issue
Block a user