Introduce versioning clock to timer system
This commit is contained in:
parent
bb1d957e49
commit
2fb50df0af
34 changed files with 703 additions and 28 deletions
|
@ -204,6 +204,7 @@ import { redactGenericText } from '../util/privacy';
|
|||
type ConversationRow = Readonly<{
|
||||
json: string;
|
||||
profileLastFetchedAt: null | number;
|
||||
expireTimerVersion: number;
|
||||
}>;
|
||||
type ConversationRows = Array<ConversationRow>;
|
||||
type StickerRow = Readonly<{
|
||||
|
@ -547,6 +548,7 @@ export function prepare<T extends Array<unknown> | Record<string, unknown>>(
|
|||
}
|
||||
|
||||
function rowToConversation(row: ConversationRow): ConversationType {
|
||||
const { expireTimerVersion } = row;
|
||||
const parsedJson = JSON.parse(row.json);
|
||||
|
||||
let profileLastFetchedAt: undefined | number;
|
||||
|
@ -562,6 +564,7 @@ function rowToConversation(row: ConversationRow): ConversationType {
|
|||
|
||||
return {
|
||||
...parsedJson,
|
||||
expireTimerVersion,
|
||||
profileLastFetchedAt,
|
||||
};
|
||||
}
|
||||
|
@ -1635,6 +1638,7 @@ function updateConversation(db: WritableDB, data: ConversationType): void {
|
|||
profileLastFetchedAt,
|
||||
e164,
|
||||
serviceId,
|
||||
expireTimerVersion,
|
||||
} = data;
|
||||
|
||||
const membersList = getConversationMembersList(data);
|
||||
|
@ -1654,7 +1658,8 @@ function updateConversation(db: WritableDB, data: ConversationType): void {
|
|||
profileName = $profileName,
|
||||
profileFamilyName = $profileFamilyName,
|
||||
profileFullName = $profileFullName,
|
||||
profileLastFetchedAt = $profileLastFetchedAt
|
||||
profileLastFetchedAt = $profileLastFetchedAt,
|
||||
expireTimerVersion = $expireTimerVersion
|
||||
WHERE id = $id;
|
||||
`
|
||||
).run({
|
||||
|
@ -1674,6 +1679,7 @@ function updateConversation(db: WritableDB, data: ConversationType): void {
|
|||
profileFamilyName: profileFamilyName || null,
|
||||
profileFullName: combineNames(profileName, profileFamilyName) || null,
|
||||
profileLastFetchedAt: profileLastFetchedAt || null,
|
||||
expireTimerVersion,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1737,7 +1743,7 @@ function getAllConversations(db: ReadableDB): Array<ConversationType> {
|
|||
const rows: ConversationRows = db
|
||||
.prepare<EmptyQuery>(
|
||||
`
|
||||
SELECT json, profileLastFetchedAt
|
||||
SELECT json, profileLastFetchedAt, expireTimerVersion
|
||||
FROM conversations
|
||||
ORDER BY id ASC;
|
||||
`
|
||||
|
@ -1766,7 +1772,7 @@ function getAllGroupsInvolvingServiceId(
|
|||
const rows: ConversationRows = db
|
||||
.prepare<Query>(
|
||||
`
|
||||
SELECT json, profileLastFetchedAt
|
||||
SELECT json, profileLastFetchedAt, expireTimerVersion
|
||||
FROM conversations WHERE
|
||||
type = 'group' AND
|
||||
members LIKE $serviceId
|
||||
|
|
30
ts/sql/migrations/1150-expire-timer-version.ts
Normal file
30
ts/sql/migrations/1150-expire-timer-version.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
// Copyright 2024 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 = 1150;
|
||||
|
||||
export function updateToSchemaVersion1150(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1150) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(`
|
||||
-- All future conversations will start from '1'
|
||||
ALTER TABLE conversations
|
||||
ADD COLUMN expireTimerVersion INTEGER NOT NULL DEFAULT 1;
|
||||
|
||||
-- All current conversations will start from '2'
|
||||
UPDATE conversations SET expireTimerVersion = 2;
|
||||
`);
|
||||
|
||||
db.pragma('user_version = 1150');
|
||||
})();
|
||||
logger.info('updateToSchemaVersion1150: success!');
|
||||
}
|
|
@ -90,10 +90,11 @@ import { updateToSchemaVersion1100 } from './1100-optimize-mark-call-history-rea
|
|||
import { updateToSchemaVersion1110 } from './1110-sticker-local-key';
|
||||
import { updateToSchemaVersion1120 } from './1120-messages-foreign-keys-indexes';
|
||||
import { updateToSchemaVersion1130 } from './1130-isStory-index';
|
||||
import { updateToSchemaVersion1140 } from './1140-call-links-deleted-column';
|
||||
import {
|
||||
updateToSchemaVersion1140,
|
||||
updateToSchemaVersion1150,
|
||||
version as MAX_VERSION,
|
||||
} from './1140-call-links-deleted-column';
|
||||
} from './1150-expire-timer-version';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -2052,6 +2053,7 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion1120,
|
||||
updateToSchemaVersion1130,
|
||||
updateToSchemaVersion1140,
|
||||
updateToSchemaVersion1150,
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue