From 93b63c893bb1ce3844e3576e7234266f51cc3027 Mon Sep 17 00:00:00 2001 From: fatchan Date: Tue, 8 Oct 2019 10:51:37 +0000 Subject: [PATCH] make time diff string separate function and use it in webring generatio nfor same format timestamp --- helpers/tasks.js | 2 +- helpers/timediffstring.js | 5 +++++ schedules/webring.js | 9 ++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 helpers/timediffstring.js diff --git a/helpers/tasks.js b/helpers/tasks.js index 3719cf02..390cc849 100644 --- a/helpers/tasks.js +++ b/helpers/tasks.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 = { diff --git a/helpers/timediffstring.js b/helpers/timediffstring.js new file mode 100644 index 00000000..d68fa7c6 --- /dev/null +++ b/helpers/timediffstring.js @@ -0,0 +1,5 @@ +'use strict'; + +module.exports = (label, end) => { + return `${label} -> ${end[0] > 0 ? end[0]+'s ' : ''}${(end[1]/1000000).toFixed(2)}ms`; +} diff --git a/schedules/webring.js b/schedules/webring.js index b277a91d..2d0b0b1a 100644 --- a/schedules/webring.js +++ b/schedules/webring.js @@ -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)); }