Skip to content

Commit

Permalink
old renotes
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Aug 9, 2019
1 parent 196946e commit fbb00f1
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/tools/_clean-old-posts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Favorite from '../models/favorite';
import { concat } from '../prelude/array';

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

// favs
const favs = await Favorite.find({
Expand Down Expand Up @@ -51,7 +51,10 @@ async function main() {
},

{
renoteCount: { $exists: false }
$or: [
{ renoteCount: { $exists: false } },
{ renoteCount: 0 },
],
},
{
repliesCount: { $exists: false }
Expand Down
90 changes: 90 additions & 0 deletions src/tools/_clean-old-renotes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
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('f00000000000000000000000');

// 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 notes = await Note.find({
$and: [
{
userId: user._id
},

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

{
$or: [
{ renoteCount: { $exists: false } },
{ renoteCount: 0 },
],
},
{
repliesCount: { $exists: false }
},
{
reactionCounts: { $exists: false }
},

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

for (const note of notes) {
console.log(`${note._id}`);
await Note.update({ _id: note.renoteId }, {
$inc: {
renoteCount: -1
}
});

await Note.remove({ _id: note._id });
}
}
}

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

0 comments on commit fbb00f1

Please sign in to comment.