Bug 34587: Move period total calculations to the backend to improve performance

Remove the front end processing in favour of doing this in the backend and passing it in the API response

Signed-off-by: Jessica Zairo <jzairo@bywatersolutions.com>
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Matt Blenkinsop 2023-08-04 16:32:16 +00:00 committed by Tomas Cohen Arazi
parent 1ad9959fa5
commit e935423b78
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
4 changed files with 47 additions and 22 deletions

View file

@ -283,6 +283,8 @@ sub metric_types_report {
=head3 provider_rollup_report
An endpoint to fetch all data for all providers for a given report type
=cut
sub provider_rollup_report {
@ -389,7 +391,11 @@ sub provider_rollup_report {
};
}
=head3 _get_data_set
Returns the Koha object that needs to be used to fetch the data for this report.
=cut
sub _get_data_set {
my ($data_type) = @_;
@ -409,6 +415,13 @@ sub _get_data_set {
return 0;
}
=head3 _get_correct_query_param
Returns the array of ids (or an empty array) for the data type that has been requested as a report parameter.
e.g. If it is a titles report and the user has requested titles with the ids 1,2,3, these will be fetched from the query parameters and returned as (1,2,3).
=cut
sub _get_correct_query_param {
my ( $data_type, $array_ref, $period ) = @_;
@ -428,6 +441,13 @@ sub _get_correct_query_param {
return $param;
}
=head3 _get_result_with_no_statistics
Takes in an id number and a dataset. If that id number exists within the dataset then no action is needed.
If it isn't found then that means there are no statistics for that object. It is however required in the report so is returned with a blank dataset.
=cut
sub _get_result_with_no_statistics {
my ($args) = @_;
@ -466,6 +486,7 @@ sub _get_object_hash {
my $provider = $args->{provider};
my $metric_type = $args->{metric_type};
my $period = $args->{period};
my $sum = $args->{sum};
my %object_hash;
if ( $data_type eq 'title' ) {
@ -527,6 +548,12 @@ sub _get_object_hash {
return \%object_hash;
}
=head3 _get_missing_data
If an id is identified as missing, this piece of data is fetched and returned into _get_result_with_no_statistics for processing.
=cut
sub _get_missing_data {
my ( $data_type, $id ) = @_;

View file

@ -153,4 +153,12 @@ __PACKAGE__->belongs_to(
# You can replace this text with custom code or comments, and it will be preserved on regeneration
sub koha_object_class {
'Koha::ERM::UsageDatabase';
}
sub koha_objects_class {
'Koha::ERM::UsageDatabases';
}
1;

View file

@ -143,4 +143,13 @@ __PACKAGE__->belongs_to(
# You can replace this text with custom code or comments, and it will be preserved on regeneration
sub koha_object_class {
'Koha::ERM::UsageItem';
}
sub koha_objects_class {
'Koha::ERM::UsageItems';
}
1;

View file

@ -151,22 +151,8 @@ export default {
orderable: true,
})
column_set.push({
title: __("Period Total"),
render: function (data, type, row, meta) {
const sum = row[`erm_usage_${data_type}s`].reduce(
(acc, obj) => {
const objSum = obj.erm_usage_muses.reduce(
(acc, mus) => {
return acc + mus.usage_count
},
0
)
return acc + objSum
},
0
)
return sum
},
title: __("Period total"),
data: "provider_rollup_total",
searchable: true,
orderable: true,
})
@ -281,12 +267,7 @@ export default {
if (report_type === "monthly_with_totals") {
column_set.push({
title: __("Period total"),
render: function (data, type, row, meta) {
const sum = row.erm_usage_muses.reduce((acc, item) => {
return acc + item.usage_count
}, 0)
return sum
},
name: "usage_total",
searchable: true,
orderable: true,
})