optimisation for backlink deleting, use an with updadtemany instead of updateOne to reduce bulkwrite amount instead of one for everyt single quote (duhhh)

merge-requests/208/head
fatchan 5 years ago
parent 1932e597ad
commit fcec878053
  1. 30
      models/forms/deletepost.js
  2. 1
      models/forms/makepost.js

@ -50,28 +50,26 @@ module.exports = async (posts, board) => {
return acc;
}, { postFiles: [], postBacklinks: [], postMongoIds: [] });
//is there a nicer way to do this
const bulkWrites = [];
for (let j = 0; j < allPosts.length; j++) {
const post = allPosts[j];
for (let i = 0; i < post.quotes.length; i++) {
const quote = post.quotes[i];
//remove the backlink to this post from any post that it quoted
bulkWrites.push({
'updateOne': {
'filter': {
'_id': quote._id
},
'update': {
'$pull': {
'backlinks': {
'postId': post.postId
}
//remove the backlink to this post from any post that it quoted
bulkWrites.push({
'updateMany': {
'filter': {
'_id': {
'$in': post.quotes.map(q => q._id)
}
},
'update': {
'$pull': {
'backlinks': {
'postId': post.postId
}
}
}
});
}
}
});
}
if (bulkWrites.length > 0) {
await Posts.db.bulkWrite(bulkWrites);

@ -272,7 +272,6 @@ module.exports = async (req, res, next) => {
//for cyclic threads, delete posts beyond bump limit
if (thread && thread.cyclic && thread.replyposts > res.locals.board.settings.replyLimit) {
//is there a way to NOT have to fetch before deleting for this?
const cyclicOverflowPosts = await Posts.db.find({
'thread': data.thread,
'board': req.params.board

Loading…
Cancel
Save