Add a backup media download progress bar
This commit is contained in:
parent
84f1d98020
commit
501f27127f
31 changed files with 640 additions and 78 deletions
|
@ -446,6 +446,11 @@ export type GetRecentStoryRepliesOptionsType = {
|
|||
sentAt?: number;
|
||||
};
|
||||
|
||||
export enum AttachmentDownloadSource {
|
||||
BACKUP_IMPORT = 'backup_import',
|
||||
STANDARD = 'standard',
|
||||
}
|
||||
|
||||
type ReadableInterface = {
|
||||
close: () => void;
|
||||
|
||||
|
@ -642,6 +647,7 @@ type ReadableInterface = {
|
|||
getMaxMessageCounter(): number | undefined;
|
||||
|
||||
getStatisticsForLogging(): Record<string, string>;
|
||||
getSizeOfPendingBackupAttachmentDownloadJobs(): number;
|
||||
};
|
||||
|
||||
type WritableInterface = {
|
||||
|
@ -840,6 +846,7 @@ type WritableInterface = {
|
|||
saveAttachmentDownloadJob: (job: AttachmentDownloadJobType) => void;
|
||||
resetAttachmentDownloadActive: () => void;
|
||||
removeAttachmentDownloadJob: (job: AttachmentDownloadJobType) => void;
|
||||
removeAllBackupAttachmentDownloadJobs: () => void;
|
||||
|
||||
getNextAttachmentBackupJobs: (options: {
|
||||
limit: number;
|
||||
|
|
|
@ -145,6 +145,7 @@ import type {
|
|||
StoredKyberPreKeyType,
|
||||
BackupCdnMediaObjectType,
|
||||
} from './Interface';
|
||||
import { AttachmentDownloadSource } from './Interface';
|
||||
import { SeenStatus } from '../MessageSeenStatus';
|
||||
import {
|
||||
SNIPPET_LEFT_PLACEHOLDER,
|
||||
|
@ -200,6 +201,7 @@ import {
|
|||
attachmentBackupJobSchema,
|
||||
} from '../types/AttachmentBackup';
|
||||
import { redactGenericText } from '../util/privacy';
|
||||
import { getAttachmentCiphertextLength } from '../AttachmentCrypto';
|
||||
|
||||
type ConversationRow = Readonly<{
|
||||
json: string;
|
||||
|
@ -340,6 +342,7 @@ export const DataReader: ServerReadableInterface = {
|
|||
getStatisticsForLogging,
|
||||
|
||||
getBackupCdnObjectMetadata,
|
||||
getSizeOfPendingBackupAttachmentDownloadJobs,
|
||||
|
||||
// Server-only
|
||||
getKnownMessageAttachments,
|
||||
|
@ -463,6 +466,7 @@ export const DataWriter: ServerWritableInterface = {
|
|||
saveAttachmentDownloadJob,
|
||||
resetAttachmentDownloadActive,
|
||||
removeAttachmentDownloadJob,
|
||||
removeAllBackupAttachmentDownloadJobs,
|
||||
|
||||
getNextAttachmentBackupJobs,
|
||||
saveAttachmentBackupJob,
|
||||
|
@ -4733,6 +4737,20 @@ function getAttachmentDownloadJob(
|
|||
return db.prepare(query).get(params);
|
||||
}
|
||||
|
||||
function removeAllBackupAttachmentDownloadJobs(db: WritableDB): void {
|
||||
const [query, params] = sql`
|
||||
DELETE FROM attachment_downloads
|
||||
WHERE source = ${AttachmentDownloadSource.BACKUP_IMPORT};`;
|
||||
db.prepare(query).run(params);
|
||||
}
|
||||
|
||||
function getSizeOfPendingBackupAttachmentDownloadJobs(db: ReadableDB): number {
|
||||
const [query, params] = sql`
|
||||
SELECT SUM(ciphertextSize) FROM attachment_downloads
|
||||
WHERE source = ${AttachmentDownloadSource.BACKUP_IMPORT};`;
|
||||
return db.prepare(query).pluck().get(params);
|
||||
}
|
||||
|
||||
function getNextAttachmentDownloadJobs(
|
||||
db: WritableDB,
|
||||
{
|
||||
|
@ -4799,6 +4817,9 @@ function getNextAttachmentDownloadJobs(
|
|||
...row,
|
||||
active: Boolean(row.active),
|
||||
attachment: jsonToObject(row.attachmentJson),
|
||||
ciphertextSize:
|
||||
row.ciphertextSize ||
|
||||
getAttachmentCiphertextLength(row.attachment.size),
|
||||
});
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
|
@ -4839,7 +4860,9 @@ function saveAttachmentDownloadJob(
|
|||
attempts,
|
||||
retryAfter,
|
||||
lastAttemptTimestamp,
|
||||
attachmentJson
|
||||
attachmentJson,
|
||||
ciphertextSize,
|
||||
source
|
||||
) VALUES (
|
||||
${job.messageId},
|
||||
${job.attachmentType},
|
||||
|
@ -4852,7 +4875,9 @@ function saveAttachmentDownloadJob(
|
|||
${job.attempts},
|
||||
${job.retryAfter},
|
||||
${job.lastAttemptTimestamp},
|
||||
${objectToJSON(job.attachment)}
|
||||
${objectToJSON(job.attachment)},
|
||||
${job.ciphertextSize},
|
||||
${job.source}
|
||||
);
|
||||
`;
|
||||
db.prepare(query).run(params);
|
||||
|
|
|
@ -11,6 +11,7 @@ import {
|
|||
} from '../../types/AttachmentDownload';
|
||||
import type { AttachmentType } from '../../types/Attachment';
|
||||
import { jsonToObject, objectToJSON, sql } from '../util';
|
||||
import { AttachmentDownloadSource } from '../Interface';
|
||||
|
||||
export const version = 1040;
|
||||
|
||||
|
@ -133,6 +134,9 @@ export function updateToSchemaVersion1040(
|
|||
attempts: existingJobData.attempts ?? 0,
|
||||
retryAfter: null,
|
||||
lastAttemptTimestamp: null,
|
||||
// adding due to changes in the schema
|
||||
source: AttachmentDownloadSource.STANDARD,
|
||||
ciphertextSize: 0,
|
||||
};
|
||||
|
||||
const parsed = attachmentDownloadJobSchema.parse(updatedJob);
|
||||
|
|
37
ts/sql/migrations/1180-add-attachment-download-source.ts
Normal file
37
ts/sql/migrations/1180-add-attachment-download-source.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
// 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';
|
||||
import { AttachmentDownloadSource } from '../Interface';
|
||||
|
||||
export const version = 1180;
|
||||
export function updateToSchemaVersion1180(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1180) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
db.exec(`
|
||||
ALTER TABLE attachment_downloads
|
||||
ADD COLUMN source TEXT NOT NULL DEFAULT ${AttachmentDownloadSource.STANDARD};
|
||||
|
||||
ALTER TABLE attachment_downloads
|
||||
-- this default value will be overridden by getNextAttachmentDownloadJobs
|
||||
ADD COLUMN ciphertextSize INTEGER NOT NULL DEFAULT 0;
|
||||
`);
|
||||
|
||||
db.exec(`
|
||||
CREATE INDEX attachment_downloads_source_ciphertextSize
|
||||
ON attachment_downloads (
|
||||
source, ciphertextSize
|
||||
);
|
||||
`);
|
||||
|
||||
db.pragma('user_version = 1180');
|
||||
})();
|
||||
logger.info('updateToSchemaVersion1180: success!');
|
||||
}
|
|
@ -93,10 +93,11 @@ import { updateToSchemaVersion1130 } from './1130-isStory-index';
|
|||
import { updateToSchemaVersion1140 } from './1140-call-links-deleted-column';
|
||||
import { updateToSchemaVersion1150 } from './1150-expire-timer-version';
|
||||
import { updateToSchemaVersion1160 } from './1160-optimize-calls-unread-count';
|
||||
import { updateToSchemaVersion1170 } from './1170-update-call-history-unread-index';
|
||||
import {
|
||||
updateToSchemaVersion1170,
|
||||
updateToSchemaVersion1180,
|
||||
version as MAX_VERSION,
|
||||
} from './1170-update-call-history-unread-index';
|
||||
} from './1180-add-attachment-download-source';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -2058,6 +2059,7 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion1150,
|
||||
updateToSchemaVersion1160,
|
||||
updateToSchemaVersion1170,
|
||||
updateToSchemaVersion1180,
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue