Revert "Periodically optimize FTS table"

This reverts commit 5dfdde998b.
This commit is contained in:
Fedor Indutny 2023-01-30 15:55:11 -08:00 committed by GitHub
parent de1564fd37
commit e64816830b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 0 additions and 131 deletions

View file

@ -78,7 +78,6 @@ import type {
DeleteSentProtoRecipientOptionsType,
DeleteSentProtoRecipientResultType,
EmojiType,
FTSOptimizationStateType,
GetAllStoriesResultType,
GetConversationRangeCenteredOnMessageResultType,
GetKnownMessageAttachmentsResultType,
@ -342,8 +341,6 @@ const dataInterface: ServerInterface = {
getStatisticsForLogging,
optimizeFTS,
// Server-only
initialize,
@ -5413,48 +5410,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);