From b1482ad69beb34e8774be86bc5c1287d12a41bec Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Thu, 1 Feb 2024 14:45:30 +0000 Subject: [PATCH 1/7] Reduce queries on /admin page by prefetching assigned user --- perllib/FixMyStreet/App/Controller/Admin.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 145e64256dc..2301196405a 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -82,7 +82,7 @@ sub index : Path : Args(0) { }, { '+columns' => ['user.email'], - prefetch => 'contact', + prefetch => [ 'contact', 'user_planned_reports' ], join => 'user', order_by => 'confirmed', } )->all; From bd88681e1602b95d242efd17e6b1543db003986d Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Thu, 1 Feb 2024 14:46:16 +0000 Subject: [PATCH 2/7] Show count of unsent reports above table on /admin --- templates/web/base/admin/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/web/base/admin/index.html b/templates/web/base/admin/index.html index 11031b26cc4..f00a62cb6df 100644 --- a/templates/web/base/admin/index.html +++ b/templates/web/base/admin/index.html @@ -52,7 +52,7 @@ [% IF unsent_reports.size %] -

[% loc('Reports waiting to be sent') %]

+

[% tprintf( nget(loc('%d report waiting to be sent'), loc('%d reports waiting to be sent'), unsent_reports.size), unsent_reports.size ) %]

From d70a2aa3cd07bd844dc7a633a318c599e00b8fe5 Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Thu, 1 Feb 2024 15:25:15 +0000 Subject: [PATCH 3/7] Reformat unsent reports table on /admin --- templates/web/base/admin/index.html | 7 ++-- .../web/base/admin/unsent_problem_row.html | 35 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 templates/web/base/admin/unsent_problem_row.html diff --git a/templates/web/base/admin/index.html b/templates/web/base/admin/index.html index f00a62cb6df..bdb9dfd9a00 100644 --- a/templates/web/base/admin/index.html +++ b/templates/web/base/admin/index.html @@ -58,12 +58,13 @@

