Introduce logging for unexpected incoming urgent values
This commit is contained in:
parent
f92be05b15
commit
5fcf97b43b
8 changed files with 278 additions and 83 deletions
|
@ -208,6 +208,7 @@ export type UnprocessedType = {
|
|||
serverGuid?: string;
|
||||
serverTimestamp?: number;
|
||||
decrypted?: string;
|
||||
urgent?: boolean;
|
||||
};
|
||||
|
||||
export type UnprocessedUpdateType = {
|
||||
|
|
|
@ -15,6 +15,7 @@ import {
|
|||
forEach,
|
||||
fromPairs,
|
||||
groupBy,
|
||||
isBoolean,
|
||||
isNil,
|
||||
isNumber,
|
||||
isString,
|
||||
|
@ -3085,6 +3086,7 @@ function saveUnprocessedSync(data: UnprocessedType): string {
|
|||
serverGuid,
|
||||
serverTimestamp,
|
||||
decrypted,
|
||||
urgent,
|
||||
} = data;
|
||||
if (!id) {
|
||||
throw new Error('saveUnprocessedSync: id was falsey');
|
||||
|
@ -3110,7 +3112,8 @@ function saveUnprocessedSync(data: UnprocessedType): string {
|
|||
sourceDevice,
|
||||
serverGuid,
|
||||
serverTimestamp,
|
||||
decrypted
|
||||
decrypted,
|
||||
urgent
|
||||
) values (
|
||||
$id,
|
||||
$timestamp,
|
||||
|
@ -3123,7 +3126,8 @@ function saveUnprocessedSync(data: UnprocessedType): string {
|
|||
$sourceDevice,
|
||||
$serverGuid,
|
||||
$serverTimestamp,
|
||||
$decrypted
|
||||
$decrypted,
|
||||
$urgent
|
||||
);
|
||||
`
|
||||
).run({
|
||||
|
@ -3139,6 +3143,7 @@ function saveUnprocessedSync(data: UnprocessedType): string {
|
|||
serverGuid: serverGuid || null,
|
||||
serverTimestamp: serverTimestamp || null,
|
||||
decrypted: decrypted || null,
|
||||
urgent: urgent || !isBoolean(urgent) ? 1 : 0,
|
||||
});
|
||||
|
||||
return id;
|
||||
|
@ -3210,7 +3215,10 @@ async function getUnprocessedById(
|
|||
id,
|
||||
});
|
||||
|
||||
return row;
|
||||
return {
|
||||
...row,
|
||||
urgent: isNumber(row.urgent) ? Boolean(row.urgent) : true,
|
||||
};
|
||||
}
|
||||
|
||||
async function getUnprocessedCount(): Promise<number> {
|
||||
|
@ -3267,7 +3275,11 @@ async function getAllUnprocessedAndIncrementAttempts(): Promise<
|
|||
ORDER BY receivedAtCounter ASC;
|
||||
`
|
||||
)
|
||||
.all();
|
||||
.all()
|
||||
.map(row => ({
|
||||
...row,
|
||||
urgent: isNumber(row.urgent) ? Boolean(row.urgent) : true,
|
||||
}));
|
||||
})();
|
||||
}
|
||||
|
||||
|
|
28
ts/sql/migrations/63-add-urgent-to-unprocessed.ts
Normal file
28
ts/sql/migrations/63-add-urgent-to-unprocessed.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
// Copyright 2021-2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { Database } from 'better-sqlite3';
|
||||
|
||||
import type { LoggerType } from '../../types/Logging';
|
||||
|
||||
export default function updateToSchemaVersion63(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 63) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(
|
||||
`
|
||||
ALTER TABLE unprocessed ADD COLUMN urgent INTEGER;
|
||||
`
|
||||
);
|
||||
|
||||
db.pragma('user_version = 63');
|
||||
})();
|
||||
|
||||
logger.info('updateToSchemaVersion63: success!');
|
||||
}
|
|
@ -38,6 +38,7 @@ import updateToSchemaVersion59 from './59-unprocessed-received-at-counter-index'
|
|||
import updateToSchemaVersion60 from './60-update-expiring-index';
|
||||
import updateToSchemaVersion61 from './61-distribution-list-storage';
|
||||
import updateToSchemaVersion62 from './62-add-urgent-to-send-log';
|
||||
import updateToSchemaVersion63 from './63-add-urgent-to-unprocessed';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -1939,6 +1940,7 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion60,
|
||||
updateToSchemaVersion61,
|
||||
updateToSchemaVersion62,
|
||||
updateToSchemaVersion63,
|
||||
];
|
||||
|
||||
export function updateSchema(db: Database, logger: LoggerType): void {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue