nicer timer logs for page build times

merge-requests/208/head
fatchan 5 years ago
parent 87f59ed051
commit 64620e847a
  1. 40
      helpers/build.js

@ -12,57 +12,67 @@ const Mongo = require(__dirname+'/../db/db.js')
module.exports = {
buildBanners: async(board) => {
console.log('building banners', `${board._id}/banners.html`);
return render(`${board._id}/banners.html`, 'banners.pug', {
const buildName = `Building: ${board._id}/banners.html`;
console.time(buildName);
await render(`${board._id}/banners.html`, 'banners.pug', {
board: board,
});
console.timeEnd(buildName);
},
buildCatalog: async (board) => {
console.log('building catalog', `${board._id}/catalog.html`);
const buildName = `Building: ${board._id}/catalog.html`;
console.time(buildName);
if (!board._id) {
board = await Boards.findOne(board);
}
const threads = await Posts.getCatalog(board._id);
return render(`${board._id}/catalog.html`, 'catalog.pug', {
await render(`${board._id}/catalog.html`, 'catalog.pug', {
board,
threads,
});
console.timeEnd(buildName);
},
buildThread: async (threadId, board) => {
console.log('building thread', `${board._id || board}/thread/${threadId}.html`);
const buildName = `Building: ${board._id || board}/thread/${threadId}.html`;
console.time(buildName);
if (!board._id) {
board = await Boards.findOne(board);
}
const thread = await Posts.getThread(board._id, threadId)
if (!thread) {
console.timeEnd(buildName, 'deleted OP')
return; //this thread may have been an OP that was deleted
}
return render(`${board._id}/thread/${threadId}.html`, 'thread.pug', {
await render(`${board._id}/thread/${threadId}.html`, 'thread.pug', {
board,
thread,
});
console.timeEnd(buildName);
},
buildBoard: async (board, page, maxPage=null) => {
console.log('building board page', `${board._id}/${page === 1 ? 'index' : page}.html`);
const buildName = `Building: ${board._id || board}/${page === 1 ? 'index' : page}.html`;
console.time(buildName);
const threads = await Posts.getRecent(board._id, page);
if (maxPage == null) {
maxPage = Math.min(Math.ceil((await Posts.getPages(board._id)) / 10), Math.ceil(board.settings.threadLimit/10));
}
return render(`${board._id}/${page === 1 ? 'index' : page}.html`, 'board.pug', {
await render(`${board._id}/${page === 1 ? 'index' : page}.html`, 'board.pug', {
board,
threads,
maxPage,
page,
});
console.timeEnd(buildName);
},
//building multiple pages (for rebuilds)
buildBoardMultiple: async (board, startpage=1, endpage) => {
const buildName = 'multi page build';
console.time(buildName);
const maxPage = Math.min(Math.ceil((await Posts.getPages(board._id)) / 10), Math.ceil(board.settings.threadLimit/10));
if (endpage === 0) {
//deleted only/all posts, so only 1 page will remain
@ -73,9 +83,8 @@ console.log('building board page', `${board._id}/${page === 1 ? 'index' : page}.
}
const difference = endpage-startpage + 1; //+1 because for single pagemust be > 0
const threads = await Posts.getRecent(board._id, startpage, difference*10);
console.timeLog(buildName, `${board._id}/ ${startpage === 1 ? 'index' : startpage} -> ${endpage === 1 ? 'index' : endpage} .html`);
const buildArray = [];
console.log('multi building board pages', `${board._id}/ ${startpage === 1 ? 'index' : startpage} -> ${endpage === 1 ? 'index' : endpage} .html`);
for (let i = startpage; i <= endpage; i++) {
let spliceStart = (i-1)*10;
if (spliceStart > 0) {
@ -90,11 +99,13 @@ console.log('multi building board pages', `${board._id}/ ${startpage === 1 ? 'in
})
);
}
return Promise.all(buildArray);
await Promise.all(buildArray);
console.timeEnd(buildName);
},
buildHomepage: async () => {
console.log('building homepage /index.html');
const buildName = `Building: index.html`;
console.time(buildName);
//getting boards
const boards = await Boards.find();
//geting PPH for each board
@ -142,10 +153,11 @@ console.log('building homepage /index.html');
totalSizeString: formatSize(stats.size)
}
});
return render('index.html', 'home.pug', {
await render('index.html', 'home.pug', {
boards,
fileStats,
});
console.timeEnd(buildName);
},
buildChangePassword: () => {

Loading…
Cancel
Save