Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3514358
D13514.id44749.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D13514.id44749.diff
View Options
diff --git a/keyserver/src/deleters/account-deleters.js b/keyserver/src/deleters/account-deleters.js
--- a/keyserver/src/deleters/account-deleters.js
+++ b/keyserver/src/deleters/account-deleters.js
@@ -17,9 +17,38 @@
fetchUsername,
} from '../fetchers/user-fetchers.js';
import { rescindPushNotifs } from '../push/rescind.js';
+import { removeBlobHolders } from '../services/blob.js';
import { createNewAnonymousCookie } from '../session/cookies.js';
import type { Viewer, AnonymousViewerData } from '../session/viewer.js';
import { fetchOlmAccount } from '../updaters/olm-account-updater.js';
+import { blobHoldersFromUploadRows } from '../uploads/media-utils.js';
+
+async function deleteUploadsForUser(deletedUserID: string): Promise<void> {
+ try {
+ const [holderRows] = await dbQuery(SQL`
+ SELECT extra
+ FROM uploads
+ WHERE user_container = ${deletedUserID}
+ `);
+ const blobHolders = blobHoldersFromUploadRows(holderRows);
+ await removeBlobHolders(blobHolders);
+ await dbQuery(SQL`
+ DELETE u, i
+ FROM uploads u
+ LEFT JOIN ids i on i.id = u.id
+ WHERE u.user_container = ${deletedUserID};
+ `);
+ } catch (err) {
+ // unassign uploads so the deletion will be retried
+ // by the `deleteUnassignedUploads()`
+ await dbQuery(SQL`
+ UPDATE uploads
+ SET user_container = NULL
+ WHERE user_container = ${deletedUserID};
+ `);
+ throw err;
+ }
+}
async function deleteAccount(viewer: Viewer): Promise<?LogOutResponse> {
if (!viewer.loggedIn) {
@@ -33,6 +62,8 @@
(user: UserInfo): boolean => user.id !== deletedUserID,
);
+ ignorePromiseRejections(deleteUploadsForUser(deletedUserID));
+
// TODO: if this results in any orphaned orgs, convert them to chats
const deletionQuery = SQL`
START TRANSACTION;
@@ -60,10 +91,6 @@
FROM reports r
LEFT JOIN ids i ON i.id = r.id
WHERE r.user = ${deletedUserID};
- DELETE u, i
- FROM uploads u
- LEFT JOIN ids i on i.id = u.id
- WHERE u.user_container = ${deletedUserID};
DELETE FROM relationships_undirected WHERE user1 = ${deletedUserID};
DELETE FROM relationships_undirected WHERE user2 = ${deletedUserID};
DELETE FROM relationships_directed WHERE user1 = ${deletedUserID};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Dec 23, 4:28 AM (17 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2693547
Default Alt Text
D13514.id44749.diff (2 KB)
Attached To
Mode
D13514: [keyserver] Remove holders in account deleters
Attached
Detach File
Event Timeline
Log In to Comment