From 9fff419f14d76e33c561e9180d101780ab1405dc Mon Sep 17 00:00:00 2001 From: Andy Beverley Date: Sun, 20 Oct 2024 20:04:33 +0100 Subject: [PATCH] Fix regression of performance --- lib/GADS/Record.pm | 8 +++++--- lib/GADS/Records.pm | 13 ++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/GADS/Record.pm b/lib/GADS/Record.pm index b6c1200bf..019fbce04 100644 --- a/lib/GADS/Record.pm +++ b/lib/GADS/Record.pm @@ -459,10 +459,12 @@ has created_user => ( my $column = $self->layout->column_by_name_short('_created_user'); + my $value = $self->set_record_created_user || $self->record->{record_created_user}; + # Has it been retrieved as part of sql query? - if ($self->record && exists $self->record->{record_created_user}) + if ($value) { - return $self->_person($self->record->{record_created_user}, $column); + return $self->_person($value, $column); } my $user = $self->first_record_rs->createdby; @@ -518,7 +520,7 @@ has edited_user => ( # Has it been retrieved as part of sql query? if ($self->record && exists $self->record->{createdby}) { - return $self->_person($self->record->{createdby}, $column); + return $self->_person($self->record->{$column->field}, $column); } my $user = $self->record_rs->createdby; diff --git a/lib/GADS/Records.pm b/lib/GADS/Records.pm index 9a796d5c3..f422164cc 100644 --- a/lib/GADS/Records.pm +++ b/lib/GADS/Records.pm @@ -1274,7 +1274,7 @@ sub _build_standard_results set_record_created => $rec->{record_created_date}, ); $record->set_record_created_user($rec->{record_created_user}) - if exists $rec->{record_creted_user}; + if exists $rec->{record_created_user}; push @all, $record; push @created_ids, $rec->{record_created_user}; push @record_ids, $rec->{id}; @@ -1288,6 +1288,17 @@ sub _build_standard_results already_seen => $self->already_seen, ); + # Fetch and add created users (unable to retrieve during initial query) + my $created_column = $self->layout->column_by_name_short('_created_user'); + my $created_users = $created_column->fetch_multivalues(\@created_ids); + foreach my $rec (@all) + { + my $original = $rec->set_record_created_user + or next; + my $user = $created_users->{$original}; + $rec->set_record_created_user($user); + } + \@all; }