diff --git a/controllers/forms/deleteboard.js b/controllers/forms/deleteboard.js index a9128771..0287852f 100644 --- a/controllers/forms/deleteboard.js +++ b/controllers/forms/deleteboard.js @@ -43,7 +43,7 @@ module.exports = async (req, res, next) => { } try { - await deleteBoard(req.body.uri); + await deleteBoard(board._id, board); } catch (err) { return next(err); } diff --git a/db/boards.js b/db/boards.js index 753a4222..f9bfd806 100644 --- a/db/boards.js +++ b/db/boards.js @@ -50,6 +50,7 @@ module.exports = { insertOne: (data) => { cache.del(`board_${data._id}`); //removing cached no_exist + cache.set('webring_update', 1); return db.insertOne(data); }, diff --git a/db/posts.js b/db/posts.js index b9683a97..58fe3550 100644 --- a/db/posts.js +++ b/db/posts.js @@ -4,6 +4,7 @@ const Mongo = require(__dirname+'/db.js') , Boards = require(__dirname+'/boards.js') , Stats = require(__dirname+'/stats.js') , db = Mongo.client.db('jschan').collection('posts') + , cache = require(__dirname+'/../redis.js') , { quoteLimit } = require(__dirname+'/../configs/main.json'); module.exports = { @@ -322,6 +323,11 @@ module.exports = { data.bumped = new Date() } + if (!saged && !board.unlisted) { + //mark webring as needing update for schedule to reduce redundant webring builds + cache.set('webring_update', 1); + } + //get the postId and add it to the post const postId = await Boards.getNextId(board._id, saged); data.postId = postId; @@ -343,6 +349,7 @@ module.exports = { } }); } + return postId; }, diff --git a/models/forms/changeboardsettings.js b/models/forms/changeboardsettings.js index e17bcb6e..1d7edd56 100644 --- a/models/forms/changeboardsettings.js +++ b/models/forms/changeboardsettings.js @@ -3,6 +3,7 @@ const { Boards, Posts, Accounts } = require(__dirname+'/../../db/') , uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.js') , buildQueue = require(__dirname+'/../../queue.js') + , cache = require(__dirname+'/../../redis.js') , { remove } = require('fs-extra') , deletePosts = require(__dirname+'/deletepost.js') , linkQuotes = require(__dirname+'/../../helpers/posting/quotes.js') @@ -102,6 +103,16 @@ module.exports = async (req, res, next) => { , rebuildCatalog = false , rebuildOther = false; + //name, description, sfw, unlisted, tags changed need webring update + if ((!oldSettings.unlisted && !newSettings.unlisted) //if not unlisted or is changing unlisted status (thus will be added or removed from webring list) + && (oldSettings.name != newSettings.name //and changing something that needs to be shown in webring + || oldSettings.description != newSettings.description + || oldSettings.unlisted != newSettings.unlisted + || oldSettings.sfw != newSettings.sfw + || oldSettings.tags != newSettings.tags)) { + cache.set('webring_update', 1); + } + if (newSettings.captchaMode > oldSettings.captchaMode) { rebuildBoard = true; if (newSettings.captchaMode == 2) { @@ -156,13 +167,13 @@ module.exports = async (req, res, next) => { }); } if (rebuildOther) { + //NOTE does not rebuild individual log pages they are stuck on old theme for now buildQueue.push({ 'task': 'buildModLogList', 'options': { 'board': res.locals.board, } }); - //NOTE does not rebuild individual log pages they are stuck on old theme for now buildQueue.push({ 'task': 'buildBanners', 'options': { diff --git a/models/forms/deleteboard.js b/models/forms/deleteboard.js index acd64da5..3120b790 100644 --- a/models/forms/deleteboard.js +++ b/models/forms/deleteboard.js @@ -1,11 +1,12 @@ 'use strict'; const { Boards, Stats, Posts, Bans, Modlogs } = require(__dirname+'/../../db/') + , cache = require(__dirname+'/../../redis.js') , deletePosts = require(__dirname+'/deletepost.js') , uploadDirectory = require(__dirname+'/../../helpers/files/uploadDirectory.js') , { remove } = require('fs-extra'); -module.exports = async (uri) => { +module.exports = async (uri, board) => { //delete board await Boards.deleteOne(uri); @@ -23,5 +24,8 @@ module.exports = async (uri) => { remove(`${uploadDirectory}/json/${uri}/`), //json remove(`${uploadDirectory}/banners/${uri}/`) //banners ]); + if (!board.unlisted) { + cache.set('webring_update', 1); + } } diff --git a/schedules/webring.js b/schedules/webring.js index 56672b22..f420fd8d 100644 --- a/schedules/webring.js +++ b/schedules/webring.js @@ -10,7 +10,7 @@ const fetch = require('node-fetch') , timeDiffString = require(__dirname+'/../helpers/timediffstring.js'); module.exports = async () => { - const label = `/webring.json`; + const label = `updating webring`; const start = process.hrtime(); //fetch stuff from others @@ -56,32 +56,35 @@ module.exports = async () => { await Webring.db.insertMany(webringBoards); //output our own webring json - const boards = await Boards.boardSort(0, 0); - const json = { - name: meta.siteName, - url: meta.url, - endpoint: `${meta.url}/webring.json`, - logos, - following, - blacklist, - known, - boards: boards.map(b => { - //map local boards to webring format - return { - uri: b._id, - title: b.settings.name, - subtitle: b.settings.description, - path: `${meta.url}/${b._id}/`, - postsPerHour: b.pph, - totalPosts: b.sequence_value-1, - uniqueUsers: b.ips, - nsfw: !b.settings.sfw, - tags: b.settings.tags, - lastPostTimestamp: b.lastPostTimestamp, - }; - }), + const needsUpdate = await cache.del('webring_update'); //returns 1 if somethign was deleted, 0 if not exist + if (needsUpdate) { + const boards = await Boards.boardSort(0, 0); + const json = { + name: meta.siteName, + url: meta.url, + endpoint: `${meta.url}/webring.json`, + logos, + following, + blacklist, + known, + boards: boards.map(b => { + //map local boards to webring format + return { + uri: b._id, + title: b.settings.name, + subtitle: b.settings.description, + path: `${meta.url}/${b._id}/`, + postsPerHour: b.pph, + totalPosts: b.sequence_value-1, + uniqueUsers: b.ips, + nsfw: !b.settings.sfw, + tags: b.settings.tags, + lastPostTimestamp: b.lastPostTimestamp, + }; + }), + } + await outputFile(`${uploadDirectory}/json/webring.json`, JSON.stringify(json)); } - await outputFile(`${uploadDirectory}/json/webring.json`, JSON.stringify(json)); const end = process.hrtime(start); console.log(timeDiffString(label, end));