From 93191c10d2ea782b6e2ac4aad4fc65f6ea0a2b99 Mon Sep 17 00:00:00 2001 From: Thomas Bloor Date: Mon, 9 Sep 2019 16:42:49 +0100 Subject: [PATCH] fix transaction list in admin and speed up external count --- lib/Pear/LocalLoop/Controller/Admin/Transactions.pm | 4 ++-- lib/Pear/LocalLoop/Controller/Api/External.pm | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm b/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm index c73697f..514f326 100644 --- a/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm +++ b/lib/Pear/LocalLoop/Controller/Admin/Transactions.pm @@ -18,8 +18,8 @@ sub index { {}, { select => [ - { count => 'id', '-as' => 'count' }, - { sum => 'value', '-as' => 'sum_value' }, + { count => 'me.value', '-as' => 'count' }, + { sum => 'me.value', '-as' => 'sum_value' }, 'quantised_weeks', ], group_by => 'quantised_weeks', diff --git a/lib/Pear/LocalLoop/Controller/Api/External.pm b/lib/Pear/LocalLoop/Controller/Api/External.pm index a33c5f2..269d461 100644 --- a/lib/Pear/LocalLoop/Controller/Api/External.pm +++ b/lib/Pear/LocalLoop/Controller/Api/External.pm @@ -199,14 +199,15 @@ sub post_supplier_count { buyer_id => $user->entity->id, }, { - prefetch => { 'seller' => 'organisation' }, + join => { 'seller' => 'organisation' }, select => [ { count => 'me.id', '-as' => 'count' }, { sum => 'me.value', '-as' => 'total_spend' }, 'organisation.name', 'me.quantised_days', ], - group_by => [ 'me.quantised_days', 'seller.id' ], + as => [ qw/ count total_spend name quantised_days / ], + group_by => [ qw/ me.quantised_days seller.id organisation.id / ], order_by => { '-asc' => 'me.quantised_days' }, } ); @@ -216,7 +217,7 @@ sub post_supplier_count { count => $_->get_column('count'), value => ($_->get_column('total_spend') / 100000) // 0, date => $_->get_column('quantised_days'), - seller => $_->seller->organisation->name, + seller => $_->get_column('name'), }} $spend_rs->all, );