dont build homepage immediately on schedule start, and move delete captchas to separate file

merge-requests/208/head
fatchan 5 years ago
parent a7cf529a89
commit 5ce2b42a0e
  1. 25
      helpers/captcha/deletecaptchas.js
  2. 4
      models/pages/globalmanage.js
  3. 29
      schedules.js

@ -0,0 +1,25 @@
'use strict';
const { stat, remove, readdir } = require('fs-extra')
, uploadDirectory = require(__dirname+'/../files/uploadDirectory.js')
, msTime = require(__dirname+'/../mstime.js')
module.exports = async () => {
const files = await readdir(`${uploadDirectory}captcha/`);
if (files.length > 0) {
files.forEach(async (file) => {
try {
const filePath = `${uploadDirectory}captcha/${file}`;
const stats = await stat(filePath);
const now = Date.now();
const expiry = new Date(stats.ctime).getTime() + msTime.minute*5;
if (now > expiry) {
await remove(filePath);
console.log(`Deleted expired captcha ${filePath}`)
}
} catch (e) {
console.error(e);
}
});
}
}

@ -1,8 +1,6 @@
'use strict';
const Posts = require(__dirname+'/../../db/posts.js')
, Bans = require(__dirname+'/../../db/bans.js')
, News = require(__dirname+'/../../db/news.js');
const { Bans, News, Posts } = require(__dirname+'/../../db/')
module.exports = async (req, res, next) => {

@ -4,30 +4,9 @@ process
.on('uncaughtException', console.error)
.on('unhandledRejection', console.error);
const { stat, remove, readdir } = require('fs-extra')
, uploadDirectory = require(__dirname+'/helpers/files/uploadDirectory.js')
, msTime = require(__dirname+'/helpers/mstime.js')
, Mongo = require(__dirname+'/db/db.js')
async function deleteCaptchas() {
const files = await readdir(`${uploadDirectory}captcha/`);
if (files.length > 0) {
files.forEach(async (file) => {
try {
const filePath = `${uploadDirectory}captcha/${file}`;
const stats = await stat(filePath);
const now = Date.now();
const expiry = new Date(stats.ctime).getTime() + msTime.minute*5;
if (now > expiry) {
await remove(filePath);
console.log(`Deleted expired captcha ${filePath}`)
}
} catch (e) {
console.error(e);
}
});
}
}
const msTime = require(__dirname+'/helpers/mstime.js')
, deleteCaptchas = require(__dirname+'/helpers/captcha/deletecaptchas.js')
, Mongo = require(__dirname+'/db/db.js');
(async () => {
@ -37,7 +16,6 @@ async function deleteCaptchas() {
console.log('Starting schedules');
await buildHomepage();
setInterval(async () => {
try {
await buildHomepage();
@ -46,7 +24,6 @@ async function deleteCaptchas() {
}
}, msTime.minute*5); //rebuild homepage for pph updates
//could make this use a db changefeed
setInterval(async () => {
try {
await deleteCaptchas();

Loading…
Cancel
Save