Bugzilla – Attachment 58270 Details for
Bug 17783
Optimize Koha::IssuingRules->get_effective_issuing_rule
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[SIGNED-OFF] Bug 17783: Add Koha::Objects->single
SIGNED-OFF-Bug-17783-Add-KohaObjects-single.patch (text/plain), 3.06 KB, created by
Josef Moravec
on 2016-12-18 19:50:39 UTC
(
hide
)
Description:
[SIGNED-OFF] Bug 17783: Add Koha::Objects->single
Filename:
MIME Type:
Creator:
Josef Moravec
Created:
2016-12-18 19:50:39 UTC
Size:
3.06 KB
patch
obsolete
>From b5e653ad9149d1207ab1e9e8df5e8e42b5eab43d Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@jns.fi> >Date: Thu, 15 Dec 2016 19:28:38 +0200 >Subject: [PATCH] [SIGNED-OFF] Bug 17783: Add Koha::Objects->single > >Returns one and only one object that is part of this set. >Returns undef if there are no objects found. > >->single is faster than ->search->next > >This is optimal as it will grab the first returned result without instantiating >a cursor. > >It is useful for this Bug as we only want to select the top row of found issuing >rules. > >To test: >1. Run t/db_dependent/Koha/Objects.t > >Signed-off-by: Josef Moravec <josef.moravec@gmail.com> >--- > Koha/Objects.pm | 26 +++++++++++++++++++++++++- > t/db_dependent/Koha/Objects.t | 13 ++++++++++++- > 2 files changed, 37 insertions(+), 2 deletions(-) > >diff --git a/Koha/Objects.pm b/Koha/Objects.pm >index 56f165c..9231206 100644 >--- a/Koha/Objects.pm >+++ b/Koha/Objects.pm >@@ -161,6 +161,30 @@ sub search_related { > } > } > >+=head3 single >+ >+my $object = Koha::Objects->search({}, { rows => 1 })->single >+ >+Returns one and only one object that is part of this set. >+Returns undef if there are no objects found. >+ >+This is optimal as it will grab the first returned result without instantiating >+a cursor. >+ >+See: >+http://search.cpan.org/dist/DBIx-Class/lib/DBIx/Class/Manual/Cookbook.pod#Retrieve_one_and_only_one_row_from_a_resultset >+ >+=cut >+ >+sub single { >+ my ($self) = @_; >+ >+ my $single = $self->_resultset()->single; >+ return unless $single; >+ >+ return $self->object_class()->_new_from_dbic($single); >+} >+ > =head3 Koha::Objects->next(); > > my $object = Koha::Objects->next(); >@@ -299,7 +323,7 @@ Currently count, pager, update and delete are covered. > sub AUTOLOAD { > my ( $self, @params ) = @_; > >- my @known_methods = qw( count pager update delete result_class ); >+ my @known_methods = qw( count pager update delete result_class single ); > my $method = our $AUTOLOAD; > $method =~ s/.*:://; > >diff --git a/t/db_dependent/Koha/Objects.t b/t/db_dependent/Koha/Objects.t >index 84b1a86..29dea67 100644 >--- a/t/db_dependent/Koha/Objects.t >+++ b/t/db_dependent/Koha/Objects.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 10; >+use Test::More tests => 11; > use Test::Warn; > > use Koha::Authority::Types; >@@ -116,6 +116,17 @@ subtest 'search_related' => sub { > is( $libraries[1]->branchcode, $patron_2->{branchcode}, 'Koha::Objects->search_related should work as expected' ); > }; > >+subtest 'single' => sub { >+ plan tests => 2; >+ my $builder = t::lib::TestBuilder->new; >+ my $patron_1 = $builder->build( { source => 'Borrower' } ); >+ my $patron_2 = $builder->build( { source => 'Borrower' } ); >+ my $patron = Koha::Patrons->search({}, { rows => 1 })->single; >+ is(ref($patron), 'Koha::Patron', 'Koha::Objects->single returns a single Koha::Patron object.'); >+ warning_like { Koha::Patrons->search->single } qr/SQL that returns multiple rows/, >+ "Warning is presented if single is used for a result with multiple rows."; >+}; >+ > subtest 'Exceptions' => sub { > plan tests => 2; > >-- >2.1.4
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 17783
:
58228
|
58229
|
58230
|
58231
|
58268
|
58269
|
58270
|
58271
|
58300
|
58304
|
58309
|
58310
|
58311
|
58312
|
58313
|
58314