implemented tombstoning

This commit is contained in:
Wyatt Johnson
2018-04-18 17:22:39 -06:00
parent 431e9d8b09
commit 8e34fd1925
11 changed files with 75 additions and 31 deletions
+30 -23
View File
@@ -92,7 +92,7 @@ const delUser = async (ctx, id) => {
updateBatchSize: 10000,
});
// Remove all actions against comments.
// Remove all actions against this users comments.
await transformSingleWithCursor(
Action.collection.find({ user_id: user.id, item_type: 'COMMENTS' }),
actionDecrTransformer,
@@ -111,34 +111,41 @@ const delUser = async (ctx, id) => {
.setOptions({ multi: true })
.remove();
// Removes all the user's reply counts on each of the comments that they
// have commented on.
// For each comment that the user has authored, purge the comment data from it
// and unset their id from those comments.
await transformSingleWithCursor(
Comment.collection.aggregate([
{ $match: { author_id: user.id } },
{
$group: {
_id: '$parent_id',
count: { $sum: 1 },
},
},
]),
({ _id: parent_id, count }) => ({
query: { id: parent_id },
update: {
$inc: {
reply_count: -1 * count,
},
Comment.collection.find({ author_id: user.id }),
({
id,
asset_id,
status,
parent_id,
reply_count,
created_at,
updated_at,
}) => ({
query: { id },
replace: {
id,
body: null,
body_history: [],
asset_id,
author_id: null,
status_history: [],
status,
parent_id,
reply_count,
action_counts: {},
tags: [],
metadata: {},
deleted_at: new Date(),
created_at,
updated_at,
},
}),
Comment
);
// Remove all the user's comments.
await Comment.where({ author_id: user.id })
.setOptions({ multi: true })
.remove();
// Remove the user.
await user.remove();
};