[% tprintf( nget(loc('%d report waiting to be sent'), loc('%d reports waitin

- - + + + - [% INCLUDE 'admin/problem_row.html' problems = unsent_reports %] + [% INCLUDE 'admin/unsent_problem_row.html' problems = unsent_reports %]
[% loc('ID') %] [% loc('Title') %][% loc('Name') %] [% loc('Body') %][% loc('State') %][% loc('Age') %][% loc('Failures') %][% loc('Last failure') %] *
[% END %] diff --git a/templates/web/base/admin/unsent_problem_row.html b/templates/web/base/admin/unsent_problem_row.html new file mode 100644 index 00000000000..79cb62eddfd --- /dev/null +++ b/templates/web/base/admin/unsent_problem_row.html @@ -0,0 +1,35 @@ +[%- FOR problem IN problems %] + + [%- IF problem.is_visible -%] + [%- uri = c.uri_for_email( '/report', problem.id ) %] + [% problem.id %] + [%- ELSE %] + [%- problem.id %] + [%- END -%] + [% PROCESS value_or_nbsp value=problem.title %] + + [% PROCESS value_or_nbsp value=problem.category_display %] + [%- IF edit_body_contacts -%] + [% FOR body IN problem.bodies.values %] +
[% PROCESS value_or_nbsp value=body.name %] + [% END %] + [%- ELSE -%] +
[%- PROCESS value_or_nbsp value=problem.bodies_str -%] + [%- END -%] + + + [% problem.time_ago %] +
[% PROCESS format_time time=problem.confirmed %] + + [% problem.send_fail_count %] + + [% PROCESS format_time time=problem.send_fail_timestamp %] +
[% problem.time_ago('send_fail_timestamp') %] ago + + + [% IF c.user.has_permission_to('report_edit', problem.bodies_str_ids) %] + [% loc('Edit') %] + [% END %] + + +[%- END -%] From 0cd40278696ebcb5739f83b7d05ab88c2c6668cb Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Thu, 1 Feb 2024 15:38:16 +0000 Subject: [PATCH 4/7] fixup! Reformat unsent reports table on /admin --- templates/web/base/admin/unsent_problem_row.html | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/templates/web/base/admin/unsent_problem_row.html b/templates/web/base/admin/unsent_problem_row.html index 79cb62eddfd..5187bc354e3 100644 --- a/templates/web/base/admin/unsent_problem_row.html +++ b/templates/web/base/admin/unsent_problem_row.html @@ -23,8 +23,10 @@ [% problem.send_fail_count %] - [% PROCESS format_time time=problem.send_fail_timestamp %] -
[% problem.time_ago('send_fail_timestamp') %] ago + [% IF problem.send_fail_timestamp %] + [% PROCESS format_time time=problem.send_fail_timestamp %] +
[% problem.time_ago('send_fail_timestamp') %] ago + [% END %] [% IF c.user.has_permission_to('report_edit', problem.bodies_str_ids) %] From 3c82fd6a3ecb08bd251ce5de8df4f554412ce397 Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Thu, 1 Feb 2024 15:50:51 +0000 Subject: [PATCH 5/7] fixup! Reformat unsent reports table on /admin --- templates/web/base/admin/unsent_problem_row.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/web/base/admin/unsent_problem_row.html b/templates/web/base/admin/unsent_problem_row.html index 5187bc354e3..1e80f7db6ff 100644 --- a/templates/web/base/admin/unsent_problem_row.html +++ b/templates/web/base/admin/unsent_problem_row.html @@ -22,7 +22,7 @@
[% PROCESS format_time time=problem.confirmed %] [% problem.send_fail_count %] - + [% IF problem.send_fail_timestamp %] [% PROCESS format_time time=problem.send_fail_timestamp %]
[% problem.time_ago('send_fail_timestamp') %] ago From a506d78213145e7b248836e4700ed57e545a1e63 Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Wed, 7 Feb 2024 10:10:21 +0000 Subject: [PATCH 6/7] Show WasteWorks unsent reports to superusers on .com /admin --- perllib/FixMyStreet/App/Controller/Admin.pm | 4 +++- templates/web/base/admin/unsent_problem_row.html | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 2301196405a..6117354c8f3 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -73,7 +73,9 @@ sub index : Path : Args(0) { $c->stash->{edit_body_contacts} = 1 if grep { $_ eq 'body' } keys %{$c->stash->{allowed_pages}}; - my @unsent = $c->cobrand->problems->search( { + my $problems = ($c->cobrand->moniker eq 'fixmystreet' && $c->user->is_superuser) ? $c->model('DB::Problem') : $c->cobrand->problems; + + my @unsent = $problems->search( { send_state => ['unprocessed', 'acknowledged'], 'me.state' => [ FixMyStreet::DB::Result::Problem::open_states() ], bodies_str => { '!=', undef }, diff --git a/templates/web/base/admin/unsent_problem_row.html b/templates/web/base/admin/unsent_problem_row.html index 1e80f7db6ff..e0e3de0ac04 100644 --- a/templates/web/base/admin/unsent_problem_row.html +++ b/templates/web/base/admin/unsent_problem_row.html @@ -5,7 +5,9 @@ [% problem.id %] [%- ELSE %] [%- problem.id %] - [%- END -%] + [%- END -%] + [%~ IF problem.cobrand_data %]
[% problem.cobrand_data %][%~ END ~%] + [% PROCESS value_or_nbsp value=problem.title %] [% PROCESS value_or_nbsp value=problem.category_display %] From 5f130db7d8055f6d23bd3064d914892be258848d Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Wed, 7 Feb 2024 10:10:46 +0000 Subject: [PATCH 7/7] WIP restore display of unsent bodies --- templates/web/base/admin/unsent_problem_row.html | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/templates/web/base/admin/unsent_problem_row.html b/templates/web/base/admin/unsent_problem_row.html index e0e3de0ac04..782838b4afa 100644 --- a/templates/web/base/admin/unsent_problem_row.html +++ b/templates/web/base/admin/unsent_problem_row.html @@ -12,11 +12,19 @@ [% PROCESS value_or_nbsp value=problem.category_display %] [%- IF edit_body_contacts -%] - [% FOR body IN problem.bodies.values %] -
[% PROCESS value_or_nbsp value=body.name %] - [% END %] + [% IF problem.whensent %] +
[% loc('When sent') %]: [% PROCESS format_time time=problem.whensent %] + [%- send_fail_bodies = problem.send_fail_bodies -%] + [%- IF send_fail_bodies.size %] +
[% loc('Failed bodies:') %] [% send_fail_bodies.join(', ') %] + [% END -%] + [% ELSE -%] + [% FOR body IN problem.bodies.values %] +
[% PROCESS value_or_nbsp value=body.name %] + [% END %] + [% END -%] [%- ELSE -%] -
[%- PROCESS value_or_nbsp value=problem.bodies_str -%] +
[%- PROCESS value_or_nbsp value=problem.bodies_str -%] [%- END -%]