Skip to content

Commit

Permalink
古いリモート投稿を物理削除する
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Aug 9, 2019
1 parent a89ccfe commit 196946e
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/tools/_clean-old-posts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import User from '../models/user';
import Note from '../models/note';
import { ObjectID } from 'mongodb';
import Favorite from '../models/favorite';
import { concat } from '../prelude/array';

async function main() {
const id = new ObjectID('700000000000000000000000');

// favs
const favs = await Favorite.find({
noteId: { $lt: id }
});

// remote users
const users = await User.find({
host: { $ne: null },
}, {
fields: {
_id: true
}
});

let prs = 0;

for (const u of users) {
prs++;

const user = await User.findOne({
_id: u._id
});

console.log(`user(${prs}/${users.length}): ${user.username}@${user.host}`);

const exIds = concat([
favs.map(x => x.noteId),
(user.pinnedNoteIds || [])
]);

const result = await Note.remove({
$and: [
{
userId: user._id
},

{
_id: { $nin: exIds }
},
{
_id: { $lt: id }
},

{
renoteCount: { $exists: false }
},
{
repliesCount: { $exists: false }
},
{
reactionCounts: { $exists: false }
},

{
replyId: null,
},
{
renoteId: null,
},
],
});

console.log(` deleted count:${result.deletedCount}`);

/*
for (const note of notes) {
//console.log(JSON.stringify(note, null, 2));
console.log(`${note._id}`);
}
*/
}
}

main().then(() => {
console.log('Done');
});

0 comments on commit 196946e

Please sign in to comment.