make time diff string separate function and use it in webring generatio nfor same format timestamp

merge-requests/208/head
fatchan 5 years ago
parent 457384be94
commit 93b63c893b
  1. 2
      helpers/tasks.js
  2. 5
      helpers/timediffstring.js
  3. 9
      schedules/webring.js

@ -8,7 +8,7 @@ const Mongo = require(__dirname+'/../db/db.js')
, { pruneModlogs, enableWebring } = require(__dirname+'/../configs/main.json')
, { Stats, Posts, Files, Boards, News, Modlogs } = require(__dirname+'/../db/')
, render = require(__dirname+'/render.js')
, timeDiffString = (label, end) => `${label} -> ${end[0] > 0 ? end[0]+'s ' : ''}${(end[1]/1000000).toFixed(2)}ms`;
, timeDiffString = require(__dirname+'/timediffstring.js');
module.exports = {

@ -0,0 +1,5 @@
'use strict';
module.exports = (label, end) => {
return `${label} -> ${end[0] > 0 ? end[0]+'s ' : ''}${(end[1]/1000000).toFixed(2)}ms`;
}

@ -6,12 +6,14 @@ const fetch = require('node-fetch')
, { Boards } = require(__dirname+'/../db/')
, { outputFile } = require('fs-extra')
, cache = require(__dirname+'/../redis.js')
, uploadDirectory = require(__dirname+'/../helpers/files/uploadDirectory.js');
, uploadDirectory = require(__dirname+'/../helpers/files/uploadDirectory.js')
, timeDiffString = require(__dirname+'/../helpers/timediffstring.js');
module.exports = async () => {
const label = `/webring.json`;
const start = process.hrtime();
//fetch stuff from others
const fetchWebring = [...new Set((await cache.get('webring:sites') || []).concat(following))]
console.log('updating webring', fetchWebring);
let rings = await Promise.all(fetchWebring.map(url => {
return fetch(url).then(res => res.json()).catch(e => console.error);
}));
@ -63,5 +65,6 @@ module.exports = async () => {
}),
}
await outputFile(`${uploadDirectory}/json/webring.json`, JSON.stringify(json));
console.log('updated webring');
const end = process.hrtime(start);
console.log(timeDiffString(label, end));
}

Loading…
Cancel
Save