Parallelize SQL queries
This commit is contained in:
parent
86b4da1ec2
commit
c64762858e
178 changed files with 3377 additions and 3618 deletions
|
@ -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