feat: slow down
This commit is contained in:
@@ -46,17 +46,17 @@ class ClientService extends EventTarget {
|
|||||||
private profileEventCache = new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 })
|
private profileEventCache = new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 })
|
||||||
private profileEventDataloader = new DataLoader<string, NEvent | undefined>(
|
private profileEventDataloader = new DataLoader<string, NEvent | undefined>(
|
||||||
(ids) => Promise.all(ids.map((id) => this._fetchProfileEvent(id))),
|
(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>(
|
private fetchProfileEventFromDefaultRelaysDataloader = new DataLoader<string, NEvent | undefined>(
|
||||||
this.profileEventBatchLoadFn.bind(this),
|
this.profileEventBatchLoadFn.bind(this),
|
||||||
{ cache: false, maxBatchSize: 10 }
|
{ cache: false, maxBatchSize: 20 }
|
||||||
)
|
)
|
||||||
private relayListEventDataLoader = new DataLoader<string, NEvent | undefined>(
|
private relayListEventDataLoader = new DataLoader<string, NEvent | undefined>(
|
||||||
this.relayListEventBatchLoadFn.bind(this),
|
this.relayListEventBatchLoadFn.bind(this),
|
||||||
{
|
{
|
||||||
cacheMap: new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 }),
|
cacheMap: new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 }),
|
||||||
maxBatchSize: 10
|
maxBatchSize: 20
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
private relayInfoDataLoader = new DataLoader<string, TRelayInfo | undefined>(async (urls) => {
|
private relayInfoDataLoader = new DataLoader<string, TRelayInfo | undefined>(async (urls) => {
|
||||||
@@ -531,7 +531,10 @@ class ClientService extends EventTarget {
|
|||||||
|
|
||||||
async initUserIndexFromFollowings(pubkey: string) {
|
async initUserIndexFromFollowings(pubkey: string) {
|
||||||
const followings = await this.fetchFollowings(pubkey)
|
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> {
|
private async fetchEventById(relayUrls: string[], id: string): Promise<NEvent | undefined> {
|
||||||
|
|||||||
Reference in New Issue
Block a user