Optimize FTS5

This commit is contained in:
ayumi-signal 2023-11-13 10:30:40 -08:00 committed by GitHub
parent 4ab950c8b2
commit f8b936f258
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 2 deletions

View file

@ -0,0 +1,30 @@
// Copyright 2023 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 = 970;
export function updateToSchemaVersion970(
currentVersion: number,
db: Database,
logger: LoggerType
): void {
if (currentVersion >= 970) {
return;
}
const start = Date.now();
db.transaction(() => {
db.exec(`
INSERT INTO messages_fts(messages_fts) VALUES ('optimize');
`);
db.pragma('user_version = 970');
})();
const duration = Date.now() - start;
logger.info(
`updateToSchemaVersion970: success! fts optimize took ${duration}ms`
);
}

View file

@ -71,10 +71,11 @@ import { updateToSchemaVersion920 } from './920-clean-more-keys';
import { updateToSchemaVersion930 } from './930-fts5-secure-delete';
import { updateToSchemaVersion940 } from './940-fts5-revert';
import { updateToSchemaVersion950 } from './950-fts5-secure-delete';
import { updateToSchemaVersion960 } from './960-untag-pni';
import {
version as MAX_VERSION,
updateToSchemaVersion960,
} from './960-untag-pni';
updateToSchemaVersion970,
} from './970-fts5-optimize';
function updateToSchemaVersion1(
currentVersion: number,
@ -2013,6 +2014,7 @@ export const SCHEMA_VERSIONS = [
updateToSchemaVersion940,
updateToSchemaVersion950,
updateToSchemaVersion960,
updateToSchemaVersion970,
];
export class DBVersionFromFutureError extends Error {