getAllStories: Remove nested queries

This commit is contained in:
Scott Nonnenberg 2024-07-30 11:29:35 -07:00 committed by GitHub
parent a795602e19
commit 95209689a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 328 additions and 34 deletions

View file

@ -0,0 +1,31 @@
// 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';
export const version = 1130;
export function updateToSchemaVersion1130(
currentVersion: number,
db: Database,
logger: LoggerType
): void {
if (currentVersion >= 1130) {
return;
}
db.transaction(() => {
// This is to improve the performance of getAllStories
db.exec(`
CREATE INDEX messages_isStory
ON messages(received_at, sent_at)
WHERE isStory = 1;
`);
})();
db.pragma('user_version = 1130');
logger.info('updateToSchemaVersion1130: success!');
}