Reuse recent CDN locators

Co-authored-by: trevor-signal <131492920+trevor-signal@users.noreply.github.com>
This commit is contained in:
automated-signal
2026-02-24 14:31:40 -06:00
committed by GitHub
parent d0ec8ae066
commit 4a9093091c
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,
@@ -560,6 +561,7 @@ export const DataReader: ServerReadableInterface = {
getStatisticsForLogging,
getMostRecentAttachmentUploadData,
getBackupCdnObjectMetadata,
getBackupAttachmentDownloadProgress,
getAttachmentReferencesForMessages,
@@ -3045,6 +3047,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