Reuse recent CDN locators

This commit is contained in:
trevor-signal
2026-02-24 12:58:17 -05:00
committed by GitHub
parent d38277e2ce
commit 239b57576f
8 changed files with 398 additions and 120 deletions

View File

@@ -198,6 +198,7 @@ import type {
GetMessagesBetweenOptions,
MaybeStaleCallHistory,
ExistingAttachmentData,
ExistingAttachmentUploadData,
} from './Interface.std.js';
import {
AttachmentDownloadSource,
@@ -559,6 +560,7 @@ export const DataReader: ServerReadableInterface = {
getStatisticsForLogging,
getMostRecentAttachmentUploadData,
getBackupCdnObjectMetadata,
getBackupAttachmentDownloadProgress,
getAttachmentReferencesForMessages,
@@ -3043,6 +3045,35 @@ function isAttachmentSafeToDelete(db: ReadableDB, path: string): boolean {
return db.prepare(query, { pluck: true }).get(params) === 0;
}
function getMostRecentAttachmentUploadData(
db: ReadableDB,
plaintextHash: string
): ExistingAttachmentUploadData | undefined {
const [query, params] = sql`
SELECT
key,
digest,
transitCdnKey AS cdnKey,
transitCdnNumber AS cdnNumber,
transitCdnUploadTimestamp AS uploadTimestamp,
incrementalMac,
incrementalMacChunkSize as chunkSize
FROM message_attachments
INDEXED BY message_attachments_plaintextHash
WHERE
plaintextHash = ${plaintextHash} AND
key IS NOT NULL AND
digest IS NOT NULL AND
transitCdnKey IS NOT NULL AND
transitCdnNumber IS NOT NULL AND
transitCdnUploadTimestamp IS NOT NULL
ORDER BY transitCdnUploadTimestamp DESC
LIMIT 1
`;
return db.prepare(query).get<ExistingAttachmentUploadData>(params);
}
function _testOnlyRemoveMessageAttachments(
db: WritableDB,
timestamp: number