dont build webring redundantly and set flag when new post or change setting on unlisted board, or new board created or existing listed board deleted

merge-requests/208/head
fatchan 5 years ago
parent 0920fa9de4
commit 89d1c7aa16
  1. 2
      controllers/forms/deleteboard.js
  2. 1
      db/boards.js
  3. 7
      db/posts.js
  4. 13
      models/forms/changeboardsettings.js
  5. 6
      models/forms/deleteboard.js
  6. 55
      schedules/webring.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);
}

@ -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);
},

@ -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;
},

@ -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': {

@ -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);
}
}

@ -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));

Loading…
Cancel
Save