From a3e2af403b68cf3bbcf0abb49de5a89657962943 Mon Sep 17 00:00:00 2001 From: nonmakina Date: Sun, 10 Jan 2021 22:18:32 -0600 Subject: [PATCH] Adds limit to overboard catalog --- templates/themes/catalog/info.php | 7 +++++++ templates/themes/catalog/theme.php | 11 +++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/templates/themes/catalog/info.php b/templates/themes/catalog/info.php index 98b68600..67999c88 100644 --- a/templates/themes/catalog/info.php +++ b/templates/themes/catalog/info.php @@ -97,6 +97,13 @@ 'default' => 'overboard', 'comment' => 'Fill in the location of the overboard directory. Default is \'overboard\' which corresponds to ./overboard' ); + $theme['config'][] = Array( + 'title' => 'Max posts in catalog overboard', + 'name' => 'overboard_limit', + 'type' => 'text', + 'default' => '350', + 'comment' => 'The maximum number of thread that will appear in the overboard catalog' + ); // Unique function name for building everything $theme['build_function'] = 'catalog_build'; diff --git a/templates/themes/catalog/theme.php b/templates/themes/catalog/theme.php index 269e237f..9948738f 100644 --- a/templates/themes/catalog/theme.php +++ b/templates/themes/catalog/theme.php @@ -357,12 +357,15 @@ } else { $sql = ''; foreach ($boards as $board) { - $sql .= $this->buildThreadsQuery($board); + $sql .= '('. $this->buildThreadsQuery($board) . ')'; $sql .= " UNION ALL "; } - $sql = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC', $sql); - $result = query($sql) or error(db_error()); - $threads = $result->fetchAll(PDO::FETCH_ASSOC); + $sql = preg_replace('/UNION ALL $/', 'ORDER BY `bump` DESC LIMIT :limit', $sql); + $query = prepare($sql); + $query->bindValue(':limit', $settings['overboard_limit'], PDO::PARAM_INT); + $query->execute() or error(db_error($query)); + + $threads = $query->fetchAll(PDO::FETCH_ASSOC); // Save for posterity $this->threadsCache[$board_name] = $threads; }