Parallelize SQL queries
This commit is contained in:
parent
86b4da1ec2
commit
c64762858e
178 changed files with 3377 additions and 3618 deletions
|
@ -2,12 +2,17 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { noop } from 'lodash';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
|
||||
import type { ReadableDB, WritableDB } from '../../sql/Interface';
|
||||
import { SCHEMA_VERSIONS } from '../../sql/migrations';
|
||||
import { consoleLogger } from '../../util/consoleLogger';
|
||||
|
||||
export function updateToVersion(db: Database, version: number): void {
|
||||
export function createDB(): WritableDB {
|
||||
return new SQL(':memory:') as WritableDB;
|
||||
}
|
||||
|
||||
export function updateToVersion(db: WritableDB, version: number): void {
|
||||
const startVersion = db.pragma('user_version', { simple: true });
|
||||
|
||||
const silentLogger = {
|
||||
|
@ -32,7 +37,11 @@ type TableRows = ReadonlyArray<
|
|||
Record<string, string | number | null | Record<string, unknown>>
|
||||
>;
|
||||
|
||||
export function insertData(db: Database, table: string, rows: TableRows): void {
|
||||
export function insertData(
|
||||
db: WritableDB,
|
||||
table: string,
|
||||
rows: TableRows
|
||||
): void {
|
||||
for (const row of rows) {
|
||||
db.prepare(
|
||||
`
|
||||
|
@ -52,7 +61,7 @@ export function insertData(db: Database, table: string, rows: TableRows): void {
|
|||
}
|
||||
}
|
||||
|
||||
export function getTableData(db: Database, table: string): TableRows {
|
||||
export function getTableData(db: ReadableDB, table: string): TableRows {
|
||||
return db
|
||||
.prepare(`SELECT * FROM ${table}`)
|
||||
.all()
|
||||
|
|
|
@ -2,23 +2,21 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
|
||||
import data, { setupTests, teardownTests } from '../../sql/Server';
|
||||
import { insertData, getTableData } from './helpers';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { migrateConversationMessages, setupTests } from '../../sql/Server';
|
||||
import { createDB, insertData, getTableData } from './helpers';
|
||||
|
||||
describe('SQL/migrateConversationMessages', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
setupTests(db);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
db.close();
|
||||
teardownTests();
|
||||
});
|
||||
|
||||
function compactify(
|
||||
|
@ -33,7 +31,7 @@ describe('SQL/migrateConversationMessages', () => {
|
|||
};
|
||||
}
|
||||
|
||||
it('should leave irrelevant messages intact', async () => {
|
||||
it('should leave irrelevant messages intact', () => {
|
||||
insertData(db, 'messages', [
|
||||
{
|
||||
id: 'irrelevant',
|
||||
|
@ -44,7 +42,7 @@ describe('SQL/migrateConversationMessages', () => {
|
|||
},
|
||||
]);
|
||||
|
||||
await data.migrateConversationMessages('obsolete', 'current');
|
||||
migrateConversationMessages(db, 'obsolete', 'current');
|
||||
|
||||
assert.deepStrictEqual(getTableData(db, 'messages').map(compactify), [
|
||||
{
|
||||
|
@ -57,7 +55,7 @@ describe('SQL/migrateConversationMessages', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('should update conversationId and send state', async () => {
|
||||
it('should update conversationId and send state', () => {
|
||||
insertData(db, 'messages', [
|
||||
{
|
||||
id: 'no-send-state',
|
||||
|
@ -82,7 +80,7 @@ describe('SQL/migrateConversationMessages', () => {
|
|||
},
|
||||
]);
|
||||
|
||||
await data.migrateConversationMessages('obsolete', 'current');
|
||||
migrateConversationMessages(db, 'obsolete', 'current');
|
||||
|
||||
assert.deepStrictEqual(getTableData(db, 'messages').map(compactify), [
|
||||
{
|
||||
|
|
|
@ -2,21 +2,19 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
|
||||
import { jsonToObject, sql } from '../../sql/util';
|
||||
import { updateToVersion } from './helpers';
|
||||
import type { MessageType } from '../../sql/Interface';
|
||||
import { createDB, updateToVersion } from './helpers';
|
||||
import type { WritableDB, MessageType } from '../../sql/Interface';
|
||||
import { ReadStatus } from '../../messages/MessageReadStatus';
|
||||
import { SeenStatus } from '../../MessageSeenStatus';
|
||||
|
||||
describe('SQL/updateToSchemaVersion1000', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 990);
|
||||
});
|
||||
|
||||
|
|
|
@ -2,15 +2,14 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
|
||||
import { normalizeAci } from '../../util/normalizeAci';
|
||||
import { insertData, getTableData, updateToVersion } from './helpers';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { createDB, insertData, getTableData, updateToVersion } from './helpers';
|
||||
|
||||
describe('SQL/updateToSchemaVersion1020', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
const OUR_ACI = normalizeAci(
|
||||
generateGuid(),
|
||||
|
@ -22,7 +21,7 @@ describe('SQL/updateToSchemaVersion1020', () => {
|
|||
);
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 1010);
|
||||
});
|
||||
|
||||
|
|
|
@ -2,19 +2,17 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
import { sql } from '../../sql/util';
|
||||
import { updateToVersion } from './helpers';
|
||||
import type { MessageType } from '../../sql/Interface';
|
||||
import { createDB, updateToVersion } from './helpers';
|
||||
import type { WritableDB, MessageType } from '../../sql/Interface';
|
||||
import { MessageRequestResponseEvent } from '../../types/MessageRequestResponseEvent';
|
||||
|
||||
describe('SQL/updateToSchemaVersion1030', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 1020);
|
||||
});
|
||||
|
||||
|
|
|
@ -2,17 +2,16 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
import { omit } from 'lodash';
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
|
||||
import type { ReadableDB, WritableDB } from '../../sql/Interface';
|
||||
import { jsonToObject, objectToJSON, sql, sqlJoin } from '../../sql/util';
|
||||
import { updateToVersion } from './helpers';
|
||||
import { createDB, updateToVersion } from './helpers';
|
||||
import type { LegacyAttachmentDownloadJobType } from '../../sql/migrations/1040-undownloaded-backed-up-media';
|
||||
import type { AttachmentType } from '../../types/Attachment';
|
||||
import type { AttachmentDownloadJobType } from '../../types/AttachmentDownload';
|
||||
import { IMAGE_JPEG } from '../../types/MIME';
|
||||
|
||||
function getAttachmentDownloadJobs(db: Database) {
|
||||
function getAttachmentDownloadJobs(db: ReadableDB) {
|
||||
const [query] = sql`
|
||||
SELECT * FROM attachment_downloads ORDER BY receivedAt DESC;
|
||||
`;
|
||||
|
@ -31,7 +30,7 @@ type UnflattenedAttachmentDownloadJobType = Omit<
|
|||
'digest' | 'contentType' | 'size'
|
||||
>;
|
||||
function insertNewJob(
|
||||
db: Database,
|
||||
db: WritableDB,
|
||||
job: UnflattenedAttachmentDownloadJobType,
|
||||
addMessageFirst: boolean = true
|
||||
): void {
|
||||
|
@ -82,10 +81,10 @@ function insertNewJob(
|
|||
|
||||
describe('SQL/updateToSchemaVersion1040', () => {
|
||||
describe('Storing of new attachment jobs', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 1040);
|
||||
});
|
||||
|
||||
|
@ -338,10 +337,10 @@ describe('SQL/updateToSchemaVersion1040', () => {
|
|||
});
|
||||
|
||||
describe('existing jobs are transferred', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 1030);
|
||||
});
|
||||
|
||||
|
@ -462,7 +461,7 @@ describe('SQL/updateToSchemaVersion1040', () => {
|
|||
});
|
||||
|
||||
function insertLegacyJob(
|
||||
db: Database,
|
||||
db: WritableDB,
|
||||
job: Partial<LegacyAttachmentDownloadJobType>
|
||||
): void {
|
||||
db.prepare('INSERT OR REPLACE INTO messages (id) VALUES ($id)').run({
|
||||
|
|
|
@ -2,17 +2,16 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
|
||||
import {
|
||||
getAllSyncTasksSync,
|
||||
getMostRecentAddressableMessagesSync,
|
||||
removeSyncTaskByIdSync,
|
||||
saveSyncTasksSync,
|
||||
getAllSyncTasks,
|
||||
getMostRecentAddressableMessages,
|
||||
removeSyncTaskById,
|
||||
saveSyncTasks,
|
||||
} from '../../sql/Server';
|
||||
import { insertData, updateToVersion } from './helpers';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { insertData, updateToVersion, createDB } from './helpers';
|
||||
import { MAX_SYNC_TASK_ATTEMPTS } from '../../util/syncTasks.types';
|
||||
import { WEEK } from '../../util/durations';
|
||||
|
||||
|
@ -34,9 +33,9 @@ function generateMessage(json: MessageAttributesType) {
|
|||
}
|
||||
|
||||
describe('SQL/updateToSchemaVersion1060', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 1060);
|
||||
});
|
||||
|
||||
|
@ -117,10 +116,7 @@ describe('SQL/updateToSchemaVersion1060', () => {
|
|||
}),
|
||||
]);
|
||||
|
||||
const messages = getMostRecentAddressableMessagesSync(
|
||||
db,
|
||||
conversationId
|
||||
);
|
||||
const messages = getMostRecentAddressableMessages(db, conversationId);
|
||||
|
||||
assert.lengthOf(messages, 3);
|
||||
assert.deepEqual(messages, [
|
||||
|
@ -151,7 +147,7 @@ describe('SQL/updateToSchemaVersion1060', () => {
|
|||
]);
|
||||
});
|
||||
|
||||
it('ensures that index is used for getMostRecentAddressableMessagesSync, with storyId', () => {
|
||||
it('ensures that index is used for getMostRecentAddressableMessages, with storyId', () => {
|
||||
const { detail } = db
|
||||
.prepare(
|
||||
`
|
||||
|
@ -219,14 +215,14 @@ describe('SQL/updateToSchemaVersion1060', () => {
|
|||
},
|
||||
];
|
||||
|
||||
saveSyncTasksSync(db, expected);
|
||||
saveSyncTasks(db, expected);
|
||||
|
||||
const actual = getAllSyncTasksSync(db);
|
||||
const actual = getAllSyncTasks(db);
|
||||
assert.deepEqual(expected, actual, 'before delete');
|
||||
|
||||
removeSyncTaskByIdSync(db, expected[1].id);
|
||||
removeSyncTaskById(db, expected[1].id);
|
||||
|
||||
const actualAfterDelete = getAllSyncTasksSync(db);
|
||||
const actualAfterDelete = getAllSyncTasks(db);
|
||||
assert.deepEqual(
|
||||
[
|
||||
{ ...expected[0], attempts: 2 },
|
||||
|
@ -291,9 +287,9 @@ describe('SQL/updateToSchemaVersion1060', () => {
|
|||
},
|
||||
];
|
||||
|
||||
saveSyncTasksSync(db, expected);
|
||||
saveSyncTasks(db, expected);
|
||||
|
||||
const actual = getAllSyncTasksSync(db);
|
||||
const actual = getAllSyncTasks(db);
|
||||
|
||||
assert.lengthOf(actual, 3);
|
||||
assert.deepEqual([expected[1], expected[2], expected[3]], actual);
|
||||
|
|
|
@ -2,12 +2,11 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
|
||||
import { getMostRecentAddressableNondisappearingMessagesSync } from '../../sql/Server';
|
||||
import { insertData, updateToVersion } from './helpers';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { getMostRecentAddressableNondisappearingMessages } from '../../sql/Server';
|
||||
import { createDB, insertData, updateToVersion } from './helpers';
|
||||
|
||||
import type { MessageAttributesType } from '../../model-types';
|
||||
import { DurationInSeconds } from '../../util/durations/duration-in-seconds';
|
||||
|
@ -28,9 +27,9 @@ function generateMessage(json: MessageAttributesType) {
|
|||
}
|
||||
|
||||
describe('SQL/updateToSchemaVersion1080', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 1080);
|
||||
});
|
||||
|
||||
|
@ -111,7 +110,7 @@ describe('SQL/updateToSchemaVersion1080', () => {
|
|||
}),
|
||||
]);
|
||||
|
||||
const messages = getMostRecentAddressableNondisappearingMessagesSync(
|
||||
const messages = getMostRecentAddressableNondisappearingMessages(
|
||||
db,
|
||||
conversationId
|
||||
);
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { updateToVersion } from './helpers';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { createDB, updateToVersion } from './helpers';
|
||||
|
||||
describe('SQL/updateToSchemaVersion1090', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 1090);
|
||||
});
|
||||
|
||||
|
|
|
@ -2,11 +2,9 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { findLast } from 'lodash';
|
||||
import { insertData, updateToVersion } from './helpers';
|
||||
import { markAllCallHistoryReadSync } from '../../sql/Server';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { markAllCallHistoryRead } from '../../sql/Server';
|
||||
import { SeenStatus } from '../../MessageSeenStatus';
|
||||
import { CallMode } from '../../types/Calling';
|
||||
import {
|
||||
|
@ -15,11 +13,12 @@ import {
|
|||
DirectCallStatus,
|
||||
} from '../../types/CallDisposition';
|
||||
import { strictAssert } from '../../util/assert';
|
||||
import { createDB, insertData, updateToVersion } from './helpers';
|
||||
|
||||
describe('SQL/updateToSchemaVersion1100', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 1100);
|
||||
});
|
||||
|
||||
|
@ -73,7 +72,7 @@ describe('SQL/updateToSchemaVersion1100', () => {
|
|||
};
|
||||
|
||||
const start = performance.now();
|
||||
markAllCallHistoryReadSync(db, target, true);
|
||||
markAllCallHistoryRead(db, target, true);
|
||||
const end = performance.now();
|
||||
assert.isBelow(end - start, 50);
|
||||
});
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { updateToVersion } from './helpers';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { createDB, updateToVersion } from './helpers';
|
||||
|
||||
describe('SQL/updateToSchemaVersion1120', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 1120);
|
||||
});
|
||||
|
||||
|
|
|
@ -2,12 +2,10 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
import { range } from 'lodash';
|
||||
|
||||
import { insertData, updateToVersion } from './helpers';
|
||||
import { createDB, insertData, updateToVersion } from './helpers';
|
||||
import type {
|
||||
AciString,
|
||||
PniString,
|
||||
|
@ -16,6 +14,7 @@ import type {
|
|||
import { normalizePni } from '../../types/ServiceId';
|
||||
import { normalizeAci } from '../../util/normalizeAci';
|
||||
import type {
|
||||
WritableDB,
|
||||
KyberPreKeyType,
|
||||
PreKeyType,
|
||||
SignedPreKeyType,
|
||||
|
@ -49,7 +48,7 @@ type TestingSignedKey = Omit<
|
|||
};
|
||||
|
||||
describe('SQL/updateToSchemaVersion87(cleanup)', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
const OUR_ACI = normalizeAci(
|
||||
generateGuid(),
|
||||
|
@ -62,7 +61,7 @@ describe('SQL/updateToSchemaVersion87(cleanup)', () => {
|
|||
let idCount = 0;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 86);
|
||||
});
|
||||
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
|
||||
import { updateToVersion, insertData, getTableData } from './helpers';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { createDB, updateToVersion, insertData, getTableData } from './helpers';
|
||||
|
||||
const CONVO_ID = generateGuid();
|
||||
const GROUP_ID = generateGuid();
|
||||
|
@ -17,10 +16,10 @@ const OUR_PNI = generateGuid();
|
|||
const THEIR_UUID = generateGuid();
|
||||
|
||||
describe('SQL/updateToSchemaVersion88', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 86);
|
||||
|
||||
insertData(db, 'items', [
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
|
||||
import { jsonToObject, sql } from '../../sql/util';
|
||||
|
@ -22,14 +20,14 @@ import type {
|
|||
} from '../../sql/migrations/89-call-history';
|
||||
import { getCallIdFromEra } from '../../util/callDisposition';
|
||||
import { isValidUuid } from '../../util/isValidUuid';
|
||||
import { updateToVersion } from './helpers';
|
||||
import type { MessageType } from '../../sql/Interface';
|
||||
import { createDB, updateToVersion } from './helpers';
|
||||
import type { WritableDB, MessageType } from '../../sql/Interface';
|
||||
|
||||
describe('SQL/updateToSchemaVersion89', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 88);
|
||||
});
|
||||
|
||||
|
|
|
@ -1,17 +1,16 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { assert } from 'chai';
|
||||
|
||||
import { updateToVersion, insertData, getTableData } from './helpers';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { createDB, updateToVersion, insertData, getTableData } from './helpers';
|
||||
|
||||
describe('SQL/updateToSchemaVersion90', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
|
|
@ -2,16 +2,14 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
import { range } from 'lodash';
|
||||
|
||||
import { getTableData, insertData, updateToVersion } from './helpers';
|
||||
import { createDB, getTableData, insertData, updateToVersion } from './helpers';
|
||||
import type { ServiceIdString } from '../../types/ServiceId';
|
||||
import { normalizePni } from '../../types/ServiceId';
|
||||
import { normalizeAci } from '../../util/normalizeAci';
|
||||
import type { PreKeyType } from '../../sql/Interface';
|
||||
import type { WritableDB, PreKeyType } from '../../sql/Interface';
|
||||
|
||||
type TestingPreKey = Omit<
|
||||
PreKeyType,
|
||||
|
@ -21,7 +19,7 @@ type TestingPreKey = Omit<
|
|||
};
|
||||
|
||||
describe('SQL/updateToSchemaVersion91', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
const OUR_ACI = normalizeAci(generateGuid(), 'updateToSchemaVersion91 test');
|
||||
const OUR_PNI = normalizePni(
|
||||
|
@ -31,7 +29,7 @@ describe('SQL/updateToSchemaVersion91', () => {
|
|||
let idCount = 0;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 90);
|
||||
});
|
||||
|
||||
|
|
|
@ -2,16 +2,18 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
import { range } from 'lodash';
|
||||
|
||||
import { insertData, updateToVersion } from './helpers';
|
||||
import { createDB, insertData, updateToVersion } from './helpers';
|
||||
import type { ServiceIdString } from '../../types/ServiceId';
|
||||
import { normalizePni } from '../../types/ServiceId';
|
||||
import { normalizeAci } from '../../util/normalizeAci';
|
||||
import type { KyberPreKeyType, SignedPreKeyType } from '../../sql/Interface';
|
||||
import type {
|
||||
WritableDB,
|
||||
KyberPreKeyType,
|
||||
SignedPreKeyType,
|
||||
} from '../../sql/Interface';
|
||||
|
||||
type TestingKyberKey = Omit<
|
||||
KyberPreKeyType,
|
||||
|
@ -27,7 +29,7 @@ type TestingSignedKey = Omit<
|
|||
};
|
||||
|
||||
describe('SQL/updateToSchemaVersion92', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
const OUR_ACI = normalizeAci(generateGuid(), 'updateToSchemaVersion92 test');
|
||||
const OUR_PNI = normalizePni(
|
||||
|
@ -37,7 +39,7 @@ describe('SQL/updateToSchemaVersion92', () => {
|
|||
let idCount = 0;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 91);
|
||||
});
|
||||
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
|
||||
import { updateToVersion, insertData, getTableData } from './helpers';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { createDB, updateToVersion, insertData, getTableData } from './helpers';
|
||||
|
||||
const CONVO_ID = generateGuid();
|
||||
const OUR_ACI = generateGuid();
|
||||
|
@ -14,10 +13,10 @@ const OUR_UNPREFIXED_PNI = generateGuid();
|
|||
const OUR_PREFIXED_PNI = `PNI:${OUR_UNPREFIXED_PNI}`;
|
||||
|
||||
describe('SQL/updateToSchemaVersion960', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 950);
|
||||
|
||||
insertData(db, 'items', [
|
||||
|
|
|
@ -2,16 +2,15 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
|
||||
import { updateToVersion, insertData, getTableData } from './helpers';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { createDB, updateToVersion, insertData, getTableData } from './helpers';
|
||||
|
||||
describe('SQL/updateToSchemaVersion990', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
updateToVersion(db, 980);
|
||||
});
|
||||
|
||||
|
|
|
@ -2,27 +2,22 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import { assert } from 'chai';
|
||||
import type { Database } from '@signalapp/better-sqlite3';
|
||||
import SQL from '@signalapp/better-sqlite3';
|
||||
import { v4 as generateGuid } from 'uuid';
|
||||
|
||||
import {
|
||||
_storyIdPredicate,
|
||||
getJobsInQueueSync,
|
||||
insertJobSync,
|
||||
} from '../../sql/Server';
|
||||
import { _storyIdPredicate, getJobsInQueue, insertJob } from '../../sql/Server';
|
||||
import type { WritableDB } from '../../sql/Interface';
|
||||
import { ReadStatus } from '../../messages/MessageReadStatus';
|
||||
import { SeenStatus } from '../../MessageSeenStatus';
|
||||
import { objectToJSON, sql, sqlJoin } from '../../sql/util';
|
||||
import { BodyRange } from '../../types/BodyRange';
|
||||
import type { AciString } from '../../types/ServiceId';
|
||||
import { generateAci } from '../../types/ServiceId';
|
||||
import { updateToVersion } from './helpers';
|
||||
import { createDB, updateToVersion } from './helpers';
|
||||
|
||||
const OUR_UUID = generateGuid();
|
||||
|
||||
describe('SQL migrations test', () => {
|
||||
let db: Database;
|
||||
let db: WritableDB;
|
||||
|
||||
const addOurUuid = () => {
|
||||
const value = {
|
||||
|
@ -71,7 +66,7 @@ describe('SQL migrations test', () => {
|
|||
};
|
||||
|
||||
beforeEach(() => {
|
||||
db = new SQL(':memory:');
|
||||
db = createDB();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -1409,7 +1404,7 @@ describe('SQL migrations test', () => {
|
|||
const CONVERSATION_ID_1 = generateGuid();
|
||||
const CONVERSATION_ID_2 = generateGuid();
|
||||
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-1',
|
||||
timestamp: 1,
|
||||
queueType: 'reactions',
|
||||
|
@ -1417,7 +1412,7 @@ describe('SQL migrations test', () => {
|
|||
messageId: MESSAGE_ID_1,
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-2',
|
||||
timestamp: 2,
|
||||
queueType: 'reactions',
|
||||
|
@ -1425,12 +1420,12 @@ describe('SQL migrations test', () => {
|
|||
messageId: MESSAGE_ID_2,
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-3-missing-data',
|
||||
timestamp: 3,
|
||||
queueType: 'reactions',
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-4-non-string-messageId',
|
||||
timestamp: 1,
|
||||
queueType: 'reactions',
|
||||
|
@ -1438,7 +1433,7 @@ describe('SQL migrations test', () => {
|
|||
messageId: 4,
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-5-missing-message',
|
||||
timestamp: 5,
|
||||
queueType: 'reactions',
|
||||
|
@ -1446,7 +1441,7 @@ describe('SQL migrations test', () => {
|
|||
messageId: 'missing',
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-6-missing-conversation',
|
||||
timestamp: 6,
|
||||
queueType: 'reactions',
|
||||
|
@ -1490,7 +1485,7 @@ describe('SQL migrations test', () => {
|
|||
assert.strictEqual(reactionJobs.get(), 0, 'reaction jobs after');
|
||||
assert.strictEqual(conversationJobs.get(), 2, 'conversation jobs after');
|
||||
|
||||
const jobs = getJobsInQueueSync(db, 'conversation');
|
||||
const jobs = getJobsInQueue(db, 'conversation');
|
||||
|
||||
assert.deepEqual(jobs, [
|
||||
{
|
||||
|
@ -1525,7 +1520,7 @@ describe('SQL migrations test', () => {
|
|||
const CONVERSATION_ID_1 = generateGuid();
|
||||
const CONVERSATION_ID_2 = generateGuid();
|
||||
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-1',
|
||||
timestamp: 1,
|
||||
queueType: 'normal send',
|
||||
|
@ -1534,7 +1529,7 @@ describe('SQL migrations test', () => {
|
|||
messageId: MESSAGE_ID_1,
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-2',
|
||||
timestamp: 2,
|
||||
queueType: 'normal send',
|
||||
|
@ -1543,7 +1538,7 @@ describe('SQL migrations test', () => {
|
|||
messageId: MESSAGE_ID_2,
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-3-missing-data',
|
||||
timestamp: 3,
|
||||
queueType: 'normal send',
|
||||
|
@ -1567,7 +1562,7 @@ describe('SQL migrations test', () => {
|
|||
assert.strictEqual(normalSend.get(), 0, 'normal send jobs after');
|
||||
assert.strictEqual(conversationJobs.get(), 2, 'conversation jobs after');
|
||||
|
||||
const jobs = getJobsInQueueSync(db, 'conversation');
|
||||
const jobs = getJobsInQueue(db, 'conversation');
|
||||
|
||||
assert.deepEqual(jobs, [
|
||||
{
|
||||
|
@ -1742,7 +1737,7 @@ describe('SQL migrations test', () => {
|
|||
assert.strictEqual(totalJobs.get(), 2, 'after total');
|
||||
assert.strictEqual(reportSpamJobs.get(), 1, 'after report spam');
|
||||
|
||||
const jobs = getJobsInQueueSync(db, 'report spam');
|
||||
const jobs = getJobsInQueue(db, 'report spam');
|
||||
|
||||
assert.deepEqual(jobs, [
|
||||
{
|
||||
|
@ -2494,13 +2489,13 @@ describe('SQL migrations test', () => {
|
|||
`
|
||||
);
|
||||
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-1',
|
||||
timestamp: 1,
|
||||
queueType: 'random job',
|
||||
data: {},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-2',
|
||||
timestamp: 2,
|
||||
queueType: 'delivery receipts',
|
||||
|
@ -2509,7 +2504,7 @@ describe('SQL migrations test', () => {
|
|||
deliveryReceipts: [],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-3',
|
||||
timestamp: 3,
|
||||
queueType: 'read receipts',
|
||||
|
@ -2518,7 +2513,7 @@ describe('SQL migrations test', () => {
|
|||
readReceipts: [],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-4',
|
||||
timestamp: 4,
|
||||
queueType: 'viewed receipts',
|
||||
|
@ -2527,7 +2522,7 @@ describe('SQL migrations test', () => {
|
|||
viewedReceipt: {},
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-5',
|
||||
timestamp: 5,
|
||||
queueType: 'conversation',
|
||||
|
@ -2577,7 +2572,7 @@ describe('SQL migrations test', () => {
|
|||
const CONVERSATION_ID_1 = generateGuid();
|
||||
const CONVERSATION_ID_2 = generateGuid();
|
||||
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-1',
|
||||
timestamp: 1,
|
||||
queueType: 'delivery receipts',
|
||||
|
@ -2591,7 +2586,7 @@ describe('SQL migrations test', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-2',
|
||||
timestamp: 2,
|
||||
queueType: 'delivery receipts',
|
||||
|
@ -2605,12 +2600,12 @@ describe('SQL migrations test', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-3-missing-data',
|
||||
timestamp: 3,
|
||||
queueType: 'delivery receipts',
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-4-non-string-messageId',
|
||||
timestamp: 4,
|
||||
queueType: 'delivery receipts',
|
||||
|
@ -2624,7 +2619,7 @@ describe('SQL migrations test', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-5-missing-message',
|
||||
timestamp: 5,
|
||||
queueType: 'delivery receipts',
|
||||
|
@ -2638,7 +2633,7 @@ describe('SQL migrations test', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-6-missing-conversation',
|
||||
timestamp: 6,
|
||||
queueType: 'delivery receipts',
|
||||
|
@ -2652,7 +2647,7 @@ describe('SQL migrations test', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-7-missing-delivery-receipts',
|
||||
timestamp: 7,
|
||||
queueType: 'delivery receipts',
|
||||
|
@ -2698,7 +2693,7 @@ describe('SQL migrations test', () => {
|
|||
assert.strictEqual(conversationJobs.get(), 2, 'conversation jobs after');
|
||||
assert.strictEqual(deliveryJobs.get(), 0, 'delivery jobs after');
|
||||
|
||||
const jobs = getJobsInQueueSync(db, 'conversation');
|
||||
const jobs = getJobsInQueue(db, 'conversation');
|
||||
|
||||
assert.deepEqual(jobs, [
|
||||
{
|
||||
|
@ -2748,7 +2743,7 @@ describe('SQL migrations test', () => {
|
|||
const CONVERSATION_ID_1 = generateGuid();
|
||||
const CONVERSATION_ID_2 = generateGuid();
|
||||
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-1',
|
||||
timestamp: 1,
|
||||
queueType: 'read receipts',
|
||||
|
@ -2762,7 +2757,7 @@ describe('SQL migrations test', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-2',
|
||||
timestamp: 2,
|
||||
queueType: 'read receipts',
|
||||
|
@ -2776,12 +2771,12 @@ describe('SQL migrations test', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-3-missing-data',
|
||||
timestamp: 3,
|
||||
queueType: 'read receipts',
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-4-non-string-messageId',
|
||||
timestamp: 4,
|
||||
queueType: 'read receipts',
|
||||
|
@ -2795,7 +2790,7 @@ describe('SQL migrations test', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-5-missing-message',
|
||||
timestamp: 5,
|
||||
queueType: 'read receipts',
|
||||
|
@ -2809,7 +2804,7 @@ describe('SQL migrations test', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-6-missing-conversation',
|
||||
timestamp: 6,
|
||||
queueType: 'read receipts',
|
||||
|
@ -2823,7 +2818,7 @@ describe('SQL migrations test', () => {
|
|||
],
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-7-missing-read-receipts',
|
||||
timestamp: 7,
|
||||
queueType: 'read receipts',
|
||||
|
@ -2867,7 +2862,7 @@ describe('SQL migrations test', () => {
|
|||
assert.strictEqual(conversationJobs.get(), 2, 'conversation jobs after');
|
||||
assert.strictEqual(readJobs.get(), 0, 'read jobs after');
|
||||
|
||||
const jobs = getJobsInQueueSync(db, 'conversation');
|
||||
const jobs = getJobsInQueue(db, 'conversation');
|
||||
|
||||
assert.deepEqual(jobs, [
|
||||
{
|
||||
|
@ -2917,7 +2912,7 @@ describe('SQL migrations test', () => {
|
|||
const CONVERSATION_ID_1 = generateGuid();
|
||||
const CONVERSATION_ID_2 = generateGuid();
|
||||
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-1',
|
||||
timestamp: 1,
|
||||
queueType: 'viewed receipts',
|
||||
|
@ -2929,7 +2924,7 @@ describe('SQL migrations test', () => {
|
|||
},
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-2',
|
||||
timestamp: 2,
|
||||
queueType: 'viewed receipts',
|
||||
|
@ -2941,12 +2936,12 @@ describe('SQL migrations test', () => {
|
|||
},
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-3-missing-data',
|
||||
timestamp: 3,
|
||||
queueType: 'viewed receipts',
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-4-non-string-messageId',
|
||||
timestamp: 4,
|
||||
queueType: 'viewed receipts',
|
||||
|
@ -2958,7 +2953,7 @@ describe('SQL migrations test', () => {
|
|||
},
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-5-missing-message',
|
||||
timestamp: 5,
|
||||
queueType: 'viewed receipts',
|
||||
|
@ -2970,7 +2965,7 @@ describe('SQL migrations test', () => {
|
|||
},
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-6-missing-conversation',
|
||||
timestamp: 6,
|
||||
queueType: 'viewed receipts',
|
||||
|
@ -2982,7 +2977,7 @@ describe('SQL migrations test', () => {
|
|||
},
|
||||
},
|
||||
});
|
||||
insertJobSync(db, {
|
||||
insertJob(db, {
|
||||
id: 'id-7-missing-viewed-receipt',
|
||||
timestamp: 7,
|
||||
queueType: 'viewed receipts',
|
||||
|
@ -3028,7 +3023,7 @@ describe('SQL migrations test', () => {
|
|||
assert.strictEqual(conversationJobs.get(), 2, 'conversation jobs after');
|
||||
assert.strictEqual(viewedJobs.get(), 0, 'viewed jobs after');
|
||||
|
||||
const jobs = getJobsInQueueSync(db, 'conversation');
|
||||
const jobs = getJobsInQueue(db, 'conversation');
|
||||
|
||||
assert.deepEqual(jobs, [
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue