From 2d40c71a35dfdf5cbd5d697b475dfc1cd18e8d08 Mon Sep 17 00:00:00 2001 From: alice-blue Date: Wed, 4 Dec 2024 14:06:15 -0500 Subject: [PATCH 01/25] newitems.php: use doSearch for getting new games --- www/newitems.php | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/www/newitems.php b/www/newitems.php index 78c9ff23..a60c8909 100644 --- a/www/newitems.php +++ b/www/newitems.php @@ -1,5 +1,7 @@ date_sub(now(), interval $days day)"; + $limit_clause = "limit 0, $games_limit"; + $browse = 0; // query the recent games - $result = mysql_query( - "select id, title, author, `desc`, created as d, - date_format(created, '%M %e, %Y') as fmtdate, - system, pagevsn, - (coverart is not null) as hasart - from games - where $dayWhere - order by created desc - limit $games_limit", $db); - $gamecnt = mysql_num_rows($result); - for ($i = 0 ; $i < $gamecnt ; $i++) { - $row = mysql_fetch_array($result, MYSQL_ASSOC); - $items[] = array('G', $row['d'], $row); + list($rows, $rowcnt, $sortList, $errMsg, $summaryDesc, $badges, + $specials, $specialsUsed, $orderBy) = + doSearch($db, $term, $searchType, $sortby, $limit_clause, $browse); + foreach ($rows as $row) { + $items[] = array('G', $row['createdate'], $row); } } From eb97d6bce009e0610c9afe95be79b7c05d77c50e Mon Sep 17 00:00:00 2001 From: alice-blue Date: Wed, 4 Dec 2024 14:07:32 -0500 Subject: [PATCH 02/25] searchutil.php: select createdate for game listings so we can use it to sort new items on the front page --- www/searchutil.php | 1 + 1 file changed, 1 insertion(+) diff --git a/www/searchutil.php b/www/searchutil.php index b8c31ad0..87bad066 100644 --- a/www/searchutil.php +++ b/www/searchutil.php @@ -259,6 +259,7 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse) games.author as author, games.desc as description, games.tags as tags, + games.created as createdate, games.moddate as moddate, games.system as devsys, if (time(games.published) = '00:00:00', From c5fcdb9d8f6b2775253bcb8b2ca920317ccafa23 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Fri, 17 Jan 2025 17:22:25 -0800 Subject: [PATCH 03/25] `#ratings:` search should use `numRatingsInAvg` not `numRatingsTotal` `numRatingsInAvg` is what we display in search results. Querying a different number from what we display made the search results look wrong. Fixes #1252 --- www/searchutil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/searchutil.php b/www/searchutil.php index 494d393e..7cdfe8a3 100644 --- a/www/searchutil.php +++ b/www/searchutil.php @@ -234,7 +234,7 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse) "rating:" => array("avgRating", 1, true), "#reviews:" => array("numMemberReviews",1, true), "ratingdev:" => array("stdDevRating", 1, true), - "#ratings:" => array("numRatingsTotal", 1, true), + "#ratings:" => array("numRatingsInAvg", 1, true), "forgiveness:" => array("forgiveness", 0), "language:" => array("language", 99), "author:" => array("author", 99), From c050f71e682ae311ce41e7d410996c3a59d0a439 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Fri, 17 Jan 2025 17:43:04 -0800 Subject: [PATCH 04/25] Search results call it `devsys` instead of `system` --- www/components/games.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/components/games.php b/www/components/games.php index 05c73cf4..fd3d1ae2 100644 --- a/www/components/games.php +++ b/www/components/games.php @@ -69,7 +69,7 @@ . ", by " . htmlspecialcharx($g['author']); - if ($g['system']) echo "
{$g['system']}
"; + if ($g['devsys']) echo "
{$g['devsys']}
"; echo ""; } From a7d6d0e5f734326a77e189020c2b5826cf21ceb8 Mon Sep 17 00:00:00 2001 From: alice-blue Date: Fri, 17 Jan 2025 22:08:47 -0500 Subject: [PATCH 05/25] newitems.php: remove unnecessary 0 in limit clause --- www/newitems.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/newitems.php b/www/newitems.php index a60c8909..f8031cb1 100644 --- a/www/newitems.php +++ b/www/newitems.php @@ -89,7 +89,7 @@ function getNewItems($db, $limit, $itemTypes = NEWITEMS_ALLITEMS, $options = []) $searchType = "game"; $sortby = "lnew"; $games_limit = $options['games_limit'] ?? $limit; - $limit_clause = "limit 0, $games_limit"; + $limit_clause = "limit $games_limit"; $browse = 0; // query the recent games list($rows, $rowcnt, $sortList, $errMsg, $summaryDesc, $badges, From 157bf5f1b593b6d8c38b554622b9632a12ceeef3 Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 01:31:31 +0000 Subject: [PATCH 06/25] searchutil.php: Add $count_all_possible_rows parameter to doSearch --- www/searchutil.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/www/searchutil.php b/www/searchutil.php index 40d30122..e1849a43 100644 --- a/www/searchutil.php +++ b/www/searchutil.php @@ -57,7 +57,7 @@ function writeGamesFilteredAnnouncement($page, $sort_order, $search_term) { } -function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_game_filter = 0) +function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_possible_rows = false, $override_game_filter = 0) { // we need the current user for some types of queries checkPersistentLogin(); @@ -1155,6 +1155,14 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_g // But when browsing for all games, we can do a fast `count(*)` query instead $sql_calc_found_rows = ""; } + if (!$count_all_possible_rows) { + // `sql_calc_found_rows` forces the query to ignore the `limit` clause + // in order to count all possible results, which means a slower full + // table scan. If the total number of rows is not needed, we can skip + // `sql_calc_found_rows` to speed up the query. + $sql_calc_found_rows = ""; + } + // build the SELECT statement $sql = "select $sql_calc_found_rows From 310ebac9bae9c7cd1304d77f68817d4f1b83ba26 Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 01:33:07 +0000 Subject: [PATCH 07/25] ifdb-recommends.php: Use $count_all_possible_rows parameter in call to doSearch --- www/components/ifdb-recommends.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/components/ifdb-recommends.php b/www/components/ifdb-recommends.php index 5ca3208c..3f0f3220 100644 --- a/www/components/ifdb-recommends.php +++ b/www/components/ifdb-recommends.php @@ -21,13 +21,14 @@ function sortBySortorder($a, $b) $maxpicks = 12; // Get the first twelve results. (We want extras so we're not always displaying the same games.) $limit = "limit 0, $maxpicks"; $browse = 0; +$count_all_possible_rows = false; $override_game_filter = 0; // run the search for highly-rated games list($recs, $rowcnt, $sortList, $errMsg, $summaryDesc, $badges, $specials, $specialsUsed, $orderBy, $games_were_filtered) = - doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_game_filter); + doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_possible_rows, $override_game_filter); // show some recommendations From be1f66707246915135d07895b5a58122f0b820a1 Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 01:34:03 +0000 Subject: [PATCH 08/25] review: Use $count_all_possible_rows parameter and $override_game_filter in call to doSearch --- www/review | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/www/review b/www/review index 08bb480b..38e8577c 100644 --- a/www/review +++ b/www/review @@ -142,8 +142,10 @@ if (isset($_REQUEST['browse'])) if ($searchFor) { // run the search + $count_all_possible_rows = false; + $override_game_filter = 0; list($rows, $rowcnt, $sortList, $errMsg) = - doSearch($db, $searchFor, "game", "rel", "limit 0, 10", false); + doSearch($db, $searchFor, "game", "rel", "limit 0, 10", false, $count_all_possible_rows, $override_game_filter); // show the results $term = htmlspecialcharx($searchFor); From 0954a8b7b43e39eae60502c3f103f887970b2d7b Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 01:35:56 +0000 Subject: [PATCH 09/25] search: Use $count_all_possible_rows parameter in call to doSearch --- www/search | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/www/search b/www/search index 35abcd21..989db93b 100644 --- a/www/search +++ b/www/search @@ -292,11 +292,16 @@ if ($pg == 'all') { // if we have a search term, find it if ($term || $browse) { + + // We want a count of all possible results, regardless of + // limit clause, so we can display that number + $count_all_possible_rows = true; // run the search list($rows, $rowcnt, $sortList, $errMsg, $summaryDesc, $badges, $specials, $specialsUsed, $orderBy, $games_were_filtered) = - doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_game_filter); + doSearch($db, $term, $searchType, $sortby, $limit, $browse, + $count_all_possible_rows, $override_game_filter); // adjust our page limits to include the whole result set if desired if ($pgAll) { From db7086acfa397d94a68a48789cd5d19c53384f86 Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 01:37:30 +0000 Subject: [PATCH 10/25] editgame: Use $count_all_possible_rows and $override_game_filter parameters in call to doSearch --- www/editgame | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/www/editgame b/www/editgame index d4f1d60f..625b035b 100644 --- a/www/editgame +++ b/www/editgame @@ -65,8 +65,11 @@ if (isset($_REQUEST['search'])) if ($searchFor) { // run the search + $count_all_possible_rows = false; + $override_game_filter = 0; list($rows, $rowcnt, $sortList, $errMsg) = - doSearch($db, $searchFor, "game", "rel", "limit 0, 10", false); + doSearch($db, $searchFor, "game", "rel", "limit 0, 10", false, + $count_all_possible_rows, $override_game_filter); // if the top result matches the title exactly, consider it a // one-row match, even if we found other less relevant titles From 9bc40d4a5e7cb3b7235e1ba9ce49fcfe548e61fb Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 03:31:15 +0000 Subject: [PATCH 11/25] length($rows) --> count($rows) (to get rid of fatal error) --- www/searchutil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/searchutil.php b/www/searchutil.php index e1849a43..af094447 100644 --- a/www/searchutil.php +++ b/www/searchutil.php @@ -1215,7 +1215,7 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_ $result = mysql_query("select count(*) from games", $db); [$rowcnt] = mysql_fetch_row($result); } else { - $rowcnt = length($rows); + $rowcnt = count($rows); } } else { From d016bac510324e2e4d0de6d3cbe1dbd03503a645 Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 16:17:41 -0500 Subject: [PATCH 12/25] searchutil.php: check for $term rather than a where clause to see if we're searching or browsing --- www/searchutil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/searchutil.php b/www/searchutil.php index b54d6351..d55c6a09 100644 --- a/www/searchutil.php +++ b/www/searchutil.php @@ -1113,7 +1113,7 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse) } $sql_calc_found_rows = "sql_calc_found_rows"; - if ($searchType === "game" && $where === "1") { + if ($searchType === "game" && !$term) { // `sql_calc_found_rows` forces the query to ignore the `limit` clause in order to count all possible results. // But when browsing for all games, we can do a fast `count(*)` query instead $sql_calc_found_rows = ""; From 96bb618d58206de46518f6ab1536f4c5ef150748 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Sun, 19 Jan 2025 14:14:09 -0800 Subject: [PATCH 13/25] Correctly exclude sandboxed ratings from `gameRatingsSandbox0` Prior to #1256, we were excluding special reviews, embargoed reviews, and sandboxed reviews with a `where` clause, but this meant that some games were missing from `gameRatingsSandbox0`, when all of a game's reviews were special reviews. In #1256, I removed the `where` clause and turned them into criteria on the `join` clauses. This worked fine for special reviews and embargoed reviews, but it didn't work for sandboxed reviews. We did a left join to the `users` table, excluding sandboxed users there, but we didn't use the results of that join. We never used `users.userid` for anything, and we never excluded any sandboxed reviews in the criteria for the `reviews` table. I've removed the join to `users` and replaced it with another criterion on the join to the `reviews` table, excluding reviews where the `userid` is sandboxed. I've confirmed that this still excludes special and embargoed reviews, and now it excludes sandboxed reviews, too. Also, I've confirmed that the number of rows matches the number of rows in the games table, so every game has a matching row in `gameRatingsSandbox0`. Fixes #1263 --- sql/unscrub-ifarchive.sql | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/sql/unscrub-ifarchive.sql b/sql/unscrub-ifarchive.sql index 3e85cbfc..2fe363e8 100644 --- a/sql/unscrub-ifarchive.sql +++ b/sql/unscrub-ifarchive.sql @@ -436,10 +436,7 @@ from ( 1 ) and `ifdb`.`reviews`.`special` is null - ) - left outer join `ifdb`.`users` on ( - `ifdb`.`reviews`.`userid` = `ifdb`.`users`.`id` - and ifnull(`ifdb`.`users`.`Sandbox`, 0) = 0 + and `ifdb`.`reviews`.`userid` not in (select `ifdb`.`users`.`id` from `ifdb`.`users` where `ifdb`.`users`.`Sandbox` = 1) ) ) group by `ifdb`.`reviews`.`rating`, @@ -608,9 +605,6 @@ from ( ) and `ifdb`.`reviews`.`special` is null ) - left outer join `ifdb`.`users` on ( - `ifdb`.`reviews`.`userid` = `ifdb`.`users`.`id` - ) ) group by `ifdb`.`reviews`.`rating`, `ifdb`.`games`.`id`, From 801f98532e31646a698e4f318e1d9e702c75987f Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Sun, 19 Jan 2025 14:30:05 -0800 Subject: [PATCH 14/25] searchutil.php: Fixed one more spot where we're checking `$where` --- www/searchutil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/searchutil.php b/www/searchutil.php index d55c6a09..6a7c2a6f 100644 --- a/www/searchutil.php +++ b/www/searchutil.php @@ -1165,7 +1165,7 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse) if ($sql_calc_found_rows) { $result = mysql_query("select found_rows()", $db); [$rowcnt] = mysql_fetch_row($result); - } else if ($searchType === "game" && $where === "1") { + } else if ($searchType === "game" && !$term) { if ($logging_level) error_log("select count(*) from games"); $result = mysql_query("select count(*) from games", $db); [$rowcnt] = mysql_fetch_row($result); From 166f2f6a5168782614152189bcf9d27976364ea7 Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 23:27:31 +0000 Subject: [PATCH 15/25] $where --> !$term --- www/searchutil.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/www/searchutil.php b/www/searchutil.php index af094447..bb5ad371 100644 --- a/www/searchutil.php +++ b/www/searchutil.php @@ -1150,7 +1150,7 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_ } $sql_calc_found_rows = "sql_calc_found_rows"; - if ($searchType === "game" && $where === "1") { + if ($searchType === "game" && !$term) { // `sql_calc_found_rows` forces the query to ignore the `limit` clause in order to count all possible results. // But when browsing for all games, we can do a fast `count(*)` query instead $sql_calc_found_rows = ""; @@ -1210,7 +1210,7 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_ if ($sql_calc_found_rows) { $result = mysql_query("select found_rows()", $db); [$rowcnt] = mysql_fetch_row($result); - } else if ($searchType === "game" && $where === "1") { + } else if ($searchType === "game" && !$term) { if ($logging_level) error_log("select count(*) from games"); $result = mysql_query("select count(*) from games", $db); [$rowcnt] = mysql_fetch_row($result); From b571fc54936cfc79ec68d53f77815d93aea437ab Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 23:55:48 +0000 Subject: [PATCH 16/25] Combine conditions & comments --- www/searchutil.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/www/searchutil.php b/www/searchutil.php index bb5ad371..c2df5710 100644 --- a/www/searchutil.php +++ b/www/searchutil.php @@ -1150,19 +1150,16 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_ } $sql_calc_found_rows = "sql_calc_found_rows"; - if ($searchType === "game" && !$term) { - // `sql_calc_found_rows` forces the query to ignore the `limit` clause in order to count all possible results. - // But when browsing for all games, we can do a fast `count(*)` query instead - $sql_calc_found_rows = ""; - } - if (!$count_all_possible_rows) { - // `sql_calc_found_rows` forces the query to ignore the `limit` clause - // in order to count all possible results, which means a slower full - // table scan. If the total number of rows is not needed, we can skip - // `sql_calc_found_rows` to speed up the query. + if (($searchType === "game" && !$term) || !$count_all_possible_rows) { + // `sql_calc_found_rows` forces the query to ignore the `limit` clause in order to + // count all possible results, which means a full table scan, which can be slow. + // But if we're browsing all games, we can skip `sql_calc_found_rows` and do a fast + // `count(*)` query instead. If we're searching but we don't need the number of + // possible rows, we can skip the counting altogether. + $sql_calc_found_rows = ""; } - + // build the SELECT statement $sql = "select $sql_calc_found_rows From 8f0985769c0356fa10e7824a613c417d47fe0676 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Sun, 19 Jan 2025 20:34:36 -0800 Subject: [PATCH 17/25] search: Add a comment explaining the warning banner for buried games --- www/search | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/www/search b/www/search index 9a00d19e..ad2b21fb 100644 --- a/www/search +++ b/www/search @@ -1268,6 +1268,13 @@ else if ($term || $browse) $showFlagged = isset($_GET['showFlagged']) && $_GET['showFlagged']; if (!$showFlagged && $searchType == "game" && (!$browse || $pg != 1)) { + // This is for the "buried game" feature, where we restrict links to a game when we detect widespread voter manipulation ("brigading") + // These games are hidden by default in search results, with a warning banner, "Some results were hidden. Click here to see all results". + + // Note that we don't show this warning banner on the first page of "Browse Games". + // The goal of the "bury game" feature is to silently not recommend games, but having the banner at the top of the first page + // of the "Browse Games" page draws too much attention to the banner and to buried games. + for ($i = 0 ; $i < count($rows) ; $i++) { $row = $rows[$i]; $flags = $row['flags']; From cb16a727530c549907470fa40c4dfa2eeaec4c77 Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 01:31:31 +0000 Subject: [PATCH 18/25] searchutil.php: Add $count_all_possible_rows parameter to doSearch --- www/searchutil.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/www/searchutil.php b/www/searchutil.php index f1f08040..56b105c9 100644 --- a/www/searchutil.php +++ b/www/searchutil.php @@ -43,7 +43,7 @@ function convertTimeStringToMinutes($h_m_string) { } -function doSearch($db, $term, $searchType, $sortby, $limit, $browse) +function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_possible_rows = false) { // we need the current user for some types of queries checkPersistentLogin(); @@ -1118,6 +1118,14 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse) // But when browsing for all games, we can do a fast `count(*)` query instead $sql_calc_found_rows = ""; } + if (!$count_all_possible_rows) { + // `sql_calc_found_rows` forces the query to ignore the `limit` clause + // in order to count all possible results, which means a slower full + // table scan. If the total number of rows is not needed, we can skip + // `sql_calc_found_rows` to speed up the query. + $sql_calc_found_rows = ""; + } + // build the SELECT statement $sql = "select $sql_calc_found_rows From 1e208ef15e3af838cb745f22e5c95ab6427aabdf Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 01:33:07 +0000 Subject: [PATCH 19/25] ifdb-recommends.php: Use $count_all_possible_rows parameter in call to doSearch --- www/components/ifdb-recommends.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/components/ifdb-recommends.php b/www/components/ifdb-recommends.php index e1f3986c..301552bc 100644 --- a/www/components/ifdb-recommends.php +++ b/www/components/ifdb-recommends.php @@ -21,12 +21,13 @@ function sortBySortorder($a, $b) $maxpicks = 12; // Get the first twelve results. (We want extras so we're not always displaying the same games.) $limit = "limit 0, $maxpicks"; $browse = 0; +$count_all_possible_rows = false; // run the search for highly-rated games list($recs, $rowcnt, $sortList, $errMsg, $summaryDesc, $badges, $specials, $specialsUsed, $orderBy) = - doSearch($db, $term, $searchType, $sortby, $limit, $browse); + doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_possible_rows); // show some recommendations From 404520bacc6448c8d68c5c7c8c44666256a75de0 Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 01:34:03 +0000 Subject: [PATCH 20/25] review: Use $count_all_possible_rows parameter in call to doSearch --- www/review | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/www/review b/www/review index 08bb480b..11a24b3c 100644 --- a/www/review +++ b/www/review @@ -142,8 +142,9 @@ if (isset($_REQUEST['browse'])) if ($searchFor) { // run the search + $count_all_possible_rows = false; list($rows, $rowcnt, $sortList, $errMsg) = - doSearch($db, $searchFor, "game", "rel", "limit 0, 10", false); + doSearch($db, $searchFor, "game", "rel", "limit 0, 10", false, $count_all_possible_rows); // show the results $term = htmlspecialcharx($searchFor); From 3a133f1a01bf66a1f02259519ea376db6a99c663 Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 01:35:56 +0000 Subject: [PATCH 21/25] search: Use $count_all_possible_rows parameter in call to doSearch --- www/search | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/www/search b/www/search index ad2b21fb..c3c97359 100644 --- a/www/search +++ b/www/search @@ -291,11 +291,16 @@ if ($pg == 'all') { // if we have a search term, find it if ($term || $browse) { + + // We want a count of all possible results, regardless of + // limit clause, so we can display that number + $count_all_possible_rows = true; // run the search list($rows, $rowcnt, $sortList, $errMsg, $summaryDesc, $badges, $specials, $specialsUsed, $orderBy) = - doSearch($db, $term, $searchType, $sortby, $limit, $browse); + doSearch($db, $term, $searchType, $sortby, $limit, $browse, + $count_all_possible_rows); // adjust our page limits to include the whole result set if desired if ($pgAll) { From f91e3af6fc762d5a03f8970d1c77948cb02eedac Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 01:37:30 +0000 Subject: [PATCH 22/25] editgame: Use $count_all_possible_rows in call to doSearch --- www/editgame | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/www/editgame b/www/editgame index d4f1d60f..a9ecf49b 100644 --- a/www/editgame +++ b/www/editgame @@ -65,8 +65,10 @@ if (isset($_REQUEST['search'])) if ($searchFor) { // run the search + $count_all_possible_rows = false; list($rows, $rowcnt, $sortList, $errMsg) = - doSearch($db, $searchFor, "game", "rel", "limit 0, 10", false); + doSearch($db, $searchFor, "game", "rel", "limit 0, 10", false, + $count_all_possible_rows); // if the top result matches the title exactly, consider it a // one-row match, even if we found other less relevant titles From 3342cf32df86ac11b3f9c247a186c563f799b3fb Mon Sep 17 00:00:00 2001 From: alice-blue Date: Sun, 19 Jan 2025 03:31:15 +0000 Subject: [PATCH 23/25] length($rows) --> count($rows) (to get rid of fatal error) --- www/searchutil.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/searchutil.php b/www/searchutil.php index 56b105c9..c3401c1f 100644 --- a/www/searchutil.php +++ b/www/searchutil.php @@ -1178,7 +1178,7 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_ $result = mysql_query("select count(*) from games", $db); [$rowcnt] = mysql_fetch_row($result); } else { - $rowcnt = length($rows); + $rowcnt = count($rows); } } else { From ea646748be908f176b8c9acb09c69ae578b71f64 Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Wed, 22 Jan 2025 10:38:18 -0800 Subject: [PATCH 24/25] Improve logged-out IFDB Recommends search performance This commit sets `$browse = 1`, which makes `searchutil.php` do an inner join to `gameRatingsSandbox0_mv`, allowing the query planner to grab the top N listings from the `starsort` index. --- www/components/ifdb-recommends.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/www/components/ifdb-recommends.php b/www/components/ifdb-recommends.php index 301552bc..bf24c96b 100644 --- a/www/components/ifdb-recommends.php +++ b/www/components/ifdb-recommends.php @@ -20,7 +20,7 @@ function sortBySortorder($a, $b) $sortby = "ratu"; // Sort the highly rated games to the top of the results. $maxpicks = 12; // Get the first twelve results. (We want extras so we're not always displaying the same games.) $limit = "limit 0, $maxpicks"; -$browse = 0; +$browse = 1; $count_all_possible_rows = false; From 27f50d326a9e46dd29c3b1d824a22274e54f69ec Mon Sep 17 00:00:00 2001 From: Dan Fabulich Date: Wed, 22 Jan 2025 11:15:30 -0800 Subject: [PATCH 25/25] Improve logged-in IFDB Recommends search performance The query planner couldn't figure out how to handle joins with complex `on` filters, so I replaced them with `where gameid in` clauses for `played:` `willplay:` `wontplay:` `reviewed:` and `rated:` queries. --- www/searchutil.php | 63 ++++++++-------------------------------------- 1 file changed, 11 insertions(+), 52 deletions(-) diff --git a/www/searchutil.php b/www/searchutil.php index c3401c1f..d0fa3e24 100644 --- a/www/searchutil.php +++ b/www/searchutil.php @@ -653,17 +653,9 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_ if (!$curuser) { break; } - // need to join the playedgames table to do this query - if (!isset($extraJoins[$col])) { - $extraJoins[$col] = true; - $tableList .= " left join playedgames as pg " - . "on games.id = pg.gameid " - . "and pg.userid = '$curuser'"; - } - // we need yes=not-null/no=null game ids - $op = (preg_match("/^y.*/i", $txt) ? "is not" : "is"); - $expr = "pg.gameid $op null"; + $not = (preg_match("/^y.*/i", $txt) ? "" : "not"); + $expr = "gameid $not in (select gameid from playedgames where userid = '$curuser')"; break; case 'willplay': @@ -671,17 +663,9 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_ if (!$curuser) { break; } - // need to join the wishlists table to do this query - if (!isset($extraJoins[$col])) { - $extraJoins[$col] = true; - $tableList .= " left join wishlists as wl " - . "on games.id = wl.gameid " - . "and wl.userid = '$curuser'"; - } - // we need yes=not-null/no=null game ids - $op = (preg_match("/^y.*/i", $txt) ? "is not" : "is"); - $expr = "wl.gameid $op null"; + $not = (preg_match("/^y.*/i", $txt) ? "" : "not"); + $expr = "gameid $not in (select gameid from wishlists where userid = '$curuser')"; break; case 'wontplay': @@ -689,36 +673,20 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_ if (!$curuser) { break; } - // need to join the unwishlists table to do this query - if (!isset($extraJoins[$col])) { - $extraJoins[$col] = true; - $tableList .= " left join unwishlists as ul " - . "on games.id = ul.gameid " - . "and ul.userid = '$curuser'"; - } - // we need yes=not-null/no=null game ids - $op = (preg_match("/^y.*/i", $txt) ? "is not" : "is"); - $expr = "ul.gameid $op null"; + $not = (preg_match("/^y.*/i", $txt) ? "" : "not"); + $expr = "gameid $not in (select gameid from unwishlists where userid = '$curuser')"; break; + case 'reviewed': // Only use this query when the user is logged in if (!$curuser) { break; } - // need to join the reviews table to do this query - if (!isset($extraJoins[$col])) { - $extraJoins[$col] = true; - $tableList .= " left join reviews as reviewed " - . "on games.id = reviewed.gameid " - . "and reviewed.review is not null " - . "and reviewed.userid = '$curuser'"; - } - // we need yes=not-null/no=null game ids - $op = (preg_match("/^y.*/i", $txt) ? "is not" : "is"); - $expr = "reviewed.gameid $op null"; + $not = (preg_match("/^y.*/i", $txt) ? "" : "not"); + $expr = "gameid $not in (select gameid from reviews where review is not null and userid = '$curuser')"; break; case 'rated': @@ -726,18 +694,9 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_ if (!$curuser) { break; } - // need to join the reviews table to do this query - if (!isset($extraJoins[$col])) { - $extraJoins[$col] = true; - $tableList .= " left join reviews as rated " - . "on games.id = rated.gameid " - . "and rated.rating is not null " - . "and rated.userid = '$curuser'"; - } - // we need yes=not-null/no=null game ids - $op = (preg_match("/^y.*/i", $txt) ? "is not" : "is"); - $expr = "rated.gameid $op null"; + $not = (preg_match("/^y.*/i", $txt) ? "" : "not"); + $expr = "gameid $not in (select gameid from reviews where rating is not null and userid = '$curuser')"; break; case 'author':