Skip to content

perf: denormalize games.parent_game_id#4891

Open
wescopeland wants to merge 4 commits into
RetroAchievements:masterfrom
wescopeland:denormalize-parent-game-id
Open

perf: denormalize games.parent_game_id#4891
wescopeland wants to merge 4 commits into
RetroAchievements:masterfrom
wescopeland:denormalize-parent-game-id

Conversation

@wescopeland
Copy link
Copy Markdown
Member

Follow-up to hotfix from #4887.

This PR adds a games.parent_game_id denormalized field and largely deletes the hotfix code. The field is written in-place during the migration itself. Observers keep the field synced.

It's a known limitation that the field is lossy. In other words, only one game ID is supported in this field, so subsets like Pokemon R/B's won't necessarily be accurate. I think the trade-off is fine for the time being.

@wescopeland wescopeland requested a review from a team May 15, 2026 00:08
Comment thread app/Models/Game.php
}

return $this->parentGameId !== null;
return $this->parent_game_id !== null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The short-circuit can be removed now.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done in latest.

Comment thread app/Models/Game.php Outdated
public function parent(): BelongsTo
{
return $this->belongsTo(Game::class, 'parent_game_id');
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason to add this instead of updating parentGame? As best as I can tell, there's only two references to parentGame(), and those can be updated by just removing the parentheses.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updating parentGame is better. Done in latest.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure if this isn't working, or if I'm missing something.

MariaDB [retroachievements-web]> select parent_game_id from games where id=25811;
+----------------+
| parent_game_id |
+----------------+
|          25807 |
+----------------+
1 row in set (0.001 sec)

I think it should return 4.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is confusing, and your expectation is reasonable, but I think what's happening right now that you're seeing is the correct behavior.

It's a known limitation that the field is lossy. In other words, only one game ID is supported in this field, so subsets like Pokemon R/B's won't necessarily be accurate. I think the trade-off is fine for the time being.

In this case, game 25807 (the real parent game where this subset was first attached) is the earliest non-core link as the parent. Therefore, it "wins" over the new one to game 4. This preserves existing prod behavior.

$retroRatioPlayerCount = Game::find($game->parentGameId)->players_hardcore ?? 0;
if ($game->parent_game_id) {
$retroRatioPlayerCount = Game::find($game->parent_game_id)->players_hardcore ?? 0;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Might be better to use relationship in case it's already loaded?

$game->loadMissing('parentGame');
if ($game->parentGame) {
    $retroRatioPlayerCount = $game->parentGame->players_hardcore ?? 0;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated in latest.

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