Enable more specific AttachmentDownload prioritization

This commit is contained in:
trevor-signal 2024-04-15 20:11:48 -04:00 committed by GitHub
parent 87ea909ae9
commit fc02762588
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 2245 additions and 817 deletions

View file

@ -128,7 +128,6 @@ import type { ViewOnceOpenSyncAttributesType } from './messageModifiers/ViewOnce
import { ReadStatus } from './messages/MessageReadStatus';
import type { SendStateByConversationId } from './messages/MessageSendState';
import { SendStatus } from './messages/MessageSendState';
import * as AttachmentDownloads from './messageModifiers/AttachmentDownloads';
import * as Stickers from './types/Stickers';
import * as Errors from './types/errors';
import { SignalService as Proto } from './protobuf';
@ -197,6 +196,7 @@ import {
} from './util/callDisposition';
import { deriveStorageServiceKey } from './Crypto';
import { getThemeType } from './util/getThemeType';
import { AttachmentDownloadManager } from './jobs/AttachmentDownloadManager';
export function isOverHourIntoPast(timestamp: number): boolean {
return isNumber(timestamp) && isOlderThan(timestamp, HOUR);
@ -715,8 +715,9 @@ export async function startApp(): Promise<void> {
'background/shutdown: shutdown requested'
);
server?.cancelInflightRequests('shutdown');
// Stop background processing
void AttachmentDownloads.stop();
idleDetector.stop();
// Stop processing incoming messages
@ -793,6 +794,14 @@ export async function startApp(): Promise<void> {
window.waitForAllWaitBatchers(),
]);
log.info(
'background/shutdown: waiting for all attachment downloads to finish'
);
// Since we canceled the inflight requests earlier in shutdown, this should
// resolve quickly
await AttachmentDownloadManager.stop();
log.info('background/shutdown: closing the database');
// Shut down the data interface cleanly
@ -1541,7 +1550,7 @@ export async function startApp(): Promise<void> {
log.info('background: offline');
drop(challengeHandler?.onOffline());
drop(AttachmentDownloads.stop());
drop(AttachmentDownloadManager.stop());
drop(messageReceiver?.drain());
if (connectCount === 0) {
@ -1686,11 +1695,7 @@ export async function startApp(): Promise<void> {
void window.Signal.Services.initializeGroupCredentialFetcher();
drop(
AttachmentDownloads.start({
logger: log,
})
);
drop(AttachmentDownloadManager.start());
if (connectCount === 1) {
Stickers.downloadQueuedPacks();