fix(client): better storage handling
i suppose?? i mean, it's definitely better than randomly losing updates state and entities, but this might be much slower?
This commit is contained in:
parent
b4a26c6f5b
commit
5fee1d0660
2 changed files with 18 additions and 14 deletions
|
@ -93,6 +93,7 @@ export async function _loadStorage(this: TelegramClient): Promise<void> {
|
|||
export async function _saveStorage(this: TelegramClient): Promise<void> {
|
||||
// save updates state to the session
|
||||
|
||||
try {
|
||||
// before any authorization pts will be undefined
|
||||
if (this._pts !== undefined) {
|
||||
await this.storage.setCommonPts([this._pts, this._date]) // , this._seq])
|
||||
|
@ -106,6 +107,9 @@ export async function _saveStorage(this: TelegramClient): Promise<void> {
|
|||
}
|
||||
|
||||
await this.storage.save?.()
|
||||
} catch (err) {
|
||||
this._emitError(err)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -751,6 +755,7 @@ export function _handleUpdate(
|
|||
})
|
||||
.catch((err) => this._emitError(err))
|
||||
.then(() => this._updLock.release())
|
||||
.then(() => this._saveStorage())
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -311,8 +311,6 @@ export class BaseTelegramClient {
|
|||
})
|
||||
this.primaryConnection.on('usable', async () => {
|
||||
this._keepAliveInterval = setInterval(async () => {
|
||||
await this._saveStorage()
|
||||
|
||||
// according to telethon, "We need to send some content-related request at least hourly
|
||||
// for Telegram to keep delivering updates, otherwise they will just stop even if we're connected.
|
||||
// Do so every 30 minutes"
|
||||
|
@ -690,5 +688,6 @@ export class BaseTelegramClient {
|
|||
}
|
||||
|
||||
await this.storage.updatePeers(parsedPeers)
|
||||
await this._saveStorage()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue