Skip to content

Conversation

alice-blue
Copy link
Contributor

Slightly more verbose message. Fixed the spacing before the message (by using <p>) so that the spacing is about the same whether there is one result or multiple results. Changed some variable names to be clearer (taking out "search" since the game results aren't always the result of obvious searches). Also, the formatting doesn't look so strange anymore (I never figured out the cause). There's now a default value for the $override_game_filter parameter (though I don't know if it'll help much).

@alice-blue
Copy link
Contributor Author

Here's a screenshot of "no results found." I didn't get a screenshot of the other one.

game filtering v3 A

@alice-blue
Copy link
Contributor Author

Revised it again.

filter message 3

@dfabulich dfabulich requested a review from salty-horse January 6, 2025 09:50
@dfabulich
Copy link
Collaborator

Oh, also, it's conflicted, but perhaps the deeper problem is that I'm conflicted about this PR. 😖

alice-blue and others added 3 commits February 3, 2025 19:52
Add comment explaining "game_rows_after_filtering"
…iews

Always search games for new reviews
@dfabulich
Copy link
Collaborator

I spent some time on this over the weekend and I think we're in better shape than I thought!

In #1314 I fixed a bug where approximately all searches were doing full-scan queries. This automatically fixed the two existing homepage searches (for new games and IFDB recommends).

The primary scary part of this PR was searching for reviews using doSearch (ordered by "recently reviewed").

Well, when I merge the main branch into this branch, (after manually resolving conflicts in incoming-schema-changes.sql, which is pretty easy because main's version is blank), I found that it, too, was no longer doing a full-scan query, so we're good to go!

`lastReviewDate` `analyze` query

MariaDB [ifdb]> analyze select
    ->     games.id as id,
    ->             games.title as title,
    ->             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',
    ->                 date_format(games.published, '%Y'),
    ->                 date_format(games.published, '%M %e, %Y'))
    ->                 as pubfmt,
    ->             if (time(games.published) = '00:00:00',
    ->                 date_format(games.published, '%Y'),
    ->                 date_format(games.published, '%Y-%m-%d'))
    ->                 as published,
    ->             date_format(games.published, '%Y') as pubyear,
    ->             (games.coverart is not null) as hasart,
    ->             avgRating as avgrating,
    ->             numRatingsInAvg as ratingcnt,
    ->             stdDevRating as ratingdev,
    ->             numRatingsTotal,
    ->             numMemberReviews,
    ->             lastReviewDate,
    ->             starsort,
    ->             games.sort_title as sort_title,
    ->             games.sort_author as sort_author,
    ->             ifnull(games.published, '9999-12-31') as sort_pub,
    ->             games.pagevsn,
    ->             games.flags
    ->
    -> from
    ->     games
    ->             join gameRatingsSandbox0_mv on games.id = gameid
    ->
    -> where
    ->     1 and not exists (select 1 from gametags where games.id=gameid and tag in ('beginner'))
    ->
    ->
    ->
    -> order by
    ->     lastReviewDate desc
    ->
    -> limit 8 \G
*************************** 1. row ***************************
           id: 1
  select_type: PRIMARY
        table: gameRatingsSandbox0_mv
         type: index
possible_keys: PRIMARY
          key: lastReviewDate
      key_len: 5
          ref: NULL
         rows: 14371
       r_rows: 9.00
     filtered: 100.00
   r_filtered: 100.00
        Extra:
*************************** 2. row ***************************
           id: 1
  select_type: PRIMARY
        table: games
         type: eq_ref
possible_keys: PRIMARY
          key: PRIMARY
      key_len: 130
          ref: ifdb.gameRatingsSandbox0_mv.gameid
         rows: 1
       r_rows: 1.00
     filtered: 100.00
   r_filtered: 88.89
        Extra: Using where
*************************** 3. row ***************************
           id: 2
  select_type: MATERIALIZED
        table: gametags
         type: ref
possible_keys: gameid,tag
          key: tag
      key_len: 1002
          ref: const
         rows: 40
       r_rows: 35.00
     filtered: 100.00
   r_filtered: 100.00
        Extra: Using where

Here's how I generated this analysis:

  • I logged in and set -tag:beginner in my user settings (which excludes just the most recent review of "Their First Meeting" in the June archive dump)
  • I set $logging_level = 1 in searchutil.php.
  • I visited the home page and copied and pasted the query from the Docker log
  • In VS Code, I used regex find and replace to replace \\n with \n, fixing new lines
  • I added analyze to the beginning of the query, replaced the ? in the where section with 'beginner', and added \G at the end, instead of a semicolon, displaying the results vertically
  • I copied and pasted the resulting query into ./query-docker.sh

Especially note that I needed to use analyze to see that this query was OK instead of just using explain, something that I (re?)learned about in 2025. rows indicates that the query planner thinks it's gonna have to do a full scan of the index, but r_rows shows that the query planner guessed wrong; it only had to look at 9 rows to return 8 rows of results, skipping the first one because it had the beginner tag. The query planner's pessimism doesn't hurt our actual query performance, so this is OK to ship!

Here's the next steps:

  1. Resolve conflicts on this branch. Note that the branch is also in conflict with Rename "components" folder to "home-components" #1310, so when we merge one of them, we'll have to resolve conflicts on the other; I propose to merge this PR first, and Rename "components" folder to "home-components" #1310 second.
  2. I filed a couple of PRs on this PR Add lastReviewDate to gameRatingsSandbox01 alice-blue/ifdb#11 and Patch full schema alice-blue/ifdb#12

With that done, I'll queue up a deploy and finally merge this thing.

@alice-blue
Copy link
Contributor Author

Ok, I merged your PRs. (I didn't test anything.)

@alice-blue
Copy link
Contributor Author

alice-blue commented Aug 19, 2025

I'm not sure how to fix the conflicts. The filetypes stuff looks familiar, but maybe from an old, unrelated PR.

Aside from the filetypes stuff, I see this:

alter table reviewvotes
    add column `reviewvoteid` bigint(20) unsigned NOT NULL AUTO_INCREMENT FIRST,
    add column `createdate` datetime NOT NULL DEFAULT current_timestamp(),
    add PRIMARY KEY (`reviewvoteid`)
;


-- Add column for game search filter to the users table

ALTER TABLE `users` ADD COLUMN `game_filter` VARCHAR(150) DEFAULT '';

and this:

CREATE TRIGGER games_insert
AFTER INSERT ON games FOR EACH ROW
call refresh_gameRatingsSandbox0_mv(NEW.id);

CREATE TRIGGER games_delete
AFTER DELETE ON games FOR EACH ROW
call refresh_gameRatingsSandbox0_mv(OLD.id);

The only one that seems relevant to this PR is the "game_filter" one, so maybe we keep that? I don't know what to do with the others.

@dfabulich
Copy link
Collaborator

The idea of incoming-schema-changes.sql is that it's intended to take an old database dump from the IF Archive and update it to the latest database schema. incoming-schema-changes.sql gradually accumulates incoming changes until a new quarterly database dump arrives on the IF Archive. When I update main to use a newer database dump, I delete everything in incoming-schema-changes.sql in the main branch, because all of those changes had already been applied to the production database months ago.

In this PR, you just added one line to incoming-schema-changes.sql at the top of the file. In the main branch, the file changed out from under you, removing all of the lines of the file. Resolving the conflict means using the main blank version and re-adding just the one line you actually intended to add.

@alice-blue
Copy link
Contributor Author

@dfabulich, I think I resolved this.

@alice-blue alice-blue requested a review from dfabulich August 19, 2025 17:43
dfabulich and others added 4 commits August 28, 2025 11:21
I got the column orders mixed up, so when creating/updating/deleting new reviews, `gameRatingsSandbox0_mv` wasn't getting updated properly.
Fix `refresh_gameRatingsSandbox0_mv` stored procedure
The "lastreview" search prefix isn't being used. We are instead using the "recently_reviewed" sort order to get recent reviews for the home page.
This mostly follows the pattern of the gametimes view, materialized view, triggers, and update procedures, but it's possible some stuff doesn't apply
…ch the game IDs from doSearch

This is only partly working. I think it's successfully identifying the games with recent news, but that news is not showing up on the home page.
This seems to have fixed the query that wasn't working.
@alice-blue alice-blue requested a review from dfabulich September 2, 2025 01:57
$games_with_recent_news = "'" . implode("', '",$games_with_recent_news) . "'";
echo "GAMES WITH RECENT NEWS = $games_with_recent_news"; // Delete this line after we get this working
$andGameIDsMatch = "and recentgamenews_mv.game_id in ($games_with_recent_news)";
$andGameIDsMatch = "and g.id in ($games_with_recent_news) ";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added this space at the end of the string in line 357 when I was trying to figure out the problem, and then didn't take it out. It might not be needed though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants