Optimize markAllCallHistoryReadSync
This commit is contained in:
parent
133f12cfd1
commit
01dda86538
4 changed files with 215 additions and 37 deletions
|
@ -0,0 +1,63 @@
|
|||
// Copyright 2024 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
import { sql } from '../util';
|
||||
|
||||
export const version = 1100;
|
||||
|
||||
export function updateToSchemaVersion1100(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1100) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
const [query] = sql`
|
||||
-- Fix: Query went from readStatus to seenStatus but index wasn't updated
|
||||
DROP INDEX IF EXISTS messages_callHistory_readStatus;
|
||||
DROP INDEX IF EXISTS messages_callHistory_seenStatus;
|
||||
CREATE INDEX messages_callHistory_seenStatus
|
||||
ON messages (type, seenStatus)
|
||||
WHERE type IS 'call-history';
|
||||
|
||||
-- Update to index created in 89: add sent_at to make it covering, and where clause to make it smaller
|
||||
DROP INDEX IF EXISTS messages_call;
|
||||
CREATE INDEX messages_call ON messages
|
||||
(type, conversationId, callId, sent_at)
|
||||
WHERE type IS 'call-history';
|
||||
|
||||
-- Update to index created in 89: add callId and peerId to make it covering
|
||||
DROP INDEX IF EXISTS callsHistory_order;
|
||||
CREATE INDEX callsHistory_order ON callsHistory
|
||||
(timestamp DESC, callId, peerId);
|
||||
|
||||
-- Update to index created in 89: add timestamp for querying by order and callId to make it covering
|
||||
DROP INDEX IF EXISTS callsHistory_byConversation;
|
||||
DROP INDEX IF EXISTS callsHistory_byConversation_order;
|
||||
CREATE INDEX callsHistory_byConversation_order ON callsHistory (peerId, timestamp DESC, callId);
|
||||
|
||||
-- Optimize markAllCallHistoryRead
|
||||
DROP INDEX IF EXISTS messages_callHistory_markReadBefore;
|
||||
CREATE INDEX messages_callHistory_markReadBefore
|
||||
ON messages (type, seenStatus, sent_at DESC)
|
||||
WHERE type IS 'call-history';
|
||||
|
||||
-- Optimize markAllCallHistoryReadInConversation
|
||||
DROP INDEX IF EXISTS messages_callHistory_markReadByConversationBefore;
|
||||
CREATE INDEX messages_callHistory_markReadByConversationBefore
|
||||
ON messages (type, conversationId, seenStatus, sent_at DESC)
|
||||
WHERE type IS 'call-history';
|
||||
`;
|
||||
|
||||
db.exec(query);
|
||||
})();
|
||||
|
||||
db.pragma('user_version = 1100');
|
||||
|
||||
logger.info('updateToSchemaVersion1100: success!');
|
||||
}
|
|
@ -84,10 +84,11 @@ import { updateToSchemaVersion1050 } from './1050-group-send-endorsements';
|
|||
import { updateToSchemaVersion1060 } from './1060-addressable-messages-and-sync-tasks';
|
||||
import { updateToSchemaVersion1070 } from './1070-attachment-backup';
|
||||
import { updateToSchemaVersion1080 } from './1080-nondisappearing-addressable';
|
||||
import { updateToSchemaVersion1090 } from './1090-message-delete-indexes';
|
||||
import {
|
||||
updateToSchemaVersion1090,
|
||||
updateToSchemaVersion1100,
|
||||
version as MAX_VERSION,
|
||||
} from './1090-message-delete-indexes';
|
||||
} from './1100-optimize-mark-call-history-read-in-conversation';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -2040,6 +2041,7 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion1070,
|
||||
updateToSchemaVersion1080,
|
||||
updateToSchemaVersion1090,
|
||||
updateToSchemaVersion1100,
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue