Fix messages_preview index

This commit is contained in:
Fedor Indutny 2022-01-07 11:51:41 -08:00 committed by GitHub
parent f49df88877
commit fa8ff2ae4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 68 additions and 7 deletions

View file

@ -0,0 +1,33 @@
// Copyright 2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { Database } from 'better-sqlite3';
import type { LoggerType } from '../../types/Logging';
export default function updateToSchemaVersion49(
currentVersion: number,
db: Database,
logger: LoggerType
): void {
if (currentVersion >= 49) {
return;
}
db.transaction(() => {
db.exec(
`
DROP INDEX messages_preview;
-- Note the omitted 'expiresAt' column in the index. If it is present
-- sqlite can't ORDER BY received_at, sent_at using this index.
CREATE INDEX messages_preview ON messages
(conversationId, shouldAffectPreview, isGroupLeaveEventFromOther, received_at, sent_at);
`
);
db.pragma('user_version = 49');
})();
logger.info('updateToSchemaVersion49: success!');
}

View file

@ -24,6 +24,7 @@ import updateToSchemaVersion45 from './45-stories';
import updateToSchemaVersion46 from './46-optimize-stories';
import updateToSchemaVersion47 from './47-further-optimize';
import updateToSchemaVersion48 from './48-fix-user-initiated-index';
import updateToSchemaVersion49 from './49-fix-preview-index';
function updateToSchemaVersion1(
currentVersion: number,
@ -1911,6 +1912,7 @@ export const SCHEMA_VERSIONS = [
updateToSchemaVersion46,
updateToSchemaVersion47,
updateToSchemaVersion48,
updateToSchemaVersion49,
];
export function updateSchema(db: Database, logger: LoggerType): void {