From b02f8b7c5fa602a1bf8080e3a8842fa75699d0e9 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Mon, 15 Jul 2019 04:25:51 +0100 Subject: [PATCH] This should have fixed a few issues... need to speed things up though --- lib/Pear/LocalLoop/Controller/Api/External.pm | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/External.pm b/lib/Pear/LocalLoop/Controller/Api/External.pm index d4dee8a..977d99c 100644 --- a/lib/Pear/LocalLoop/Controller/Api/External.pm +++ b/lib/Pear/LocalLoop/Controller/Api/External.pm @@ -123,7 +123,12 @@ sub post_year_spend { my $user = $c->stash->{api_user}; - my $last = DateTime->today; + # Temporary date lock for dev data + my $last = DateTime->new( + year => 2019, + month => 4, + day => 1 + ); my $first = $last->clone->subtract( years => 1 ); my $dtf = $c->schema->storage->datetime_parser; @@ -170,7 +175,12 @@ sub post_supplier_count { my $user = $c->stash->{api_user}; - my $last = DateTime->today; + # Temporary date lock for dev data + my $last = DateTime->new( + year => 2019, + month => 4, + day => 1 + ); my $first = $last->clone->subtract( years => 1 ); my $dtf = $c->schema->storage->datetime_parser; @@ -187,6 +197,7 @@ sub post_supplier_count { }, { columns => [ + 'seller_id', { quantised => 'quantised_days', count => \"COUNT(*)", @@ -203,17 +214,13 @@ sub post_supplier_count { 'me.buyer_id' => $user->entity->id, }, { - prefetch => { entity => 'organisation' }, - columns => [ - 'organisation.name', - 'entity.id' - ] + join => { seller => 'organisation' }, } ); my %name_map = ( map { - $_->entity->id => $_->entity->organisation->name, + $_->seller->id => $_->seller->organisation->name, } $name_rs->all ); @@ -222,7 +229,7 @@ sub post_supplier_count { count => $_->get_column('count'), value => $_->get_column('total_spend'), date => $_->get_column('quantised'), - seller => %name_map{ $_->get_column('seller_id') }, + seller => $name_map{ $_->get_column('seller_id') }, } } $spend_rs->all, );