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,19 +93,23 @@ export async function _loadStorage(this: TelegramClient): Promise<void> {
|
||||||
export async function _saveStorage(this: TelegramClient): Promise<void> {
|
export async function _saveStorage(this: TelegramClient): Promise<void> {
|
||||||
// save updates state to the session
|
// save updates state to the session
|
||||||
|
|
||||||
// before any authorization pts will be undefined
|
try {
|
||||||
if (this._pts !== undefined) {
|
// before any authorization pts will be undefined
|
||||||
await this.storage.setCommonPts([this._pts, this._date]) // , this._seq])
|
if (this._pts !== undefined) {
|
||||||
await this.storage.setManyChannelPts(this._cpts)
|
await this.storage.setCommonPts([this._pts, this._date]) // , this._seq])
|
||||||
}
|
await this.storage.setManyChannelPts(this._cpts)
|
||||||
if (this._userId !== null) {
|
}
|
||||||
await this.storage.setSelf({
|
if (this._userId !== null) {
|
||||||
userId: this._userId,
|
await this.storage.setSelf({
|
||||||
isBot: this._isBot,
|
userId: this._userId,
|
||||||
})
|
isBot: this._isBot,
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
|
||||||
await this.storage.save?.()
|
await this.storage.save?.()
|
||||||
|
} catch (err) {
|
||||||
|
this._emitError(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -751,6 +755,7 @@ export function _handleUpdate(
|
||||||
})
|
})
|
||||||
.catch((err) => this._emitError(err))
|
.catch((err) => this._emitError(err))
|
||||||
.then(() => this._updLock.release())
|
.then(() => this._updLock.release())
|
||||||
|
.then(() => this._saveStorage())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -311,8 +311,6 @@ export class BaseTelegramClient {
|
||||||
})
|
})
|
||||||
this.primaryConnection.on('usable', async () => {
|
this.primaryConnection.on('usable', async () => {
|
||||||
this._keepAliveInterval = setInterval(async () => {
|
this._keepAliveInterval = setInterval(async () => {
|
||||||
await this._saveStorage()
|
|
||||||
|
|
||||||
// according to telethon, "We need to send some content-related request at least hourly
|
// 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.
|
// for Telegram to keep delivering updates, otherwise they will just stop even if we're connected.
|
||||||
// Do so every 30 minutes"
|
// Do so every 30 minutes"
|
||||||
|
@ -690,5 +688,6 @@ export class BaseTelegramClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.storage.updatePeers(parsedPeers)
|
await this.storage.updatePeers(parsedPeers)
|
||||||
|
await this._saveStorage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue