Bugzilla – Attachment 151273 Details for
Bug 33745
Speed up Koha::Object attribute accessors
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33745: Lazily create attribute accessor methods in AUTOLOAD
Bug-33745-Lazily-create-attribute-accessor-methods.patch (text/plain), 2.21 KB, created by
David Gustafsson
on 2023-05-16 11:55:47 UTC
(
hide
)
Description:
Bug 33745: Lazily create attribute accessor methods in AUTOLOAD
Filename:
MIME Type:
Creator:
David Gustafsson
Created:
2023-05-16 11:55:47 UTC
Size:
2.21 KB
patch
obsolete
>From 88e6c1003af79cb0b08422b2ca6853890c818c95 Mon Sep 17 00:00:00 2001 >From: David Gustafsson <david.gustafsson@ub.gu.se> >Date: Tue, 16 May 2023 13:42:55 +0200 >Subject: [PATCH] Bug 33745: Lazily create attribute accessor methods in > AUTOLOAD > >Lazily create accessor methods when getting or setting an Koha::Object >attribute resulting in a significant speed up. > >To test: >1) Run the benchmark.pl script >2) Apply the patch >3) Run the script again, Koha::Object accessors be about 7 times faster >5) Ensure tests in t/db_dependent/Item.t still pass >--- > Koha/Object.pm | 23 ++++++++++++++--------- > 1 file changed, 14 insertions(+), 9 deletions(-) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index e463f949205..13ef9acacd5 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -900,7 +900,7 @@ The autoload method is used only to get and set values for an objects properties > =cut > > sub AUTOLOAD { >- my $self = shift; >+ my ($self) = @_; > > my $method = our $AUTOLOAD; > $method =~ s/.*://; >@@ -908,13 +908,17 @@ sub AUTOLOAD { > my @columns = @{$self->_columns()}; > # Using direct setter/getter like $item->barcode() or $item->barcode($barcode); > if ( grep { $_ eq $method } @columns ) { >- if ( @_ ) { >- $self->_result()->set_column( $method, @_ ); >- return $self; >- } else { >- my $value = $self->_result()->get_column( $method ); >- return $value; >- } >+ no strict 'refs'; >+ *{$AUTOLOAD} = sub { >+ my $self = shift; >+ if ( @_ ) { >+ $self->_result()->set_column( $method, @_); >+ return $self; >+ } else { >+ return $self->_result()->get_column( $method ); >+ } >+ }; >+ goto &{$AUTOLOAD}; > } > > my @known_methods = qw( is_changed id in_storage get_column discard_changes make_column_dirty ); >@@ -924,7 +928,8 @@ sub AUTOLOAD { > show_trace => 1 > ) unless grep { $_ eq $method } @known_methods; > >- >+ # Remove $self so that @_ now contain arguments only >+ shift; > my $r = eval { $self->_result->$method(@_) }; > if ( $@ ) { > Koha::Exceptions::Object->throw( ref($self) . "::$method generated this error: " . $@ ); >-- >2.40.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 33745
:
151273
|
151274
|
151275
|
151290
|
153449
|
153450
|
153451
|
153452
|
153510
|
153525
|
153584
|
153586