ealy404 added to pruneoldthreads

merge-requests/208/head
fatchan 5 years ago
parent c8093fce8b
commit aeb71caae6
  1. 22
      db/posts.js
  2. 2
      models/forms/changeboardsettings.js
  3. 7
      models/forms/makepost.js

@ -354,16 +354,26 @@ module.exports = {
return db.deleteOne(options); return db.deleteOne(options);
}, },
pruneOldThreads: async (board, threadLimit) => { pruneOldThreads: async (board) => {
//get lowest bumped threads
const threads = await db.find({ //get threads that have been bumped off last page
const oldThreads = await db.find({
'thread': null, 'thread': null,
'board': board 'board': board._id
}).sort({ }).sort({
'sticky': -1, 'sticky': -1,
'bumped': -1 'bumped': -1
}).skip(threadLimit).toArray(); }).skip(board.settings.threadLimit).toArray();
return threads;
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) => { deleteMany: (ids) => {

@ -48,7 +48,7 @@ module.exports = async (req, res, next) => {
const newMaxPage = Math.ceil(newSettings.threadLimit/10); const newMaxPage = Math.ceil(newSettings.threadLimit/10);
if (newMaxPage < oldMaxPage) { if (newMaxPage < oldMaxPage) {
//prune old threads //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) { if (prunedThreads.length > 0) {
await deletePosts(prunedThreads, req.params.board); await deletePosts(prunedThreads, req.params.board);
//remove board page html for pages > newMaxPage //remove board page html for pages > newMaxPage

@ -279,8 +279,7 @@ module.exports = async (req, res, next) => {
} }
const successRedirect = `/${req.params.board}/thread/${req.body.thread || postId}.html#${postId}`; 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 //build just the thread they need to see first and send them immediately
await buildThread(data.thread || postId, res.locals.board); await buildThread(data.thread || postId, res.locals.board);
@ -300,7 +299,7 @@ console.log(`NEW POST -> ${successRedirect}`);
} }
} else { } else {
//new thread, prunes any old threads before rebuilds //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. //TODO: could add early404 here alongside thread pruning.
if (prunedThreads.length > 0) { if (prunedThreads.length > 0) {
await deletePosts(prunedThreads, req.params.board); await deletePosts(prunedThreads, req.params.board);
@ -314,6 +313,4 @@ console.log(`NEW POST -> ${successRedirect}`);
//finish building other pages //finish building other pages
await Promise.all(parallelPromises); await Promise.all(parallelPromises);
console.log('--------------------------------');
} }

Loading…
Cancel
Save