From 1c0ff400570bc64d711406c7680357dbfa37233d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Tamargo?= Date: Fri, 27 Dec 2024 09:16:23 +0200 Subject: [PATCH 1/3] MBS-13872: Show primary alias in user tags and ratings I had loaded aliases here for some cases, but not most - this should now cover all pages (user tag and user tag by entity, and user rating and user rating by entity). --- lib/MusicBrainz/Server/Controller/User.pm | 19 +++++++++++++++---- lib/MusicBrainz/Server/Data/Editor.pm | 6 +++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/lib/MusicBrainz/Server/Controller/User.pm b/lib/MusicBrainz/Server/Controller/User.pm index bfebacc7459..fe1437330e6 100644 --- a/lib/MusicBrainz/Server/Controller/User.pm +++ b/lib/MusicBrainz/Server/Controller/User.pm @@ -573,6 +573,8 @@ sub ratings : Chained('load') PathPart('ratings') Args(1) HiddenOnMirrors }, limit => 100); $c->model('ArtistCredit')->load(@$ratings) if $entity_properties->{artist_credits}; + $c->model($model)->load_aliases(@$ratings) + if $c->model($model)->can('load_aliases'); my %props = ( entityType => $type, @@ -655,11 +657,15 @@ sub tag : Chained('load_tag') PathPart('') if ($tag) { %tagged_entities = map { my $entity_properties = $ENTITIES{$_}; + my $model = $c->model($entity_properties->{model}); - my ($entities, $total) = $c->model($entity_properties->{model})->tags->find_editor_entities( + my ($entities, $total) = $model->tags->find_editor_entities( $user->id, $tag->id, $show_downvoted, 10, 0); - $c->model('ArtistCredit')->load(map { $_->entity } @$entities) + my @entity_entries = map { $_->entity } @$entities; + $c->model('ArtistCredit')->load(@entity_entries) if $entity_properties->{artist_credits}; + $model->load_aliases(@entity_entries) + if $model->can('load_aliases'); ("$_" => { count => $total, @@ -694,6 +700,7 @@ for my $entity_type (entities_with('tags')) { my $method = sub { my ($self, $c) = @_; + my $model = $c->model($entity_properties->{model}); my $user = $c->stash->{user}; my $tag = $c->stash->{tag}; my $show_downvoted = $c->req->params->{show_downvoted} ? 1 : 0; @@ -708,10 +715,14 @@ for my $entity_type (entities_with('tags')) { my $entity_tags = $self->_load_paged($c, sub { return ([], 0) unless $tag; - return $c->model($entity_properties->{model})->tags->find_editor_entities( + return $model->tags->find_editor_entities( $user->id, $c->stash->{tag}->id, $show_downvoted, shift, shift); }); - $c->model('ArtistCredit')->load(map { $_->entity } @$entity_tags) if $entity_properties->{artist_credits}; + my @entity_entries = map { $_->entity } @$entity_tags; + $c->model('ArtistCredit')->load(@entity_entries) + if $entity_properties->{artist_credits}; + $model->load_aliases(@entity_entries) + if $model->can('load_aliases'); $c->stash( current_view => 'Node', diff --git a/lib/MusicBrainz/Server/Data/Editor.pm b/lib/MusicBrainz/Server/Data/Editor.pm index 2b0a4fc8b10..867357fc821 100644 --- a/lib/MusicBrainz/Server/Data/Editor.pm +++ b/lib/MusicBrainz/Server/Data/Editor.pm @@ -122,12 +122,16 @@ sub summarize_ratings return { map { my $entity_properties = $ENTITIES{$_}; - my ($entities) = $self->c->model($entity_properties->{model})->rating + my $model = $self->c->model($entity_properties->{model}); + my ($entities) = $model->rating ->find_editor_ratings($user->id, $me, 10, 0); $self->c->model('ArtistCredit')->load(@$entities) if $entity_properties->{artist_credits}; + $model->load_aliases(@$entities) + if $model->can('load_aliases'); + ($_ => to_json_array($entities)); } entities_with('ratings'), }; From 358dc20bd4b82343cb7e2a0e319f3223d472284d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Tamargo?= Date: Fri, 3 Jan 2025 10:15:05 +0200 Subject: [PATCH 2/3] Use entity_properties->{aliases} where trivial This is a bit more clear and mirrors what these files already do for ACs. Not yet changing uses of can('load_aliases') where we don't otherwise use %ENTITIES since that's a less trivial change. --- lib/MusicBrainz/Server/Controller/Root.pm | 2 +- lib/MusicBrainz/Server/Controller/Tag.pm | 2 +- lib/MusicBrainz/Server/Controller/User.pm | 6 +++--- lib/MusicBrainz/Server/Data/Editor.pm | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/MusicBrainz/Server/Controller/Root.pm b/lib/MusicBrainz/Server/Controller/Root.pm index b2cf62d48f9..cb472406359 100644 --- a/lib/MusicBrainz/Server/Controller/Root.pm +++ b/lib/MusicBrainz/Server/Controller/Root.pm @@ -457,7 +457,7 @@ sub begin : Private my @merge = values %{ $model->get_by_ids($merger->all_entities); }; - $model->load_aliases(@merge) if $model->can('load_aliases'); + $model->load_aliases(@merge) if $entity_properties->{aliases}; $c->model('ArtistCredit')->load(@merge) if $entity_properties->{artist_credits}; diff --git a/lib/MusicBrainz/Server/Controller/Tag.pm b/lib/MusicBrainz/Server/Controller/Tag.pm index 7ad275d9726..9e426fa3cbc 100644 --- a/lib/MusicBrainz/Server/Controller/Tag.pm +++ b/lib/MusicBrainz/Server/Controller/Tag.pm @@ -98,7 +98,7 @@ sub show : Chained('load') PathPart('') my @entities = map { $_->entity } @$entity_tags; $model->load_aliases(@entities) - if $model->can('load_aliases'); + if $entity_properties->{aliases}; $c->model('ArtistCredit')->load(@entities) if $entity_properties->{artist_credits}; diff --git a/lib/MusicBrainz/Server/Controller/User.pm b/lib/MusicBrainz/Server/Controller/User.pm index fe1437330e6..865fda0bc9b 100644 --- a/lib/MusicBrainz/Server/Controller/User.pm +++ b/lib/MusicBrainz/Server/Controller/User.pm @@ -574,7 +574,7 @@ sub ratings : Chained('load') PathPart('ratings') Args(1) HiddenOnMirrors $c->model('ArtistCredit')->load(@$ratings) if $entity_properties->{artist_credits}; $c->model($model)->load_aliases(@$ratings) - if $c->model($model)->can('load_aliases'); + if $entity_properties->{aliases}; my %props = ( entityType => $type, @@ -665,7 +665,7 @@ sub tag : Chained('load_tag') PathPart('') $c->model('ArtistCredit')->load(@entity_entries) if $entity_properties->{artist_credits}; $model->load_aliases(@entity_entries) - if $model->can('load_aliases'); + if $entity_properties->{aliases}; ("$_" => { count => $total, @@ -722,7 +722,7 @@ for my $entity_type (entities_with('tags')) { $c->model('ArtistCredit')->load(@entity_entries) if $entity_properties->{artist_credits}; $model->load_aliases(@entity_entries) - if $model->can('load_aliases'); + if $entity_properties->{aliases}; $c->stash( current_view => 'Node', diff --git a/lib/MusicBrainz/Server/Data/Editor.pm b/lib/MusicBrainz/Server/Data/Editor.pm index 867357fc821..d9590c0d4a9 100644 --- a/lib/MusicBrainz/Server/Data/Editor.pm +++ b/lib/MusicBrainz/Server/Data/Editor.pm @@ -130,7 +130,7 @@ sub summarize_ratings if $entity_properties->{artist_credits}; $model->load_aliases(@$entities) - if $model->can('load_aliases'); + if $entity_properties->{aliases}; ($_ => to_json_array($entities)); } entities_with('ratings'), From fbca2bd2fa901a385e02dabe70286a0ec5dab10e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Tamargo?= Date: Fri, 3 Jan 2025 10:47:36 +0200 Subject: [PATCH 3/3] Load aliases for artist merge pages Seems I added this everywhere else that is relevant but forgot for artists --- lib/MusicBrainz/Server/Controller/Artist.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/MusicBrainz/Server/Controller/Artist.pm b/lib/MusicBrainz/Server/Controller/Artist.pm index 62c3641bcd3..607a821dcc5 100644 --- a/lib/MusicBrainz/Server/Controller/Artist.pm +++ b/lib/MusicBrainz/Server/Controller/Artist.pm @@ -726,6 +726,7 @@ sub _merge_load_entities { my ($self, $c, @artists) = @_; $c->model('ArtistType')->load(@artists); + $c->model('Artist')->load_aliases(@artists); $c->model('Gender')->load(@artists); $c->model('Area')->load(@artists); $c->model('Area')->load_containment(map { $_->{area} } @artists);