2024-07-10 21:10:08 +00:00
|
|
|
// Copyright 2024 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { assert } from 'chai';
|
|
|
|
import { findLast } from 'lodash';
|
2024-07-22 18:16:33 +00:00
|
|
|
import type { WritableDB } from '../../sql/Interface';
|
|
|
|
import { markAllCallHistoryRead } from '../../sql/Server';
|
2024-07-10 21:10:08 +00:00
|
|
|
import { SeenStatus } from '../../MessageSeenStatus';
|
|
|
|
import {
|
2024-08-06 19:29:13 +00:00
|
|
|
CallMode,
|
2024-07-10 21:10:08 +00:00
|
|
|
CallDirection,
|
|
|
|
CallType,
|
|
|
|
DirectCallStatus,
|
|
|
|
} from '../../types/CallDisposition';
|
|
|
|
import { strictAssert } from '../../util/assert';
|
2024-07-22 18:16:33 +00:00
|
|
|
import { createDB, insertData, updateToVersion } from './helpers';
|
2024-07-10 21:10:08 +00:00
|
|
|
|
|
|
|
describe('SQL/updateToSchemaVersion1100', () => {
|
2024-07-22 18:16:33 +00:00
|
|
|
let db: WritableDB;
|
2024-07-10 21:10:08 +00:00
|
|
|
beforeEach(() => {
|
2024-07-22 18:16:33 +00:00
|
|
|
db = createDB();
|
2024-07-10 21:10:08 +00:00
|
|
|
updateToVersion(db, 1100);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
db.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('Optimize markAllCallHistoryReadInConversation', () => {
|
|
|
|
it('is fast', () => {
|
|
|
|
const COUNT = 10_000;
|
|
|
|
|
|
|
|
const messages = Array.from({ length: COUNT }, (_, index) => {
|
|
|
|
return {
|
|
|
|
id: `test-message-${index}`,
|
|
|
|
type: 'call-history',
|
|
|
|
seenStatus: SeenStatus.Unseen,
|
|
|
|
conversationId: `test-conversation-${index % 30}`,
|
|
|
|
sent_at: index,
|
|
|
|
json: {
|
|
|
|
callId: `test-call-${index}`,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
const callsHistory = Array.from({ length: COUNT }, (_, index) => {
|
|
|
|
return {
|
|
|
|
callId: `test-call-${index}`,
|
|
|
|
peerId: `test-conversation-${index % 30}`,
|
|
|
|
timestamp: index,
|
|
|
|
ringerId: null,
|
|
|
|
mode: CallMode.Direct,
|
|
|
|
type: CallType.Video,
|
|
|
|
direction: CallDirection.Incoming,
|
|
|
|
status: DirectCallStatus.Missed,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
insertData(db, 'messages', messages);
|
|
|
|
insertData(db, 'callsHistory', callsHistory);
|
|
|
|
|
|
|
|
const latestCallInConversation = findLast(callsHistory, call => {
|
|
|
|
return call.peerId === 'test-conversation-0';
|
|
|
|
});
|
|
|
|
|
|
|
|
strictAssert(latestCallInConversation, 'missing latest call');
|
|
|
|
|
|
|
|
const target = {
|
|
|
|
timestamp: latestCallInConversation.timestamp,
|
|
|
|
callId: latestCallInConversation.callId,
|
|
|
|
peerId: latestCallInConversation.peerId,
|
|
|
|
};
|
|
|
|
|
|
|
|
const start = performance.now();
|
2024-07-22 18:16:33 +00:00
|
|
|
markAllCallHistoryRead(db, target, true);
|
2024-07-10 21:10:08 +00:00
|
|
|
const end = performance.now();
|
|
|
|
assert.isBelow(end - start, 50);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|