fix(client): save storage after each api call

idk might rollback later
This commit is contained in:
alina 🌸 2023-12-04 15:10:13 +03:00
parent 2eb4d307cb
commit 7a89e5049e
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI

View file

@ -446,7 +446,10 @@ export class BaseTelegramClient extends EventEmitter {
const stack = this._niceStacks ? new Error().stack : undefined const stack = this._niceStacks ? new Error().stack : undefined
const res = await this.network.call(message, params, stack) const res = await this.network.call(message, params, stack)
await this._cachePeersFrom(res)
if (await this._cachePeersFrom(res)) {
await this.saveStorage()
}
// eslint-disable-next-line @typescript-eslint/no-unsafe-return // eslint-disable-next-line @typescript-eslint/no-unsafe-return
return res return res
@ -495,7 +498,7 @@ export class BaseTelegramClient extends EventEmitter {
/** /**
* Adds all peers from a given object to entity cache in storage. * Adds all peers from a given object to entity cache in storage.
*/ */
async _cachePeersFrom(obj: object): Promise<void> { async _cachePeersFrom(obj: object): Promise<boolean> {
const parsedPeers: ITelegramStorage.PeerInfo[] = [] const parsedPeers: ITelegramStorage.PeerInfo[] = []
let count = 0 let count = 0
@ -553,7 +556,11 @@ export class BaseTelegramClient extends EventEmitter {
if (count > 0) { if (count > 0) {
await this.storage.updatePeers(parsedPeers) await this.storage.updatePeers(parsedPeers)
this.log.debug('cached %d peers', count) this.log.debug('cached %d peers', count)
return true
} }
return false
} }
/** /**