Update better-sqlite3 to 8.5.2
This commit is contained in:
parent
e4238de4db
commit
c25867c737
11 changed files with 41 additions and 141 deletions
|
@ -411,11 +411,6 @@ export type GetAllStoriesResultType = ReadonlyArray<
|
|||
}
|
||||
>;
|
||||
|
||||
export type FTSOptimizationStateType = Readonly<{
|
||||
steps: number;
|
||||
done?: boolean;
|
||||
}>;
|
||||
|
||||
export type EditedMessageType = Readonly<{
|
||||
conversationId: string;
|
||||
messageId: string;
|
||||
|
@ -823,10 +818,6 @@ export type DataInterface = {
|
|||
getMaxMessageCounter(): Promise<number | undefined>;
|
||||
|
||||
getStatisticsForLogging(): Promise<Record<string, string>>;
|
||||
|
||||
optimizeFTS: (
|
||||
state?: FTSOptimizationStateType
|
||||
) => Promise<FTSOptimizationStateType | undefined>;
|
||||
};
|
||||
|
||||
export type ServerInterface = DataInterface & {
|
||||
|
|
|
@ -93,7 +93,6 @@ import type {
|
|||
DeleteSentProtoRecipientResultType,
|
||||
EditedMessageType,
|
||||
EmojiType,
|
||||
FTSOptimizationStateType,
|
||||
GetAllStoriesResultType,
|
||||
GetConversationRangeCenteredOnMessageResultType,
|
||||
GetKnownMessageAttachmentsResultType,
|
||||
|
@ -403,8 +402,6 @@ const dataInterface: ServerInterface = {
|
|||
|
||||
getStatisticsForLogging,
|
||||
|
||||
optimizeFTS,
|
||||
|
||||
// Server-only
|
||||
|
||||
initialize,
|
||||
|
@ -2222,7 +2219,6 @@ async function _removeAllMessages(): Promise<void> {
|
|||
const db = getInstance();
|
||||
db.exec(`
|
||||
DELETE FROM messages;
|
||||
INSERT INTO messages_fts(messages_fts) VALUES('optimize');
|
||||
`);
|
||||
}
|
||||
|
||||
|
@ -5548,8 +5544,6 @@ async function removeAll(): Promise<void> {
|
|||
DELETE FROM unprocessed;
|
||||
DELETE FROM uninstalled_sticker_packs;
|
||||
|
||||
INSERT INTO messages_fts(messages_fts) VALUES('optimize');
|
||||
|
||||
--- Re-create the messages delete trigger
|
||||
--- See migration 45
|
||||
CREATE TRIGGER messages_on_delete AFTER DELETE ON messages BEGIN
|
||||
|
@ -6133,48 +6127,6 @@ async function removeKnownDraftAttachments(
|
|||
return Object.keys(lookup);
|
||||
}
|
||||
|
||||
const OPTIMIZE_FTS_PAGE_COUNT = 64;
|
||||
|
||||
// This query is incremental. It gets the `state` from the return value of
|
||||
// previous `optimizeFTS` call. When `state.done` is `true` - optimization is
|
||||
// complete.
|
||||
async function optimizeFTS(
|
||||
state?: FTSOptimizationStateType
|
||||
): Promise<FTSOptimizationStateType | undefined> {
|
||||
// See https://www.sqlite.org/fts5.html#the_merge_command
|
||||
let pageCount = OPTIMIZE_FTS_PAGE_COUNT;
|
||||
if (state === undefined) {
|
||||
pageCount = -pageCount;
|
||||
}
|
||||
const db = getInstance();
|
||||
const getChanges = prepare(db, 'SELECT total_changes() as changes;', {
|
||||
pluck: true,
|
||||
});
|
||||
|
||||
const changeDifference = db.transaction(() => {
|
||||
const before: number = getChanges.get({});
|
||||
|
||||
prepare(
|
||||
db,
|
||||
`
|
||||
INSERT INTO messages_fts(messages_fts, rank) VALUES ('merge', $pageCount);
|
||||
`
|
||||
).run({ pageCount });
|
||||
|
||||
const after: number = getChanges.get({});
|
||||
|
||||
return after - before;
|
||||
})();
|
||||
|
||||
const nextSteps = (state?.steps ?? 0) + 1;
|
||||
|
||||
// From documentation:
|
||||
// "If the difference is less than 2, then the 'merge' command was a no-op"
|
||||
const done = changeDifference < 2;
|
||||
|
||||
return { steps: nextSteps, done };
|
||||
}
|
||||
|
||||
async function getJobsInQueue(queueType: string): Promise<Array<StoredJob>> {
|
||||
const db = getInstance();
|
||||
return getJobsInQueueSync(db, queueType);
|
||||
|
|
32
ts/sql/migrations/950-fts5-secure-delete.ts
Normal file
32
ts/sql/migrations/950-fts5-secure-delete.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
// 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 = 950;
|
||||
|
||||
export function updateToSchemaVersion950(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 950) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(`
|
||||
--- Enable 'secure-delete'
|
||||
INSERT INTO messages_fts
|
||||
(messages_fts, rank)
|
||||
VALUES
|
||||
('secure-delete', 1);
|
||||
`);
|
||||
|
||||
db.pragma('user_version = 950');
|
||||
})();
|
||||
|
||||
logger.info('updateToSchemaVersion950: success!');
|
||||
}
|
|
@ -69,10 +69,11 @@ import updateToSchemaVersion90 from './90-delete-story-reply-screenshot';
|
|||
import updateToSchemaVersion91 from './91-clean-keys';
|
||||
import { updateToSchemaVersion920 } from './920-clean-more-keys';
|
||||
import { updateToSchemaVersion930 } from './930-fts5-secure-delete';
|
||||
import { updateToSchemaVersion940 } from './940-fts5-revert';
|
||||
import {
|
||||
version as MAX_VERSION,
|
||||
updateToSchemaVersion940,
|
||||
} from './940-fts5-revert';
|
||||
updateToSchemaVersion950,
|
||||
} from './950-fts5-secure-delete';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -2009,6 +2010,7 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion920,
|
||||
updateToSchemaVersion930,
|
||||
updateToSchemaVersion940,
|
||||
updateToSchemaVersion950,
|
||||
];
|
||||
|
||||
export function updateSchema(db: Database, logger: LoggerType): void {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue