Parallelize SQL queries

This commit is contained in:
Fedor Indutny 2024-07-22 11:16:33 -07:00 committed by GitHub
parent 86b4da1ec2
commit c64762858e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
178 changed files with 3377 additions and 3618 deletions

View file

@ -17,6 +17,7 @@ import {
} from '@signalapp/libsignal-client';
import { v4 as generateUuid } from 'uuid';
import { DataReader, DataWriter } from '../sql/Client';
import { signal } from '../protobuf/compiled';
import { sessionStructureToBytes } from '../util/sessionTranslation';
import * as durations from '../util/durations';
@ -295,21 +296,21 @@ describe('SignalProtocolStore', () => {
await store.saveIdentity(identifier, testKey.pubKey);
});
it('marks the key firstUse', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
assert(identity.firstUse);
});
it('sets the timestamp', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
assert(identity.timestamp);
});
it('sets the verified status to DEFAULT', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -321,7 +322,7 @@ describe('SignalProtocolStore', () => {
const oldTimestamp = Date.now();
before(async () => {
await window.Signal.Data.createOrUpdateIdentityKey({
await DataWriter.createOrUpdateIdentityKey({
id: theirAci,
publicKey: testKey.pubKey,
firstUse: true,
@ -334,14 +335,14 @@ describe('SignalProtocolStore', () => {
await store.saveIdentity(identifier, newIdentity);
});
it('marks the key not firstUse', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
assert(!identity.firstUse);
});
it('updates the timestamp', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -350,7 +351,7 @@ describe('SignalProtocolStore', () => {
describe('The previous verified status was DEFAULT', () => {
before(async () => {
await window.Signal.Data.createOrUpdateIdentityKey({
await DataWriter.createOrUpdateIdentityKey({
id: theirAci,
publicKey: testKey.pubKey,
firstUse: true,
@ -363,9 +364,7 @@ describe('SignalProtocolStore', () => {
await store.saveIdentity(identifier, newIdentity);
});
it('sets the new key to default', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(
theirAci
);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -374,7 +373,7 @@ describe('SignalProtocolStore', () => {
});
describe('The previous verified status was VERIFIED', () => {
before(async () => {
await window.Signal.Data.createOrUpdateIdentityKey({
await DataWriter.createOrUpdateIdentityKey({
id: theirAci,
publicKey: testKey.pubKey,
firstUse: true,
@ -387,9 +386,7 @@ describe('SignalProtocolStore', () => {
await store.saveIdentity(identifier, newIdentity);
});
it('sets the new key to unverified', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(
theirAci
);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -401,7 +398,7 @@ describe('SignalProtocolStore', () => {
});
describe('The previous verified status was UNVERIFIED', () => {
before(async () => {
await window.Signal.Data.createOrUpdateIdentityKey({
await DataWriter.createOrUpdateIdentityKey({
id: theirAci,
publicKey: testKey.pubKey,
firstUse: true,
@ -414,9 +411,7 @@ describe('SignalProtocolStore', () => {
await store.saveIdentity(identifier, newIdentity);
});
it('sets the new key to unverified', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(
theirAci
);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -430,7 +425,7 @@ describe('SignalProtocolStore', () => {
describe('When the key has not changed', () => {
const oldTimestamp = Date.now();
before(async () => {
await window.Signal.Data.createOrUpdateIdentityKey({
await DataWriter.createOrUpdateIdentityKey({
id: theirAci,
publicKey: testKey.pubKey,
timestamp: oldTimestamp,
@ -442,22 +437,18 @@ describe('SignalProtocolStore', () => {
});
describe('If it is marked firstUse', () => {
before(async () => {
const identity = await window.Signal.Data.getIdentityKeyById(
theirAci
);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
identity.firstUse = true;
await window.Signal.Data.createOrUpdateIdentityKey(identity);
await DataWriter.createOrUpdateIdentityKey(identity);
await store.hydrateCaches();
});
it('nothing changes', async () => {
await store.saveIdentity(identifier, testKey.pubKey, true);
const identity = await window.Signal.Data.getIdentityKeyById(
theirAci
);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -467,36 +458,30 @@ describe('SignalProtocolStore', () => {
});
describe('If it is not marked firstUse', () => {
before(async () => {
const identity = await window.Signal.Data.getIdentityKeyById(
theirAci
);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
identity.firstUse = false;
await window.Signal.Data.createOrUpdateIdentityKey(identity);
await DataWriter.createOrUpdateIdentityKey(identity);
await store.hydrateCaches();
});
describe('If nonblocking approval is required', () => {
let now: number;
before(async () => {
now = Date.now();
const identity = await window.Signal.Data.getIdentityKeyById(
theirAci
);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
identity.timestamp = now;
await window.Signal.Data.createOrUpdateIdentityKey(identity);
await DataWriter.createOrUpdateIdentityKey(identity);
await store.hydrateCaches();
});
it('sets non-blocking approval', async () => {
await store.saveIdentity(identifier, testKey.pubKey, true);
const identity = await window.Signal.Data.getIdentityKeyById(
theirAci
);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -532,35 +517,35 @@ describe('SignalProtocolStore', () => {
});
it('publicKey is saved', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
assert.isTrue(constantTimeEqual(identity.publicKey, testKey.pubKey));
});
it('firstUse is saved', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
assert.strictEqual(identity.firstUse, true);
});
it('timestamp is saved', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
assert.strictEqual(identity.timestamp, now);
});
it('verified is saved', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
assert.strictEqual(identity.verified, store.VerifiedStatus.VERIFIED);
});
it('nonblockingApproval is saved', async () => {
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -607,7 +592,7 @@ describe('SignalProtocolStore', () => {
describe('setApproval', () => {
it('sets nonblockingApproval', async () => {
await store.setApproval(theirAci, true);
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -617,7 +602,7 @@ describe('SignalProtocolStore', () => {
});
describe('setVerified', () => {
async function saveRecordDefault() {
await window.Signal.Data.createOrUpdateIdentityKey({
await DataWriter.createOrUpdateIdentityKey({
id: theirAci,
publicKey: testKey.pubKey,
firstUse: true,
@ -632,7 +617,7 @@ describe('SignalProtocolStore', () => {
it('updates the verified status', async () => {
await store.setVerified(theirAci, store.VerifiedStatus.VERIFIED);
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -646,7 +631,7 @@ describe('SignalProtocolStore', () => {
it('updates the verified status', async () => {
await store.setVerified(theirAci, store.VerifiedStatus.VERIFIED);
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -667,7 +652,7 @@ describe('SignalProtocolStore', () => {
keychangeTriggered += 1;
});
await window.Signal.Data.createOrUpdateIdentityKey({
await DataWriter.createOrUpdateIdentityKey({
id: theirAci,
publicKey: testKey.pubKey,
timestamp: Date.now() - 10 * 1000 * 60,
@ -693,7 +678,7 @@ describe('SignalProtocolStore', () => {
assert.isFalse(needsNotification);
assert.strictEqual(keychangeTriggered, 0);
const identity = await window.Signal.Data.getIdentityKeyById(newAci);
const identity = await DataReader.getIdentityKeyById(newAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -712,7 +697,7 @@ describe('SignalProtocolStore', () => {
assert.isTrue(needsNotification);
assert.strictEqual(keychangeTriggered, 0);
const identity = await window.Signal.Data.getIdentityKeyById(newAci);
const identity = await DataReader.getIdentityKeyById(newAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -729,7 +714,7 @@ describe('SignalProtocolStore', () => {
assert.isFalse(needsNotification);
assert.strictEqual(keychangeTriggered, 1);
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -746,7 +731,7 @@ describe('SignalProtocolStore', () => {
assert.isTrue(needsNotification);
assert.strictEqual(keychangeTriggered, 0);
const identity = await window.Signal.Data.getIdentityKeyById(theirAci);
const identity = await DataReader.getIdentityKeyById(theirAci);
if (!identity) {
throw new Error('Missing identity!');
}
@ -757,7 +742,7 @@ describe('SignalProtocolStore', () => {
describe('isUntrusted', () => {
it('returns false if identity key old enough', async () => {
await window.Signal.Data.createOrUpdateIdentityKey({
await DataWriter.createOrUpdateIdentityKey({
id: theirAci,
publicKey: testKey.pubKey,
timestamp: Date.now() - 10 * 1000 * 60,
@ -772,7 +757,7 @@ describe('SignalProtocolStore', () => {
});
it('returns false if new but nonblockingApproval is true', async () => {
await window.Signal.Data.createOrUpdateIdentityKey({
await DataWriter.createOrUpdateIdentityKey({
id: theirAci,
publicKey: testKey.pubKey,
timestamp: Date.now(),
@ -787,7 +772,7 @@ describe('SignalProtocolStore', () => {
});
it('returns false if new but firstUse is true', async () => {
await window.Signal.Data.createOrUpdateIdentityKey({
await DataWriter.createOrUpdateIdentityKey({
id: theirAci,
publicKey: testKey.pubKey,
timestamp: Date.now(),
@ -802,7 +787,7 @@ describe('SignalProtocolStore', () => {
});
it('returns true if new, and no flags are set', async () => {
await window.Signal.Data.createOrUpdateIdentityKey({
await DataWriter.createOrUpdateIdentityKey({
id: theirAci,
publicKey: testKey.pubKey,
timestamp: Date.now(),