diff --git a/db/posts.js b/db/posts.js index 87c59db4..fae2c136 100644 --- a/db/posts.js +++ b/db/posts.js @@ -354,16 +354,26 @@ module.exports = { return db.deleteOne(options); }, - pruneOldThreads: async (board, threadLimit) => { - //get lowest bumped threads - const threads = await db.find({ + pruneOldThreads: async (board) => { + + //get threads that have been bumped off last page + const oldThreads = await db.find({ 'thread': null, - 'board': board + 'board': board._id }).sort({ 'sticky': -1, 'bumped': -1 - }).skip(threadLimit).toArray(); - return threads; + }).skip(board.settings.threadLimit).toArray(); + + const early404Threads = await db.find({ + 'thread': null, + 'board': board._id, + 'replyposts': { + '$lte': 5 //less than 5 replies + } + }).skip(30).toArray() //after page 3 + + return oldThreads.concat(early404Threads); }, deleteMany: (ids) => { diff --git a/models/forms/changeboardsettings.js b/models/forms/changeboardsettings.js index eea2f610..c3b7113c 100644 --- a/models/forms/changeboardsettings.js +++ b/models/forms/changeboardsettings.js @@ -48,7 +48,7 @@ module.exports = async (req, res, next) => { const newMaxPage = Math.ceil(newSettings.threadLimit/10); if (newMaxPage < oldMaxPage) { //prune old threads - const prunedThreads = await Posts.pruneOldThreads(req.params.board, res.locals.board.settings.threadLimit); + const prunedThreads = await Posts.pruneOldThreads(res.locals.board); if (prunedThreads.length > 0) { await deletePosts(prunedThreads, req.params.board); //remove board page html for pages > newMaxPage diff --git a/models/forms/makepost.js b/models/forms/makepost.js index c575184c..6233381c 100644 --- a/models/forms/makepost.js +++ b/models/forms/makepost.js @@ -279,8 +279,7 @@ module.exports = async (req, res, next) => { } const successRedirect = `/${req.params.board}/thread/${req.body.thread || postId}.html#${postId}`; -console.log('--------------------------------'); -console.log(`NEW POST -> ${successRedirect}`); + console.log(`NEW POST -> ${successRedirect}`); //build just the thread they need to see first and send them immediately await buildThread(data.thread || postId, res.locals.board); @@ -300,7 +299,7 @@ console.log(`NEW POST -> ${successRedirect}`); } } else { //new thread, prunes any old threads before rebuilds - const prunedThreads = await Posts.pruneOldThreads(req.params.board, res.locals.board.settings.threadLimit); + const prunedThreads = await Posts.pruneOldThreads(res.locals.board); //TODO: could add early404 here alongside thread pruning. if (prunedThreads.length > 0) { await deletePosts(prunedThreads, req.params.board); @@ -314,6 +313,4 @@ console.log(`NEW POST -> ${successRedirect}`); //finish building other pages await Promise.all(parallelPromises); -console.log('--------------------------------'); - }