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,
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: {
siteName: 'imageboard',
url: 'https://domain.com'
},
//cache templates in memory
//cache templates in memory. disable only if editing templates and doing dev work
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
pruneModlogs: true,
@ -44,7 +47,7 @@ module.exports = {
//extension for thumbnails. png is larger but allows transparency
thumbExtension: '.png',
//max thumb dimensions
//max thumb dimensions (square) in px
thumbSize: 200,
//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
highlightOptions: {
//subset of languages to allow
//subset of languages to allow.
languageSubset: [
'javascript',
'js',

@ -1,6 +1,6 @@
'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')
, pug = require('pug')
, path = require('path')
@ -17,7 +17,7 @@ module.exports = async (htmlName, templateName, options, json=null) => {
defaultCodeTheme: boardDefaults.codeTheme,
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);
let jsonPromise;
if (json !== null) {

@ -15,7 +15,7 @@ module.exports = {
buildBanners: async (options) => {
const label = `/${options.board._id}/banners.html`;
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`,
'data': options.board.banners
});
@ -31,7 +31,7 @@ module.exports = {
options.board = await Boards.findOne(options.board);
}
const threads = await Posts.getCatalog(options.board._id);
const html = render(label, 'catalog.pug', {
const html = await render(label, 'catalog.pug', {
...options,
threads,
}, {
@ -53,7 +53,7 @@ module.exports = {
if (!thread) {
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,
thread,
}, {
@ -72,7 +72,7 @@ module.exports = {
if (!options.maxPage) {
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,
threads,
}, {
@ -126,7 +126,7 @@ module.exports = {
const label = '/news.html';
const start = process.hrtime();
const news = await News.find();
const html = render('news.html', 'news.pug', {
const html = await render('news.html', 'news.pug', {
news
});
const end = process.hrtime(start);
@ -149,7 +149,7 @@ module.exports = {
if (!options.logs) {
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
});
const end = process.hrtime(start);
@ -181,7 +181,7 @@ module.exports = {
await Modlogs.deleteOld(options.board, monthAgo);
}
}
const html = render(label, 'modloglist.pug', {
const html = await render(label, 'modloglist.pug', {
board: options.board,
dates
});
@ -198,7 +198,7 @@ module.exports = {
Boards.boardSort(0, 20), //top 20 boards sorted by users, pph, total posts
Files.activeContent() //size ans number of files
]);
const html = render('index.html', 'home.pug', {
const html = await render('index.html', 'home.pug', {
totalStats,
boards,
fileStats,

Loading…
Cancel
Save