From 2b5365b572f1ecf5627ff6916f417660b958b205 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Wed, 30 Mar 2022 23:59:21 +0000 Subject: [PATCH] use more cache. Speeds up page builds (#72) use more cache. Speeds up page builds. Tested as much as reasonably possible. Works well. cuts self delete from ~8 seconds to ~1 second. and mod delete from 10-14 seconds to ~4 seconds. Co-authored-by: nonmakina Co-committed-by: nonmakina --- inc/functions.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/inc/functions.php b/inc/functions.php index ab43210b..1ff9768a 100644 --- a/inc/functions.php +++ b/inc/functions.php @@ -1690,6 +1690,21 @@ function buildIndex($global_api = "yes") { if (!$content) break; + // Tries to avoid rebuilding if the body is the same as the one in cache. + if ($config['cache']['enabled']) { + $contentHash = md5(json_encode($content['body'])); + $contentHashKey = '_index_hashed_'. $board['uri'] . '_' . $page; + $cachedHash = cache::get($contentHashKey); + if ($cachedHash == $contentHash){ + if ($config['api']['enabled']) { + // this is needed for the thread.json and catalog.json rebuilding below, which includes all pages. + $catalog[$page-1] = $content['threads']; + } + continue; + } + cache::set($contentHashKey, $contentHash, 3600); + } + // json api if ($config['api']['enabled']) { $threads = $content['threads'];