Skip to content

Commit

Permalink
In category setup, eagerly fetch translations.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Oct 24, 2024
1 parent 884bb0d commit 148ebde
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion perllib/FixMyStreet/App/Controller/Report/New.pm
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ sub setup_categories_and_bodies : Private {

my $all_areas = $c->stash->{all_areas};

my @bodies = $c->model('DB::Body')->active->for_areas(keys %$all_areas)->all;
my @bodies = $c->model('DB::Body')->active->for_areas(keys %$all_areas)->translated->all;
my %bodies = map { $_->id => $_ } @bodies;

$c->cobrand->call_hook(munge_report_new_bodies => \%bodies);
Expand Down
28 changes: 22 additions & 6 deletions perllib/FixMyStreet/DB/ResultSet/Contact.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,33 @@ sub for_new_reports {
$params->{$rs->me('state')} = [ 'unconfirmed', 'confirmed' ];
}

$rs->search($params, { prefetch => 'body' });
$rs = $rs->search($params, { prefetch => 'body' });
my $schema = $rs->result_source->schema;
$rs = $rs->search(undef, {
'+columns' => {
'body.msgstr' => \"COALESCE(translations.msgstr, body.name)",
'msgstr' => \"COALESCE(translations_2.msgstr, me.category)"
},
join => [ 'translations', 'translations' ],
bind => [
'name', $schema->lang, 'body',
'category', $schema->lang, 'contact',
],
});
return $rs;
}

sub translated {
my $rs = shift;
my $schema = $rs->result_source->schema;
$rs->search(undef, {
'+columns' => { 'msgstr' => \"COALESCE(translations.msgstr, me.category)" },
join => 'translations',
bind => [ 'category', $schema->lang, 'contact' ],
});
if (!$rs->{attrs}{'+columns'}[0]{msgstr}) {
$rs = $rs->search(undef, {
'+columns' => { 'msgstr' => \"COALESCE(translations.msgstr, me.category)" },
join => 'translations',
bind => [ 'category', $schema->lang, 'contact' ],
});
}
return $rs;
}

sub all_sorted {
Expand Down

0 comments on commit 148ebde

Please sign in to comment.