feat: slow down

This commit is contained in:
codytseng
2025-02-05 15:26:21 +08:00
parent ccf8c21954
commit 8561ef038e

View File

@@ -46,17 +46,17 @@ class ClientService extends EventTarget {
private profileEventCache = new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 })
private profileEventDataloader = new DataLoader<string, NEvent | undefined>(
(ids) => Promise.all(ids.map((id) => this._fetchProfileEvent(id))),
{ cacheMap: this.profileEventCache, maxBatchSize: 10 }
{ cacheMap: this.profileEventCache, maxBatchSize: 20 }
)
private fetchProfileEventFromDefaultRelaysDataloader = new DataLoader<string, NEvent | undefined>(
this.profileEventBatchLoadFn.bind(this),
{ cache: false, maxBatchSize: 10 }
{ cache: false, maxBatchSize: 20 }
)
private relayListEventDataLoader = new DataLoader<string, NEvent | undefined>(
this.relayListEventBatchLoadFn.bind(this),
{
cacheMap: new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 }),
maxBatchSize: 10
maxBatchSize: 20
}
)
private relayInfoDataLoader = new DataLoader<string, TRelayInfo | undefined>(async (urls) => {
@@ -531,7 +531,10 @@ class ClientService extends EventTarget {
async initUserIndexFromFollowings(pubkey: string) {
const followings = await this.fetchFollowings(pubkey)
await this.profileEventDataloader.loadMany(followings)
for (let i = 0; i * 20 < followings.length; i++) {
await this.profileEventDataloader.loadMany(followings.slice(i * 20, (i + 1) * 20))
await new Promise((resolve) => setTimeout(resolve, 200))
}
}
private async fetchEventById(relayUrls: string[], id: string): Promise<NEvent | undefined> {