https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=29953
Bug ID: 29953 Summary: Possible inefficiency in REST API for biblios endpoint Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: REST API Assignee: koha-bugs@lists.koha-community.org Reporter: dc...@prosentient.com.au CC: tomasco...@gmail.com I was looking at Koha/REST/V1/Biblios.pm because of bug 28201 when I noticed it looks like we're running $record->$method calls more than we need to in the "get" function. Consider the following block of code: if ( $c->req->headers->accept =~ m/application\/json/ ) { return $c->render( status => 200, json => $biblio->to_api ); } else { my $record = $biblio->metadata->record; $c->respond_to( marcxml => { status => 200, format => 'marcxml', text => $record->as_xml_record }, mij => { status => 200, format => 'mij', text => $record->to_mij }, marc => { status => 200, format => 'marc', text => $record->as_usmarc }, txt => { status => 200, format => 'text/plain', text => $record->as_formatted }, any => { status => 406, openapi => [ "application/json", "application/marcxml+xml", "application/marc-in-json", "application/marc", "text/plain" ] } ); } If there is an Accept header for application/json, then we run $biblio->to_api, and that's it. However, if there isn't an Accept header for application/json, it looks like we create a hash of hashrefs that output the $record in 4 different formats. I think it would make more sense (based on what I see in https://docs.mojolicious.org/Mojolicious/Plugin/DefaultHelpers#respond_to) to provide anonymous functions instead of hashrefs so that $record->$method calls are only run when a specific format is actually chosen by Mojolicious. In terms of performance, it might be only a marginal gain, but if you're doing a lot of API calls, small gains can translate into large scale time savings. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes. _______________________________________________ Koha-bugs mailing list Koha-bugs@lists.koha-community.org https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-bugs website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/