From 9e3aabd8eabee29f5df9b4aa8d1835a00e5c5fb0 Mon Sep 17 00:00:00 2001 From: fatchan Date: Sat, 27 Apr 2019 12:37:38 +0000 Subject: [PATCH] something to start prune oldest threads --- db/posts.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/db/posts.js b/db/posts.js index c102b17f..f97f87a3 100644 --- a/db/posts.js +++ b/db/posts.js @@ -269,7 +269,7 @@ module.exports = { const postId = await Boards.getNextId(board); data.postId = postId; await db.insertOne(data); - + //await module.exports.pruneOldThreads(board); return postId; }, @@ -309,6 +309,41 @@ module.exports = { return db.deleteOne(options); }, +/* pruneOldThreads: async (board) => { + const threadsToPrune = await db.find({ + 'thread': null, + 'board': board + }, { + 'projection': { + 'postId': 1, + '_id': 0 + } + }).sort({ + 'sticky': -1, + 'bumped': -1 + }).skip(3).toArray(); + console.log(threadsToPrune); + const ids = threadsToPrune.map(x => x.postId); + console.log(ids); + const data = await db.deleteMany({ + 'board': board, + '$or': [ + { + 'postId': { + '$in': ids + } + }, + { + 'thread': { + '$in': ids + } + }, + ] + }); + console.log(data.deletedCount); + //wont delete files gotta fetch thread posts for that + },*/ + deleteMany: (ids) => { return db.deleteMany({