Self-repairing message counter

This commit is contained in:
Fedor Indutny 2021-09-15 11:45:22 -07:00 committed by GitHub
parent 5780c3d4b8
commit 3f7957c20d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 81 additions and 5 deletions

View file

@ -268,6 +268,8 @@ const dataInterface: ServerInterface = {
processGroupCallRingCancelation,
cleanExpiredGroupCallRings,
getMaxMessageCounter,
getStatisticsForLogging,
// Server-only
@ -6493,6 +6495,25 @@ async function cleanExpiredGroupCallRings(): Promise<void> {
});
}
async function getMaxMessageCounter(): Promise<number | undefined> {
const db = getInstance();
return db
.prepare<EmptyQuery>(
`
SELECT MAX(counter)
FROM
(
SELECT MAX(received_at) AS counter FROM messages
UNION
SELECT MAX(timestamp) AS counter FROM unprocessed
)
`
)
.pluck()
.get();
}
async function getStatisticsForLogging(): Promise<Record<string, string>> {
const counts = await pProps({
messageCount: getMessageCount(),