Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
81 changes: 20 additions & 61 deletions www/newitems.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,47 +171,21 @@ function getNewItems($db, $limit, $itemTypes = NEWITEMS_ALLITEMS, $options = [],

if ($itemTypes & NEWITEMS_REVIEWS) {
$reviews_limit = $options['reviews_limit'] ?? $limit;
$reviews_limit_clause = "";
// deal with custom game filters
$game_filter = "";
$gameids_after_filtering = [];
if ($curuser && $override_game_filter != 1) {
$result = mysqli_execute_query($db, "select game_filter from users where id = ?", [$curuser]);
if (!$result) throw new Exception("Error: " . mysqli_error($db));
[$game_filter] = mysql_fetch_row($result);
if ($game_filter != "") {
// If we'll need only a small number of reviews (to show
// on the home page, for example, vs. the allnew page),
// find games that have been reviewed in the past 365 days.
// (This condition is to avoid a slow full table scan.)
// Sort the most recently reviewed games to the top,
// and fetch the correct number of games (at most, we'll
// need the same number of games as the number of reviews
// we're ultimately looking for). The custom game filter
// gets applied in doSearch.
$term = "";
if ($reviews_limit < 20) {
$term = "lastreview:365d-";
}
$searchType = "game";
$sortby = "recently_reviewed";
$games_limit_clause = "limit $reviews_limit";
$browse = 0;
list($game_rows_after_filtering, $rowcnt, $sortList, $errMsg, $summaryDesc, $badges, $specials, $specialsUsed, $orderBy) =
doSearch($db, $term, $searchType, $sortby, $games_limit_clause, $browse);
// Note the gameids of games that we might want to display reviews for
foreach ($game_rows_after_filtering as $game_row) {
$gameids_after_filtering[] = $game_row['id'];
}
$game_filter_was_applied = 1;
Copy link
Owner

Choose a reason for hiding this comment

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

I'm guessing that taking this out is why the announcement on the allnew page does not appear.

}
}
if (!$game_filter_was_applied) {
// We're not applying a game filter, so we don't need extra reviews.
// (We only need extras if some of them might get filtered out.)
// We can limit results to the exact number we want to display.
$reviews_limit_clause = "limit $reviews_limit";
$term = "";
$searchType = "game";
$sortby = "recently_reviewed";
$games_limit_clause = "limit $reviews_limit";
$browse = 0;
// If the user has a custom game filter and has not overridden it, that
// filter will automatically be applied within the doSearch function.
list($game_rows_after_filtering, $rowcnt, $sortList, $errMsg, $summaryDesc,
$badges, $specials, $specialsUsed, $orderBy, $game_filter_was_applied)
= doSearch($db, $term, $searchType, $sortby, $games_limit_clause, $browse);
// Note the gameids of games that we might want to display reviews for
foreach ($game_rows_after_filtering as $game_row) {
$gameids_after_filtering[] = "'" . $game_row['id'] . "'";
}
$reviews_limit_clause = "limit $reviews_limit";
// prepare to query reviews
if ($days) $dayWhere = "greatest(reviews.createdate, ifnull(reviews.embargodate, '0000-00-00')) > date_sub(now(), interval $days day)";
// query the recent reviews (minus mutes)
Expand All @@ -232,12 +206,11 @@ function getNewItems($db, $limit, $itemTypes = NEWITEMS_ALLITEMS, $options = [],
games.flags
from
reviews
join games
join users
join games on games.id = reviews.gameid
join users on users.id = reviews.userid
left outer join specialreviewers on specialreviewers.id = special
where
games.id = reviews.gameid
and users.id = reviews.userid
gameid in (".join(",", $gameids_after_filtering).")
and reviews.review is not null
and ifnull(now() >= reviews.embargodate, 1)
and ifnull(specialreviewers.code, '') <> 'external'
Expand All @@ -247,23 +220,9 @@ function getNewItems($db, $limit, $itemTypes = NEWITEMS_ALLITEMS, $options = [],
order by d desc, id desc
$reviews_limit_clause", $db);
$revcnt = mysql_num_rows($result);
if ($game_filter_was_applied) {
for ($i = 0 ; $i < $revcnt ; $i++) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
// Only add the review to $items if it matches a gameid
// in $gameids_after_filtering
if (in_array($row['gameid'], $gameids_after_filtering)) {
$items[] = array('R', $row['d'], $row);
if ( count($items) == $reviews_limit ) {
break;
}
}
}
} else {
for ($i = 0 ; $i < $revcnt ; $i++) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$items[] = array('R', $row['d'], $row);
}
for ($i = 0 ; $i < $revcnt ; $i++) {
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$items[] = array('R', $row['d'], $row);
}
}

Expand Down
11 changes: 2 additions & 9 deletions www/searchutil.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,8 @@ function doSearch($db, $term, $searchType, $sortby, $limit, $browse, $count_all_
$baseWhere = "";
$groupBy = "";
$baseOrderBy = "";
if ($browse && ($sortby == "" || $sortby == "ratu" || $sortby == "ratd" || $sortby == "rcu")) {
// when sorting by highest/lowest/most ratings, we can optimize by
// fetching the top N from the gameRatingsView
$tableList = "games
join ".getGameRatingsView($db)." on games.id = gameid";
} else {
$tableList = "games
left join ".getGameRatingsView($db)." on games.id = gameid";
}
$tableList = "games
join ".getGameRatingsView($db)." on games.id = gameid";
$matchCols = "title, author, `desc`, tags";
$likeCol = "title";
$summaryDesc = "Games";
Expand Down