Skip to content

Commit

Permalink
[keyserver] Remove holders in thread deleters
Browse files Browse the repository at this point in the history
Summary:
Address [[ https://linear.app/comm/issue/ENG-9354/delete-holders-when-deleting-thread | ENG-9354 ]].
Before calling `DELETE FROM uploads`, we need to select the `extra` column first and remove blob holders if present in the column JSON.

Depends on D13512

Test Plan: Enabled blob-hosted avatars for thin threads. Created a thread and set image avatar. Then deleted the thread. Looked into blob service logs to see that a blob was uploaded, then its holder was removed

Reviewers: tomek, ashoat

Reviewed By: ashoat

Differential Revision: https://phab.comm.dev/D13513
  • Loading branch information
barthap committed Oct 2, 2024
1 parent 4f2c8b6 commit d1df2ad
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion keyserver/src/deleters/thread-deleters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import {
import { fetchThreadPermissionsBlob } from '../fetchers/thread-permission-fetchers.js';
import { fetchUpdateInfoForThreadDeletion } from '../fetchers/update-fetchers.js';
import { rescindPushNotifs } from '../push/rescind.js';
import { removeBlobHolders } from '../services/blob.js';
import type { Viewer } from '../session/viewer.js';
import { blobHoldersFromUploadRows } from '../uploads/media-utils.js';

type DeleteThreadOptions = Partial<{
+ignorePermissions: boolean,
Expand Down Expand Up @@ -60,6 +62,8 @@ async function deleteThread(
// thread-permission-updaters should be used for descendant threads.
const threadIDs = await fetchContainedThreadIDs(threadID);

await fetchAndDeleteThreadBlobHolders(threadIDs);

const [{ threadInfos: serverThreadInfos }] = await Promise.all([
fetchServerThreadInfos({ threadIDs: new Set(threadIDs) }),
rescindPushNotifs(
Expand Down Expand Up @@ -89,6 +93,19 @@ async function deleteThread(
return { updatesResult: { newUpdates: viewerUpdates } };
}

async function fetchAndDeleteThreadBlobHolders(
threadIDs: $ReadOnlyArray<string>,
): Promise<void> {
const query = SQL`
SELECT extra
FROM uploads
WHERE container IN (${threadIDs})
`;
const [rows] = await dbQuery(query);
const blobHolders = blobHoldersFromUploadRows(rows);
await removeBlobHolders(blobHolders);
}

function deleteThreadsFromDB(
threadIDs: $ReadOnlyArray<string>,
): Promise<mixed> {
Expand Down Expand Up @@ -144,7 +161,9 @@ async function deleteInaccessibleThreads(): Promise<void> {
if (threadIDs.size === 0) {
return;
}
await deleteThreadsFromDB([...threadIDs]);
const containerIDs = [...threadIDs];
await fetchAndDeleteThreadBlobHolders(containerIDs);
await deleteThreadsFromDB(containerIDs);
}

export { deleteThread, deleteInaccessibleThreads };

0 comments on commit d1df2ad

Please sign in to comment.