From fbc4661ffc6b9ed1a7bdd84779b850f5bcfa35a9 Mon Sep 17 00:00:00 2001 From: fatchan Date: Fri, 1 May 2020 22:31:19 +1000 Subject: [PATCH] webring with temp collection instead of removeall and insertmany references #121 --- schedules/webring.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/schedules/webring.js b/schedules/webring.js index 7eadbedc..175ffb09 100644 --- a/schedules/webring.js +++ b/schedules/webring.js @@ -3,12 +3,13 @@ const fetch = require('node-fetch') , { debugLogs, meta } = require(__dirname+'/../configs/main.js') , { logo, following, blacklist, proxy } = require(__dirname+'/../configs/webring.json') + , Mongo = require(__dirname+'/../db/db.js') , { Boards, Webring } = require(__dirname+'/../db/') , { outputFile } = require('fs-extra') , cache = require(__dirname+'/../redis.js') , uploadDirectory = require(__dirname+'/../helpers/files/uploadDirectory.js') , timeDiffString = require(__dirname+'/../helpers/timediffstring.js') - , SocksProxyAgent = proxy.enabled ? require('socks-proxy-agent') : null + , SocksProxyAgent = proxy.enabled && require('socks-proxy-agent') , agent = SocksProxyAgent ? new SocksProxyAgent(require('url').parse(proxy.address)) : null module.exports = async () => { @@ -55,10 +56,13 @@ module.exports = async () => { } } - //remove and replace webring boards - await Webring.deleteAll(); - await Webring.db.insertMany(webringBoards); -//TODO: insert into a temp colletion and use a $out aggregation stage to prevent small timeframe of empty collection + //$out from temp collection to replace webring boards + const tempCollection = Mongo.client.db('jschan').collection('tempwebring'); + await tempCollection.insertMany(webringBoards); + await tempCollection.aggregate([ + { $out : 'webring' } + ]); + await tempCollection.drop(); //update webring.json const boards = await Boards.webringBoards();