Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
77 changes: 16 additions & 61 deletions www/newitems.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,47 +171,17 @@ 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;
[$game_rows_after_filtering] = doSearch($db, $term, $searchType, $sortby, $games_limit_clause, $browse);
Copy link
Owner

@alice-blue alice-blue Feb 3, 2025

Choose a reason for hiding this comment

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

In the case where no filter is set, I don't understand why this search is being run. Is it accomplishing anything other than recording the gameid of every game in the database? Wait...there's a limit, so I guess it's recording the gameids of like the 8 most recently reviewed games...?

Copy link
Owner

Choose a reason for hiding this comment

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

Also, I haven't tested this, but if there are no spare gameids--if we're just grabbing the exact number of games we need--then what happens if the last 8 games that got reviewed were reviewed by someone on my mute list?

Copy link
Author

Choose a reason for hiding this comment

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

Indeed, it is recording the gameids of the 8 most recently reviewed games, including whatever custom search filter you may or may not have applied, but not incorporating muting, so, if someone you've muted posts 8 reviews, the home page reviews section could turn up blank. I think that's fine, because it's probably never going to happen.

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm. When I test this, and mute two of the front page reviewers, I seem to still be getting the same number of reviews on the front page (6 reviews) as are on the live IFDB site, and I still seem to be getting 50 reviews when I go to the "see full list" page. I'm not sure why....

// 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 +202,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 +216,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