Self-repairing message counter
This commit is contained in:
parent
5780c3d4b8
commit
3f7957c20d
8 changed files with 81 additions and 5 deletions
|
@ -277,6 +277,8 @@ const dataInterface: ClientInterface = {
|
|||
processGroupCallRingCancelation,
|
||||
cleanExpiredGroupCallRings,
|
||||
|
||||
getMaxMessageCounter,
|
||||
|
||||
getStatisticsForLogging,
|
||||
|
||||
// Test-only
|
||||
|
@ -1656,6 +1658,10 @@ async function updateAllConversationColors(
|
|||
);
|
||||
}
|
||||
|
||||
function getMaxMessageCounter(): Promise<number | undefined> {
|
||||
return channels.getMaxMessageCounter();
|
||||
}
|
||||
|
||||
function getStatisticsForLogging(): Promise<Record<string, string>> {
|
||||
return channels.getStatisticsForLogging();
|
||||
}
|
||||
|
|
|
@ -486,6 +486,7 @@ export type DataInterface = {
|
|||
}
|
||||
) => Promise<void>;
|
||||
|
||||
getMaxMessageCounter(): Promise<number | undefined>;
|
||||
getStatisticsForLogging(): Promise<Record<string, string>>;
|
||||
};
|
||||
|
||||
|
|
|
@ -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(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue