Skip to content

Commit

Permalink
Improve performance of admin email search.
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Dec 5, 2024
1 parent cfe3eff commit de3ea02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Releases

* Unreleased
- Admin improvements:
- Improve performance of admin reports search for email. #5284
- Development improvements
- More logging when page_error is called, to aid troubleshooting. #5279

Expand Down
8 changes: 7 additions & 1 deletion perllib/FixMyStreet/App/Controller/Admin/Reports.pm
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,14 @@ sub index : Path {
my $updates = $c->cobrand->updates;
$order = { -desc => 'me.id' };
if ($valid_email) {
# If you naively put: 'user.email' => { ilike => $like_search },
# in the query, PostgreSQL 13 will perform a backwards primary key
# index scan and check each user as it goes, rather than looking up
# the users and using the comment's user_id index.
my $subselect = FixMyStreet::DB->resultset("User")->search(
{ email => { ilike => $like_search } }, { columns => ['id'] });
$query = [
'user.email' => { ilike => $like_search },
'user.id' => { -in => $subselect->as_query },
];
} elsif ($valid_phone) {
$query = [
Expand Down

0 comments on commit de3ea02

Please sign in to comment.