Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2d40c71
newitems.php: use doSearch for getting new games
alice-blue Dec 4, 2024
eb97d6b
searchutil.php: select createdate for game listings so we can use it …
alice-blue Dec 4, 2024
c5fcdb9
`#ratings:` search should use `numRatingsInAvg` not `numRatingsTotal`
dfabulich Jan 18, 2025
c050f71
Search results call it `devsys` instead of `system`
dfabulich Jan 18, 2025
a7d6d0e
newitems.php: remove unnecessary 0 in limit clause
alice-blue Jan 18, 2025
703495c
Merge pull request #8 from dfabulich/use-doSearch-for-newitems
alice-blue Jan 18, 2025
157bf5f
searchutil.php: Add $count_all_possible_rows parameter to doSearch
alice-blue Jan 19, 2025
310ebac
ifdb-recommends.php: Use $count_all_possible_rows parameter in call t…
alice-blue Jan 19, 2025
be1f667
review: Use $count_all_possible_rows parameter and $override_game_fil…
alice-blue Jan 19, 2025
0954a8b
search: Use $count_all_possible_rows parameter in call to doSearch
alice-blue Jan 19, 2025
db7086a
editgame: Use $count_all_possible_rows and $override_game_filter para…
alice-blue Jan 19, 2025
9bc40d4
length($rows) --> count($rows) (to get rid of fatal error)
alice-blue Jan 19, 2025
d016bac
searchutil.php: check for $term rather than a where clause to see if …
alice-blue Jan 19, 2025
96bb618
Correctly exclude sandboxed ratings from `gameRatingsSandbox0`
dfabulich Jan 19, 2025
02c69b3
Merge pull request #1264 from iftechfoundation/fix-sandbox-gameratings
dfabulich Jan 19, 2025
801f985
searchutil.php: Fixed one more spot where we're checking `$where`
dfabulich Jan 19, 2025
d1942d8
Merge branch 'patch-2'
dfabulich Jan 19, 2025
166f2f6
$where --> !$term
alice-blue Jan 19, 2025
b571fc5
Combine conditions & comments
alice-blue Jan 19, 2025
8796aec
Merge branch 'main' into doSearch-need_total_rows-parameter
alice-blue Jan 20, 2025
8f09857
search: Add a comment explaining the warning banner for buried games
dfabulich Jan 20, 2025
0cbb32e
Merge pull request #1253 from iftechfoundation/search-numRatingsInAvg
dfabulich Jan 21, 2025
cb16a72
searchutil.php: Add $count_all_possible_rows parameter to doSearch
alice-blue Jan 19, 2025
1e208ef
ifdb-recommends.php: Use $count_all_possible_rows parameter in call t…
alice-blue Jan 19, 2025
404520b
review: Use $count_all_possible_rows parameter in call to doSearch
alice-blue Jan 19, 2025
3a133f1
search: Use $count_all_possible_rows parameter in call to doSearch
alice-blue Jan 19, 2025
f91e3af
editgame: Use $count_all_possible_rows in call to doSearch
alice-blue Jan 19, 2025
3342cf3
length($rows) --> count($rows) (to get rid of fatal error)
alice-blue Jan 19, 2025
ea64674
Improve logged-out IFDB Recommends search performance
dfabulich Jan 22, 2025
27f50d3
Improve logged-in IFDB Recommends search performance
dfabulich Jan 22, 2025
f3d6803
Merge branch 'main' into filter-games-merged
dfabulich Jan 22, 2025
663cef4
Merge branch 'ifdb-recommends-performance' into filter-games-merged
dfabulich Jan 22, 2025
30cc954
Merge branch 'use-doSearch-for-newitems' into filter-games-merged
dfabulich Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions sql/unscrub-ifarchive.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down Expand Up @@ -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`,
Expand Down
2 changes: 1 addition & 1 deletion www/components/games.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
. "</i></b></a>, by "
. htmlspecialcharx($g['author']);

if ($g['system']) echo " <div class=details>{$g['system']}</div>";
if ($g['devsys']) echo " <div class=details>{$g['devsys']}</div>";

echo "</div>";
}
Expand Down
5 changes: 3 additions & 2 deletions www/components/ifdb-recommends.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reasoning for this seems obscure enough that it might be worth explaining in a comment

$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
Expand Down
5 changes: 4 additions & 1 deletion www/editgame
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 11 additions & 14 deletions www/newitems.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
4 changes: 3 additions & 1 deletion www/review
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion www/search
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'];
Expand Down
91 changes: 32 additions & 59 deletions www/searchutil.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -689,91 +690,50 @@ 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':
// Only use this query when the user is logged in
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':
// Only use this query when the user is logged in
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':
// 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 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':
Expand Down Expand Up @@ -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 = "";
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 1123-1129 can be removed (this condition is accounted for in 1114)

Copy link
Owner

@alice-blue alice-blue Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After merging your PR, I did another commit to delete those lines in the filter games 3 branch



// build the SELECT statement
$sql = "select $sql_calc_found_rows
Expand Down Expand Up @@ -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 {
Expand Down