From c4a0c1a56e268ac82dc678832d7cbf99e3ca9f49 Mon Sep 17 00:00:00 2001 From: l29utp0 <23908-l29utp0@users.noreply.gitgud.io> Date: Thu, 14 Apr 2022 12:01:48 +0000 Subject: [PATCH] add hotThreads function from ptchina, needs some more work --- lib/build/tasks.js | 117 ++++++++++++++++++++++++++++++++++++++++++- views/pages/home.pug | 15 ++++++ 2 files changed, 131 insertions(+), 1 deletion(-) diff --git a/lib/build/tasks.js b/lib/build/tasks.js index 6d991e26..25361e12 100644 --- a/lib/build/tasks.js +++ b/lib/build/tasks.js @@ -246,11 +246,126 @@ module.exports = { const { maxRecentNews } = config.get; const label = '/index.html'; const start = process.hrtime(); - let [ totalStats, boards, fileStats, recentNews ] = await Promise.all([ + let [ totalStats, boards, fileStats, recentNews, hotThreads ] = await Promise.all([ Boards.totalStats(), //overall total posts ever made Boards.boardSort(0, 20), //top 20 boards sorted by users, pph, total posts Files.activeContent(), //size and number of files News.find(maxRecentNews), //some recent newsposts + Posts.db.find({'board': {$in: listedBoards}, 'thread': null, 'date': {$gte: (new Date(Date.now() - (7 * 24 * 60 * 60 * 1000)))}}).sort({'replyposts':-1}).limit(5).toArray(), //top 5 threads last 7 days + ]); + const [ localStats, webringStats ] = totalStats; + const { html } = await render('index.html', 'home.pug', { + localStats, + webringStats, + boards, + fileStats, + recentNews, + hotThreads, + }); + const end = process.hrtime(start); + debugLogs && console.log(timeDiffString(label, end)); + return html; + }, + + updateStats: async () => { + const label = 'Hourly stats rollover'; + const start = process.hrtime(); + await Stats.updateBoards(); + await Stats.resetStats(); + buildQueue.push({ + 'task': 'buildHomepage', + }); + const end = process.hrtime(start); + debugLogs && console.log(timeDiffString(label, end)); + module.exports.resetTriggers(); + }, + + resetTriggers: async() => { + const label = 'Resetting pph/tph triggers'; + const start = process.hrtime(); + const triggeredBoards = await cache.sgetall('triggered'); //boards triggered pph/tph mode + if (triggeredBoards.length === 0) { + return; //no label is no triggers + } + await cache.del('triggered'); + const triggerModes = await Boards.triggerModes(triggeredBoards); + const bulkWrites = triggerModes.map(p => { + return { + 'updateOne': { + 'filter': { + '_id': p._id + }, + 'update': { + '$set': { + /* reset=0 is "no change", the options go from 0-2, and get reset to 0 or 1, + so if >0, we subtract 1 otherwise no change */ + 'settings.lockMode': (p.lockReset > 0 ? Math.min(p.lockReset-1, p.lockMode) : p.lockMode), + 'settings.captchaMode': (p.captchaReset > 0 ? Math.min(p.captchaReset-1, p.captchaMode) : p.captchaMode), + } + } + } + } + }); + await Boards.db.bulkWrite(bulkWrites); + const promises = []; + triggerModes.forEach(async (p) => { + await cache.del(`board:${p._id}`); + if (p.captchaReset > 0 && p.captchaReset-1 < p.captchaMode) { + if (p.captchaReset-1 <= 1) { + promises.push(remove(`${uploadDirectory}/html/${p._id}/thread/`)); + } + if (p.captchaReset-1 === 0) { + buildQueue.push({ + 'task': 'buildBoardMultiple', + 'options': { + 'board': p._id, + 'startpage': 1, + 'endpage': Math.ceil(p.threadLimit/10) + } + }) + buildQueue.push({ + 'task': 'buildCatalog', + 'options': { + 'board': p._id + } + }); + } + } + }) + await Promise.all(promises); + const end = process.hrtime(start); + debugLogs && console.log(timeDiffString(label, end)); + }, + + buildChangePassword: async () => { + const { html } = await render('changepassword.html', 'changepassword.pug'); + return html; + }, + + buildRegister: async () => { + const { html } = await render('register.html', 'register.pug'); + return html; + }, + + buildBypass: async (minimal=false) => { + const { html } = await render(`bypass${minimal ? '_minimal' : ''}.html`, 'bypass.pug', { + minimal, + }); + return html; + }, + + buildCreate: async () => { + const { html } = await render('create.html', 'create.pug'); + return html; + }, + + buildCaptcha: async() => { + const { html } = await render('captcha.html', 'captcha.pug'); + return html; + }, + +} + ]); const [ localStats, webringStats ] = totalStats; const { html } = await render('index.html', 'home.pug', { diff --git a/views/pages/home.pug b/views/pages/home.pug index 1a36283f..d00d706f 100644 --- a/views/pages/home.pug +++ b/views/pages/home.pug @@ -28,7 +28,22 @@ block content td - const newsDate = new Date(post.date); time.right.reltime(datetime=newsDate.toISOString()) #{newsDate.toLocaleString(undefined, {hourCycle:'h23'})} + if hotThreads && hotThreads.length > 0 + .table-container.flex-center.mv-5 + table.posttable + tr(colspan=3) + each post in hotThreads + tr + td 🔥#{post.replyposts + post.replyfiles} + td + if post.nomarkup != null + a.quote(href=`/${post.board}/thread/${post.postId}.html#${post.postId}`) #{`${post.subject.substring(0,30)}${post.subject && post.subject.length > 30 ? '...' : ''} ${post.nomarkup && post.nomarkup.substring(0,50)}${post.nomarkup && post.nomarkup.length > 50 ? '...' : ''}`} + if post.nomarkup === null + a.quote(href=`/${post.board}/thread/${post.postId}.html#${post.postId}`) (No comment.) + td + - const newsDate = new Date(post.bumped); + time.right.reltime(datetime=newsDate.toISOString()) #{newsDate.toLocaleString(undefined, {hourCycle:'h23'})} if boards && boards.length > 0 +boardtable(true, false) each board in boards