-
Notifications
You must be signed in to change notification settings - Fork 0
Filter games merged #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2d40c71
eb97d6b
c5fcdb9
c050f71
a7d6d0e
703495c
157bf5f
310ebac
be1f667
0954a8b
db7086a
9bc40d4
d016bac
96bb618
02c69b3
801f985
d1942d8
166f2f6
b571fc5
8796aec
8f09857
0cbb32e
cb16a72
1e208ef
404520b
3a133f1
f91e3af
3342cf3
ea64674
27f50d3
f3d6803
663cef4
30cc954
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,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': | ||
|
|
@@ -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 = ""; | ||
| } | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 { | ||
|
|
||
There was a problem hiding this comment.
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