Pause, cancel & resume backup media download
This commit is contained in:
parent
65539b1419
commit
028a3f3ef0
28 changed files with 958 additions and 141 deletions
|
@ -852,6 +852,7 @@ type WritableInterface = {
|
|||
getNextAttachmentDownloadJobs: (options: {
|
||||
limit: number;
|
||||
prioritizeMessageIds?: Array<string>;
|
||||
sources?: Array<AttachmentDownloadSource>;
|
||||
timestamp?: number;
|
||||
}) => Array<AttachmentDownloadJobType>;
|
||||
saveAttachmentDownloadJob: (job: AttachmentDownloadJobType) => void;
|
||||
|
|
|
@ -4785,18 +4785,28 @@ function getNextAttachmentDownloadJobs(
|
|||
db: WritableDB,
|
||||
{
|
||||
limit = 3,
|
||||
sources,
|
||||
prioritizeMessageIds,
|
||||
timestamp = Date.now(),
|
||||
maxLastAttemptForPrioritizedMessages,
|
||||
}: {
|
||||
limit: number;
|
||||
prioritizeMessageIds?: Array<string>;
|
||||
sources?: Array<AttachmentDownloadSource>;
|
||||
timestamp?: number;
|
||||
maxLastAttemptForPrioritizedMessages?: number;
|
||||
}
|
||||
): Array<AttachmentDownloadJobType> {
|
||||
let priorityJobs = [];
|
||||
|
||||
const sourceWhereFragment = sources
|
||||
? sqlFragment`
|
||||
source IN (${sqlJoin(sources)})
|
||||
`
|
||||
: sqlFragment`
|
||||
TRUE
|
||||
`;
|
||||
|
||||
// First, try to get jobs for prioritized messages (e.g. those currently user-visible)
|
||||
if (prioritizeMessageIds?.length) {
|
||||
const [priorityQuery, priorityParams] = sql`
|
||||
|
@ -4813,6 +4823,8 @@ function getNextAttachmentDownloadJobs(
|
|||
})
|
||||
AND
|
||||
messageId IN (${sqlJoin(prioritizeMessageIds)})
|
||||
AND
|
||||
${sourceWhereFragment}
|
||||
-- for priority messages, let's load them oldest first; this helps, e.g. for stories where we
|
||||
-- want the oldest one first
|
||||
ORDER BY receivedAt ASC
|
||||
|
@ -4831,6 +4843,8 @@ function getNextAttachmentDownloadJobs(
|
|||
active = 0
|
||||
AND
|
||||
(retryAfter is NULL OR retryAfter <= ${timestamp})
|
||||
AND
|
||||
${sourceWhereFragment}
|
||||
ORDER BY receivedAt DESC
|
||||
LIMIT ${numJobsRemaining}
|
||||
`;
|
||||
|
|
29
ts/sql/migrations/1200-attachment-download-source-index.ts
Normal file
29
ts/sql/migrations/1200-attachment-download-source-index.ts
Normal file
|
@ -0,0 +1,29 @@
|
|||
// 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 = 1200;
|
||||
export function updateToSchemaVersion1200(
|
||||
currentVersion: number,
|
||||
db: Database,
|
||||
logger: LoggerType
|
||||
): void {
|
||||
if (currentVersion >= 1200) {
|
||||
return;
|
||||
}
|
||||
|
||||
db.transaction(() => {
|
||||
// The standard getNextAttachmentDownloadJobs query uses active & source conditions,
|
||||
// ordered by received_at
|
||||
db.exec(`
|
||||
CREATE INDEX attachment_downloads_active_source_receivedAt
|
||||
ON attachment_downloads (
|
||||
active, source, receivedAt
|
||||
);
|
||||
`);
|
||||
|
||||
db.pragma('user_version = 1200');
|
||||
})();
|
||||
logger.info('updateToSchemaVersion1200: success!');
|
||||
}
|
|
@ -95,10 +95,11 @@ 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 { updateToSchemaVersion1180 } from './1180-add-attachment-download-source';
|
||||
import { updateToSchemaVersion1190 } from './1190-call-links-storage';
|
||||
import {
|
||||
updateToSchemaVersion1190,
|
||||
updateToSchemaVersion1200,
|
||||
version as MAX_VERSION,
|
||||
} from './1190-call-links-storage';
|
||||
} from './1200-attachment-download-source-index';
|
||||
|
||||
function updateToSchemaVersion1(
|
||||
currentVersion: number,
|
||||
|
@ -2062,6 +2063,7 @@ export const SCHEMA_VERSIONS = [
|
|||
updateToSchemaVersion1170,
|
||||
updateToSchemaVersion1180,
|
||||
updateToSchemaVersion1190,
|
||||
updateToSchemaVersion1200,
|
||||
];
|
||||
|
||||
export class DBVersionFromFutureError extends Error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue