Skip to content

Commit

Permalink
Update better-sqlite3 to 8.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
indutny-signal committed Sep 18, 2023
1 parent e4238de commit c25867c
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 141 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -92,7 +92,7 @@
"@popperjs/core": "2.11.6",
"@react-aria/utils": "3.16.0",
"@react-spring/web": "9.5.5",
"@signalapp/better-sqlite3": "8.5.1",
"@signalapp/better-sqlite3": "8.5.2",
"@signalapp/libsignal-client": "0.31.0",
"@signalapp/ringrtc": "2.31.2",
"@signalapp/windows-dummy-keystroke": "1.0.0",
Expand Down
3 changes: 0 additions & 3 deletions ts/background.ts
Expand Up @@ -53,7 +53,6 @@ import { senderCertificateService } from './services/senderCertificate';
import { GROUP_CREDENTIALS_KEY } from './services/groupCredentialFetcher';
import * as KeyboardLayout from './services/keyboardLayout';
import * as StorageService from './services/storage';
import { optimizeFTS } from './services/ftsOptimizer';
import { RoutineProfileRefresher } from './routineProfileRefresh';
import { isOlderThan, toDayMillis } from './util/timestamp';
import { isValidReactionEmoji } from './reactions/isValidReactionEmoji';
Expand Down Expand Up @@ -980,8 +979,6 @@ export async function startApp(): Promise<void> {
if (newVersion) {
await window.Signal.Data.cleanupOrphanedAttachments();

optimizeFTS();

drop(window.Signal.Data.ensureFilePermissions());
}

Expand Down
3 changes: 0 additions & 3 deletions ts/models/conversations.ts
Expand Up @@ -87,7 +87,6 @@ import {
notificationService,
} from '../services/notifications';
import { storageServiceUploadJob } from '../services/storage';
import { scheduleOptimizeFTS } from '../services/ftsOptimizer';
import { getSendOptions } from '../util/getSendOptions';
import { isConversationAccepted } from '../util/isConversationAccepted';
import {
Expand Down Expand Up @@ -4772,8 +4771,6 @@ export class ConversationModel extends window.Backbone
await window.Signal.Data.removeAllMessagesInConversation(this.id, {
logId: this.idForLogging(),
});

scheduleOptimizeFTS();
}

getTitle(options?: { isShort?: boolean }): string {
Expand Down
3 changes: 0 additions & 3 deletions ts/models/messages.ts
Expand Up @@ -70,7 +70,6 @@ import { migrateLegacyReadStatus } from '../messages/migrateLegacyReadStatus';
import { migrateLegacySendAttributes } from '../messages/migrateLegacySendAttributes';
import { getOwn } from '../util/getOwn';
import { markRead, markViewed } from '../services/MessageUpdater';
import { scheduleOptimizeFTS } from '../services/ftsOptimizer';
import {
isDirectConversation,
isGroup,
Expand Down Expand Up @@ -1158,8 +1157,6 @@ export class MessageModel extends window.Backbone.Model<MessageAttributesType> {
}

await window.Signal.Data.deleteSentProtoByMessageId(this.id);

scheduleOptimizeFTS();
}

override isEmpty(): boolean {
Expand Down
5 changes: 0 additions & 5 deletions ts/services/expiringMessagesDeletion.ts
Expand Up @@ -9,7 +9,6 @@ import { clearTimeoutIfNecessary } from '../util/clearTimeoutIfNecessary';
import { sleep } from '../util/sleep';
import { SECOND } from '../util/durations';
import * as Errors from '../types/errors';
import { scheduleOptimizeFTS } from './ftsOptimizer';

class ExpiringMessagesDeletionService {
public update: typeof this.checkExpiringMessages;
Expand Down Expand Up @@ -55,10 +54,6 @@ class ExpiringMessagesDeletionService {
window.reduxActions.conversations.messageExpired(message.id);
});
});

if (messages.length > 0) {
scheduleOptimizeFTS();
}
} catch (error) {
window.SignalContext.log.error(
'destroyExpiredMessages: Error deleting expired messages',
Expand Down
63 changes: 0 additions & 63 deletions ts/services/ftsOptimizer.ts

This file was deleted.

9 changes: 0 additions & 9 deletions ts/sql/Interface.ts
Expand Up @@ -411,11 +411,6 @@ export type GetAllStoriesResultType = ReadonlyArray<
}
>;

export type FTSOptimizationStateType = Readonly<{
steps: number;
done?: boolean;
}>;

export type EditedMessageType = Readonly<{
conversationId: string;
messageId: string;
Expand Down Expand Up @@ -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 & {
Expand Down
48 changes: 0 additions & 48 deletions ts/sql/Server.ts
Expand Up @@ -93,7 +93,6 @@ import type {
DeleteSentProtoRecipientResultType,
EditedMessageType,
EmojiType,
FTSOptimizationStateType,
GetAllStoriesResultType,
GetConversationRangeCenteredOnMessageResultType,
GetKnownMessageAttachmentsResultType,
Expand Down Expand Up @@ -403,8 +402,6 @@ const dataInterface: ServerInterface = {

getStatisticsForLogging,

optimizeFTS,

// Server-only

initialize,
Expand Down Expand Up @@ -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');
`);
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions ts/sql/migrations/950-fts5-secure-delete.ts
@@ -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!');
}
6 changes: 4 additions & 2 deletions ts/sql/migrations/index.ts
Expand Up @@ -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,
Expand Down Expand Up @@ -2009,6 +2010,7 @@ export const SCHEMA_VERSIONS = [
updateToSchemaVersion920,
updateToSchemaVersion930,
updateToSchemaVersion940,
updateToSchemaVersion950,
];

export function updateSchema(db: Database, logger: LoggerType): void {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Expand Up @@ -3355,10 +3355,10 @@
"@react-types/overlays" "^3.7.1"
"@react-types/shared" "^3.18.0"

"@signalapp/better-sqlite3@8.5.1":
version "8.5.1"
resolved "https://registry.yarnpkg.com/@signalapp/better-sqlite3/-/better-sqlite3-8.5.1.tgz#b2bcf69d29f4d01cfecf2ad940ecd138f32470b3"
integrity sha512-s9NDufkbTAuKShFmEg7eOew4cprdLI7mn5ISQFKgcFSiA/TG3wgLJW5wUff9S2vednIV9utyqRJZXrwcSAEQUg==
"@signalapp/better-sqlite3@8.5.2":
version "8.5.2"
resolved "https://registry.yarnpkg.com/@signalapp/better-sqlite3/-/better-sqlite3-8.5.2.tgz#910669f44e76a46d06df45fabefcd3ac2e7c4cce"
integrity sha512-t7XalDxuRP115EratM6i1kbvIXJvzETcl8wqnt3NlWZdzil7kelS/RYz+PE1G+z8ZwtFyn/ViAFMt76AsArifw==
dependencies:
bindings "^1.5.0"
tar "^6.1.0"
Expand Down

0 comments on commit c25867c

Please sign in to comment.