mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-21 17:08:11 +01:00
Fix handling of encrypted unprocessed envelopes
This commit is contained in:
@@ -375,6 +375,11 @@ export type StickerPackRefType = Readonly<{
|
||||
export type UnprocessedType = {
|
||||
id: string;
|
||||
timestamp: number;
|
||||
/*
|
||||
* A client generated date used for removing old envelopes from the table
|
||||
* on startup.
|
||||
*/
|
||||
receivedAtDate: number;
|
||||
receivedAtCounter: number;
|
||||
attempts: number;
|
||||
type: number;
|
||||
|
||||
@@ -4629,6 +4629,7 @@ function saveUnprocessed(db: WritableDB, data: UnprocessedType): string {
|
||||
const {
|
||||
id,
|
||||
timestamp,
|
||||
receivedAtDate,
|
||||
receivedAtCounter,
|
||||
attempts,
|
||||
type,
|
||||
@@ -4659,6 +4660,7 @@ function saveUnprocessed(db: WritableDB, data: UnprocessedType): string {
|
||||
id,
|
||||
timestamp,
|
||||
receivedAtCounter,
|
||||
receivedAtDate,
|
||||
attempts,
|
||||
type,
|
||||
isEncrypted,
|
||||
@@ -4680,6 +4682,7 @@ function saveUnprocessed(db: WritableDB, data: UnprocessedType): string {
|
||||
$id,
|
||||
$timestamp,
|
||||
$receivedAtCounter,
|
||||
$receivedAtDate,
|
||||
$attempts,
|
||||
$type,
|
||||
$isEncrypted,
|
||||
@@ -4702,7 +4705,8 @@ function saveUnprocessed(db: WritableDB, data: UnprocessedType): string {
|
||||
).run({
|
||||
id,
|
||||
timestamp,
|
||||
receivedAtCounter: receivedAtCounter ?? null,
|
||||
receivedAtCounter,
|
||||
receivedAtDate,
|
||||
attempts,
|
||||
type,
|
||||
isEncrypted: isEncrypted ? 1 : 0,
|
||||
@@ -4750,9 +4754,11 @@ function getAllUnprocessedIds(db: WritableDB): Array<string> {
|
||||
return db.transaction(() => {
|
||||
// cleanup first
|
||||
const { changes: deletedStaleCount } = db
|
||||
.prepare<Query>('DELETE FROM unprocessed WHERE timestamp < $monthAgo')
|
||||
.prepare<Query>(
|
||||
'DELETE FROM unprocessed WHERE receivedAtDate < $messageQueueCutoff'
|
||||
)
|
||||
.run({
|
||||
monthAgo: Date.now() - 45 * durations.DAY,
|
||||
messageQueueCutoff: Date.now() - 45 * durations.DAY,
|
||||
});
|
||||
|
||||
if (deletedStaleCount !== 0) {
|
||||
|
||||
38
ts/sql/migrations/1320-unprocessed-received-at-date.ts
Normal file
38
ts/sql/migrations/1320-unprocessed-received-at-date.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2025 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
import { sql } from '../util';
|
||||
import type { WritableDB } from '../Interface';
|
||||
|
||||
export const version = 1320;
|
||||
|
||||
export function updateToSchemaVersion1320(
|
||||
currentVersion: number,
|
||||
db: WritableDB,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1320) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
const [query] = sql`
|
||||
DROP INDEX unprocessed_timestamp;
|
||||
|
||||
ALTER TABLE unprocessed
|
||||
ADD COLUMN receivedAtDate INTEGER DEFAULT 0 NOT NULL;
|
||||
|
||||
UPDATE unprocessed
|
||||
SET receivedAtDate = timestamp;
|
||||
|
||||
CREATE INDEX unprocessed_byReceivedAtDate ON unprocessed
|
||||
(receivedAtDate);
|
||||
`;
|
||||
db.exec(query);
|
||||
|
||||
db.pragma('user_version = 1320');
|
||||
})();
|
||||
|
||||
logger.info('updateToSchemaVersion1320: success!');
|
||||
}
|
||||
@@ -107,10 +107,11 @@ import { updateToSchemaVersion1270 } from './1270-normalize-messages';
|
||||
import { updateToSchemaVersion1280 } from './1280-blob-unprocessed';
|
||||
import { updateToSchemaVersion1290 } from './1290-int-unprocessed-source-device';
|
||||
import { updateToSchemaVersion1300 } from './1300-sticker-pack-refs';
|
||||
import { updateToSchemaVersion1310 } from './1310-muted-fixup';
|
||||
import {
|
||||
updateToSchemaVersion1310,
|
||||
updateToSchemaVersion1320,
|
||||
version as MAX_VERSION,
|
||||
} from './1310-muted-fixup';
|
||||
} from './1320-unprocessed-received-at-date';
|
||||
import { DataWriter } from '../Server';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
@@ -2089,6 +2090,7 @@ export const SCHEMA_VERSIONS = [
|
||||
|
||||
updateToSchemaVersion1300,
|
||||
updateToSchemaVersion1310,
|
||||
updateToSchemaVersion1320,
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
||||
Reference in New Issue
Block a user