Make IP pruning schedule also apply to modlogs

Update CHANGELOG
indiachan-spamvector v0.7.1
Thomas Lynch 2 years ago
parent 18ab7d24ee
commit 0461842d14
  1. 6
      CHANGELOG.md
  2. 51
      schedules/tasks/ips.js

@ -2,8 +2,12 @@
- Show sticky level on hover (title property) of pin icon.
- Reduce frontend script size by ~10KB. More improvement to come in future updates.
- Change homepage hot threads to show creation date rather than last bumped.
- Fix incorrectly hiding "create board"/"register an account" on account page because of permission issue.
- Don't allow setting global limit for post password length below what the frontend automatically generates.
- When strict mime validation is enabled, actually tell the user what the server thinks the mime is in the mismatch error message.
- Make IP pruning schedule also apply to modlogs.
- Fix incorrectly hiding "create board"/"register an account" on account page because of permission issue.
- Fix the nginx configuration script putting commas in CSP if you say yes to recaptcha/hcaptcha.
- Fix recaptcha/hcaptcha causing an issue for scrolling to new posts in some (chrom*) browsers.
- Fix the generate-favicon gulp task not versioning correctly causing cache issues.
- Small frontend and backend refactors.
- Add screenshot image animated with light/dark theme in README.

@ -1,7 +1,7 @@
'use strict';
const Mongo = require(__dirname+'/../../db/db.js')
, { Posts } = require(__dirname+'/../../db/')
, { Posts, Modlogs } = require(__dirname+'/../../db/')
, config = require(__dirname+'/../../lib/misc/config.js')
, { createHash, randomBytes } = require('crypto')
, timeUtils = require(__dirname+'/../../lib/converter/timeutils.js');
@ -9,24 +9,20 @@ const Mongo = require(__dirname+'/../../db/db.js')
module.exports = {
func: async (days) => {
//make a mongoid set to the date before which we prunt IPs on, because _id holds date and is always indexed
const beforeDate = new Date();
beforeDate.setDate(beforeDate.getDate() - (days || config.get.pruneIps));
const beforeDateMongoId = Mongo.ObjectId.createFromTime(Math.floor(beforeDate.getTime()/1000));
//use random secret for this schedule run and generate the bulkwrite for pruning IP
const tempIpHashSecret = randomBytes(20).toString('base64');
const bulkWrites = [];
await Posts.db.find({
_id: {
$lte: beforeDateMongoId,
},
'ip.pruned': {
$ne: true
}
}).forEach(post => {
const randomIP = createHash('sha256').update(tempIpHashSecret + post.ip.cloak).digest('base64');
bulkWrites.push({
const mapBulkWrite = (document) => {
const randomIP = createHash('sha256').update(tempIpHashSecret + document.ip.cloak).digest('base64');
return {
updateOne: {
filter: {
_id: post._id,
_id: document._id,
},
update: {
$set: {
@ -36,13 +32,32 @@ module.exports = {
}
}
}
});
};
};
const pruneQuery = {
'_id': {
'$lte': beforeDateMongoId,
},
'ip.pruned': {
'$ne': true
}
};
//No need for promise.all
[Posts, Modlogs].forEach(async (coll, i) => {
const bulkWrites = (await coll.db
.find(pruneQuery)
.toArray())
.map(mapBulkWrite);
if (bulkWrites.length > 0) {
await coll.db.bulkWrite(bulkWrites);
console.log(`Randomised ips on ${bulkWrites.length} ${i === 0 ? 'posts' : 'modlog entries'}`);
}
});
console.log(`Randomising ip on ${bulkWrites.length} posts`);
if (bulkWrites.length > 0) {
await Posts.db.bulkWrite(bulkWrites);
}
},
interval: timeUtils.DAY,
immediate: true,
condition: 'pruneIps',

Loading…
Cancel
Save