aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorM Somerville <matthew-github@dracos.co.uk>2020-11-12 12:28:10 +0000
committerM Somerville <matthew-github@dracos.co.uk>2020-11-12 12:28:10 +0000
commitedb761e9ab4299910c020eb48f839bf753da1d7b (patch)
tree7a43f7851d5d4564de01f6d65eb96fb65c59f608 /perllib
parent0b97468330ab7146f16dfe4060a63d28ce445fa6 (diff)
[Bromley] Parallel initial API calls.
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/Cobrand/Bromley.pm45
1 files changed, 38 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm
index 0885f5b6b..933d671be 100644
--- a/perllib/FixMyStreet/Cobrand/Bromley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bromley.pm
@@ -7,6 +7,7 @@ use utf8;
use DateTime::Format::W3CDTF;
use DateTime::Format::Flexible;
use Integrations::Echo;
+use Parallel::ForkManager;
use Sort::Key::Natural qw(natkeysort_inplace);
use Try::Tiny;
use FixMyStreet::DateRange;
@@ -438,8 +439,6 @@ sub look_up_property {
my $id = shift;
my $cfg = $self->feature('echo');
- my $echo = Integrations::Echo->new(%$cfg);
-
if ($cfg->{max_per_day}) {
my $today = DateTime->today->set_time_zone(FixMyStreet->local_time_zone)->ymd;
my $ip = $self->{c}->req->address;
@@ -448,7 +447,15 @@ sub look_up_property {
$self->{c}->detach('/page_error_403_access_denied', []) if $count > $cfg->{max_per_day};
}
- my $result = $echo->GetPointAddress($id);
+ my $calls = $self->_parallel_api_calls(
+ GetPointAddress => [ $id ],
+ GetServiceUnitsForObject => [ $id ],
+ GetEventsForObject => [ 'PointAddress', $id ],
+ );
+
+ $self->{api_serviceunits} = $calls->{"GetServiceUnitsForObject $id"};
+ $self->{api_events} = $calls->{"GetEventsForObject PointAddress $id"};
+ my $result = $calls->{"GetPointAddress $id"};
return {
id => $result->{Id},
uprn => $result->{SharedRef}{Value}{anyType},
@@ -536,12 +543,10 @@ sub bin_services_for_address {
544 => 4,
);
- my $echo = $self->feature('echo');
- $echo = Integrations::Echo->new(%$echo);
- my $result = $echo->GetServiceUnitsForObject($property->{id});
+ my $result = $self->{api_serviceunits};
return [] unless @$result;
- my $events = $echo->GetEventsForObject('PointAddress', $property->{id});
+ my $events = $self->{api_events};
my $open = $self->_parse_open_events($events);
my @out;
@@ -926,4 +931,30 @@ sub admin_templates_external_status_code_hook {
return "$res_code,$task_type,$task_state";
}
+sub _parallel_api_calls {
+ my $self = shift;
+ my $echo = $self->feature('echo');
+ $echo = Integrations::Echo->new(%$echo);
+
+ my %calls;
+ my $pm = Parallel::ForkManager->new(FixMyStreet->test_mode ? 0 : 10);
+ $pm->run_on_finish(sub {
+ my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data) = @_;
+ %calls = ( %calls, %$data );
+ });
+
+ while (@_) {
+ my $call = shift;
+ my $args = shift;
+ $pm->start and next;
+ my $result = $echo->$call(@$args);
+ my $key = "$call @$args";
+ $key = $call if $call eq 'GetTasks';
+ $pm->finish(0, { $key => $result });
+ }
+ $pm->wait_all_children;
+
+ return \%calls;
+}
+
1;