fix some awaits in build tasks and make lock ttl configurable

merge-requests/208/head
fatchan 5 years ago
parent 7fec1719b5
commit b63e684422
  1. 11
      configs/main.js.example
  2. 4
      helpers/render.js
  3. 16
      helpers/tasks.js

@ -26,15 +26,18 @@ module.exports = {
refererCheck: true, refererCheck: true,
refererRegex: '^https?:\\/\\/(?:www\\.)?domain\\.com\\/', refererRegex: '^https?:\\/\\/(?:www\\.)?domain\\.com\\/',
//data used in opengraph meta tags //data used in opengraph meta tags. used to generate link previews in e.g. discord, twitter, etc
meta: { meta: {
siteName: 'imageboard', siteName: 'imageboard',
url: 'https://domain.com' url: 'https://domain.com'
}, },
//cache templates in memory //cache templates in memory. disable only if editing templates and doing dev work
cacheTemplates: true, cacheTemplates: true,
//max wait time in ms for obtaining locks for saving files
lockWait: 3000,
//prune modlogs older than 30 days. pruning occurs when new modlog entries are generated //prune modlogs older than 30 days. pruning occurs when new modlog entries are generated
pruneModlogs: true, pruneModlogs: true,
@ -44,7 +47,7 @@ module.exports = {
//extension for thumbnails. png is larger but allows transparency //extension for thumbnails. png is larger but allows transparency
thumbExtension: '.png', thumbExtension: '.png',
//max thumb dimensions //max thumb dimensions (square) in px
thumbSize: 200, thumbSize: 200,
//default ban duration in ms if ban duration field is left blank //default ban duration in ms if ban duration field is left blank
@ -56,7 +59,7 @@ module.exports = {
//options for code block highlighting in posts //options for code block highlighting in posts
highlightOptions: { highlightOptions: {
//subset of languages to allow //subset of languages to allow.
languageSubset: [ languageSubset: [
'javascript', 'javascript',
'js', 'js',

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const { globalLimits, boardDefaults, cacheTemplates, meta } = require(__dirname+'/../configs/main.js') const { lockWait, globalLimits, boardDefaults, cacheTemplates, meta } = require(__dirname+'/../configs/main.js')
, { outputFile } = require('fs-extra') , { outputFile } = require('fs-extra')
, pug = require('pug') , pug = require('pug')
, path = require('path') , path = require('path')
@ -17,7 +17,7 @@ module.exports = async (htmlName, templateName, options, json=null) => {
defaultCodeTheme: boardDefaults.codeTheme, defaultCodeTheme: boardDefaults.codeTheme,
globalLimits, globalLimits,
}); });
const lock = await redlock.lock(`locks:${htmlName}`, 3000); //what is a reasonable ttl? const lock = await redlock.lock(`locks:${htmlName}`, lockWait);
const htmlPromise = outputFile(`${uploadDirectory}/html/${htmlName}`, html); const htmlPromise = outputFile(`${uploadDirectory}/html/${htmlName}`, html);
let jsonPromise; let jsonPromise;
if (json !== null) { if (json !== null) {

@ -15,7 +15,7 @@ module.exports = {
buildBanners: async (options) => { buildBanners: async (options) => {
const label = `/${options.board._id}/banners.html`; const label = `/${options.board._id}/banners.html`;
const start = process.hrtime(); const start = process.hrtime();
const html = render(label, 'banners.pug', options, { const html = await render(label, 'banners.pug', options, {
'name': `/${options.board._id}/banners.json`, 'name': `/${options.board._id}/banners.json`,
'data': options.board.banners 'data': options.board.banners
}); });
@ -31,7 +31,7 @@ module.exports = {
options.board = await Boards.findOne(options.board); options.board = await Boards.findOne(options.board);
} }
const threads = await Posts.getCatalog(options.board._id); const threads = await Posts.getCatalog(options.board._id);
const html = render(label, 'catalog.pug', { const html = await render(label, 'catalog.pug', {
...options, ...options,
threads, threads,
}, { }, {
@ -53,7 +53,7 @@ module.exports = {
if (!thread) { if (!thread) {
return; //this thread may have been an OP that was deleted return; //this thread may have been an OP that was deleted
} }
const html = render(label, 'thread.pug', { const html = await render(label, 'thread.pug', {
...options, ...options,
thread, thread,
}, { }, {
@ -72,7 +72,7 @@ module.exports = {
if (!options.maxPage) { if (!options.maxPage) {
options.maxPage = Math.min(Math.ceil((await Posts.getPages(options.board._id)) / 10), Math.ceil(options.board.settings.threadLimit/10)); options.maxPage = Math.min(Math.ceil((await Posts.getPages(options.board._id)) / 10), Math.ceil(options.board.settings.threadLimit/10));
} }
const html = render(label, 'board.pug', { const html = await render(label, 'board.pug', {
...options, ...options,
threads, threads,
}, { }, {
@ -126,7 +126,7 @@ module.exports = {
const label = '/news.html'; const label = '/news.html';
const start = process.hrtime(); const start = process.hrtime();
const news = await News.find(); const news = await News.find();
const html = render('news.html', 'news.pug', { const html = await render('news.html', 'news.pug', {
news news
}); });
const end = process.hrtime(start); const end = process.hrtime(start);
@ -149,7 +149,7 @@ module.exports = {
if (!options.logs) { if (!options.logs) {
options.logs = await Modlogs.findBetweenDate(options.board, options.startDate, options.endDate); options.logs = await Modlogs.findBetweenDate(options.board, options.startDate, options.endDate);
} }
const html = render(label, 'modlog.pug', { const html = await render(label, 'modlog.pug', {
...options ...options
}); });
const end = process.hrtime(start); const end = process.hrtime(start);
@ -181,7 +181,7 @@ module.exports = {
await Modlogs.deleteOld(options.board, monthAgo); await Modlogs.deleteOld(options.board, monthAgo);
} }
} }
const html = render(label, 'modloglist.pug', { const html = await render(label, 'modloglist.pug', {
board: options.board, board: options.board,
dates dates
}); });
@ -198,7 +198,7 @@ module.exports = {
Boards.boardSort(0, 20), //top 20 boards sorted by users, pph, total posts Boards.boardSort(0, 20), //top 20 boards sorted by users, pph, total posts
Files.activeContent() //size ans number of files Files.activeContent() //size ans number of files
]); ]);
const html = render('index.html', 'home.pug', { const html = await render('index.html', 'home.pug', {
totalStats, totalStats,
boards, boards,
fileStats, fileStats,

Loading…
Cancel
Save