Skip to content
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

feat(game): add sort_title field and backfill command #2690

Merged
merged 17 commits into from
Sep 19, 2024

Conversation

wescopeland
Copy link
Member

Implements #1062.
Developed to resolve the performance issue mentioned in #2686 (comment).


sail artisan ra:platform:write-game-sort-titles 1 # write by ID
sail artisan ra:platform:write-game-sort-titles # write them all

This PR adds a sort_title field to the GameData table.

We are actually already using this field on most game lists. However, it is computed on the fly in memory by PHP.

This PR's changeset simply moves that logic to a database column, ensures it's written to when the game title changes, and allows moderators/admins to override the field in the management app.

If a custom sort_title is provided, the new action is smart enough to detect this and not override it.

Screenshot 2024-09-12 at 9 06 47 PM

@wescopeland wescopeland added the deployment/command Includes an Artisan command that needs to be run before/during deployment label Sep 13, 2024
@wescopeland wescopeland requested a review from a team September 13, 2024 01:42
app/Filament/Resources/GameResource.php Outdated Show resolved Hide resolved
$action = new WriteGameSortTitleFromGameTitleAction();
Game::query()->chunk(100, function ($games) use ($progressBar, $action) {
foreach ($games as $game) {
$action->execute($game, $game->title, shouldRespectCustomSortTitle: false);
Copy link
Member

Choose a reason for hiding this comment

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

Would it be overly ambitious to re-normalize articles?

Legend of Zelda, The: A Link to the Past => The Legend of Zelda: A Link to the Past with a sort title of just legend of zelda: a link to the past

Bug's Life, A => A Bug's Life with a sort title of bug's life

Copy link
Member Author

Choose a reason for hiding this comment

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

Tricky, but I think I got it in latest. Added a few tests which seem to verify the new behavior is okay.

Copy link
Member Author

Choose a reason for hiding this comment

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

Just to clarify, would you like to also see the game titles themselves readjust the placement of the articles?

Copy link
Member

Choose a reason for hiding this comment

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

That's the goal state. Per #1062:

Ignore definite and indefinite articles at the start of titles so we don't have to rename them to force the correct sorting order.

Doing so now would break the sort order until the queries were updated to use the new sort column.

app/Filament/Resources/GameResource.php Show resolved Hide resolved
app/Helpers/database/game.php Outdated Show resolved Hide resolved
app/Platform/Services/GameListService.php Show resolved Hide resolved
$action = new WriteGameSortTitleFromGameTitleAction();
Game::query()->chunk(100, function ($games) use ($progressBar, $action) {
foreach ($games as $game) {
$action->execute($game, $game->title, shouldRespectCustomSortTitle: false);
Copy link
Member

Choose a reason for hiding this comment

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

That's the goal state. Per #1062:

Ignore definite and indefinite articles at the start of titles so we don't have to rename them to force the correct sorting order.

Doing so now would break the sort order until the queries were updated to use the new sort column.

app/Helpers/database/game.php Outdated Show resolved Hide resolved
@wescopeland wescopeland merged commit 138ee73 into RetroAchievements:master Sep 19, 2024
6 checks passed
@wescopeland wescopeland deleted the game-sort-title branch September 19, 2024 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deployment/command Includes an Artisan command that needs to be run before/during deployment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants