diff --git a/sql/unscrub-ifarchive.sql b/sql/unscrub-ifarchive.sql index 9dc6b5fa..7aaf9abb 100644 --- a/sql/unscrub-ifarchive.sql +++ b/sql/unscrub-ifarchive.sql @@ -445,10 +445,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`, @@ -617,9 +614,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`, diff --git a/www/components/games.php b/www/components/games.php index 711f88b1..330f85ce 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 ""; } diff --git a/www/components/ifdb-recommends.php b/www/components/ifdb-recommends.php index 5ca3208c..e44991a6 100644 --- a/www/components/ifdb-recommends.php +++ b/www/components/ifdb-recommends.php @@ -20,14 +20,15 @@ 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; $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 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 diff --git a/www/newitems.php b/www/newitems.php index 12490d6e..581c8bec 100644 --- a/www/newitems.php +++ b/www/newitems.php @@ -89,22 +89,19 @@ function getNewItems($db, $limit, $itemTypes = NEWITEMS_ALLITEMS, $options = [], } if ($itemTypes & NEWITEMS_GAMES) { + $term = ""; + if ($days) $term = "added:" . $days . "d-"; + $searchType = "game"; + $sortby = "lnew"; $games_limit = $options['games_limit'] ?? $limit; - if ($days) $dayWhere = "created > date_sub(now(), interval $days day)"; + $limit_clause = "limit $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); } } 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); diff --git a/www/search b/www/search index 35abcd21..5d08ea0f 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) { @@ -1281,6 +1286,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']; diff --git a/www/searchutil.php b/www/searchutil.php index 40d30122..a8aeb9c1 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(); @@ -251,7 +251,7 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_g "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), @@ -280,6 +280,7 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_g 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', @@ -689,17 +690,9 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_g 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': @@ -707,17 +700,9 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_g 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': @@ -725,36 +710,20 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_g 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': @@ -762,18 +731,9 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_g 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': @@ -1150,11 +1110,24 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_g } $sql_calc_found_rows = "sql_calc_found_rows"; - if ($searchType === "game" && $where === "1") { - // `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 + + 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 = ""; } + 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 @@ -1202,12 +1175,12 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $override_g 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); } else { - $rowcnt = length($rows); + $rowcnt = count($rows); } } else {