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);
},
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) => {

@ -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

@ -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('--------------------------------');
}

Loading…
Cancel
Save