Dont repeat actions for boards that are already locked(or +unlisted) and not being deleted

merge-requests/341/head
Thomas Lynch 2 years ago
parent 425c15f1ce
commit a58d486a92
  1. 27
      db/boards.js
  2. 4
      schedules/tasks/abandonedboards.js

@ -311,20 +311,35 @@ module.exports = {
}).toArray();
},
getAbandoned: () => {
return db.find({
getAbandoned: (action=0) => {
const filter = {
'webring': false,
'owner': null,
}).toArray();
};
if (action === 1) {
//if just locking, only match unlocked boards
filter['settings.lockMode'] = { '$lt': 2 };
} else if (action === 2) {
//if locking+unlisting, match ones that satisfy any of the conditions
filter['$or'] = [
{ 'settings.unlistedWebring': false },
{ 'settings.unlistedLocal': false },
{ 'settings.lockMode': { '$lt': 2 } },
];
}
//else we return boards purely based on owner: null because they are going to be deleted anyway
return db
.find(filter)
.toArray();
},
unlistMany: (boards) => {
const update = {
'settings.unlistedLocal': true,
'settings.unlistedWebring': true,
'settings.lockMode': 2,
};
if (config.get.abandonedBoardAction === 2) {
update['settings.lockMode'] = 2;
update['settings.unlistedLocal'] = true;
update['settings.unlistedWebring'] = true;
}
cache.srem('boards:listed', boards);
cache.del(boards.map(b => `board:${b}`));

@ -14,13 +14,13 @@ module.exports = {
return;
}
const abandonedBoards = await Boards.getAbandoned();
const abandonedBoards = await Boards.getAbandoned(config.get.abandonedBoardAction);
if (abandonedBoards.length === 0) {
return;
}
if (config.get.abandonedBoardAction <= 2) {
debugLogs && console.log(`Unlisting${config.get.abandonedBoardAction === 2 ? '+Locking' : ''} ${abandonedBoards.length} abandoned boards.`);
debugLogs && console.log(`Locking${config.get.abandonedBoardAction === 2 ? '+Unlisting' : ''} ${abandonedBoards.length} abandoned boards.`);
const abandonedURIs = abandonedBoards.map(b => b._id);
Boards.unlistMany(abandonedURIs);
} else { //must be 2

Loading…
Cancel
Save