Summary: | Inappropriate uses of $sth->finish() in C4::ClassSource.pm | ||
---|---|---|---|
Product: | Koha | Reporter: | kenza <kenza.zaki> |
Component: | Architecture, internals, and plumbing | Assignee: | kenza <kenza.zaki> |
Status: | CLOSED FIXED | QA Contact: | Testopia <testopia> |
Severity: | normal | ||
Priority: | P5 - low | CC: | bgkriegel, chrish, gmcharlt, kenza.zaki, srdjan, tomascohen |
Version: | Main | ||
Hardware: | All | ||
OS: | All | ||
GIT URL: | Change sponsored?: | --- | |
Patch complexity: | --- | Documentation contact: | |
Documentation submission: | Text to go in the release notes: | ||
Version(s) released in: | Circulation function: | ||
Attachments: |
Bug 10643: Inappropriate uses of $sth->finish() in C4::ClassSource.pm
Bug 10643: Inappropriate uses of $sth->finish() in C4::ClassSource.pm [SIGNED-OFF] Bug 10643: Inappropriate uses of $sth->finish() in C4::ClassSource.pm Bug 10643: Inappropriate uses of $sth->finish() in C4::ClassSource.pm |
Description
kenza
2013-07-25 11:54:58 UTC
Created attachment 19948 [details] [review] Bug 10643: Inappropriate uses of $sth->finish() in C4::ClassSource.pm From the man page finish() Indicate that no more data will be fetched from this statement handle before it is either executed again or destroyed. You almost certainly do not need to call this method. Adding calls to "finish" after loop that fetches all rows is a common mistake, don't do it, it can mask genuine problems like uncaught fetch errors. I propose something even better then - get rid of prepare() all together. For example: * GetClassSources(): return $dbh->selectall_hashref("SELECT...", undef, 'cn_source'); * AddClassSource() return $dbh->do("INSERT...", undef, @params) etc. How often are those used to get advantage of prepare_cached()? Good databases (tm) cache queries anyway, however not sure that MySQL does. (In reply to Srdjan Jankovic from comment #2) > I propose something even better then - get rid of prepare() all together. > For example: > > * GetClassSources(): > return $dbh->selectall_hashref("SELECT...", undef, 'cn_source'); > > * AddClassSource() > return $dbh->do("INSERT...", undef, @params) > > etc. How often are those used to get advantage of prepare_cached()? > Good databases (tm) cache queries anyway, however not sure that MySQL does. Getting rid of $sth->finish() and replacing prepare_cached() with prepare() suffices as a minimal change, but doesn't preclude going further and using selectall_hashref. As far as the current patch is concerned, I do think it would be useful to at least get rid of prepare_cached(). Created attachment 20105 [details] [review] Bug 10643: Inappropriate uses of $sth->finish() in C4::ClassSource.pm This patch gets rid of finish() and replace prepare_cached by prepare. From the man page finish() Indicate that no more data will be fetched from this statement handle before it is either executed again or destroyed. You almost certainly do not need to call this method. Adding calls to "finish" after loop that fetches all rows is a common mistake, don't do it, it can mask genuine problems like uncaught fetch errors. None of these "$sth->finish()" patches have a test plan. I assume there's no way to detect an improvement, but how can we confirm that this change hasn't broken anything? (In reply to Owen Leonard from comment #5) > None of these "$sth->finish()" patches have a test plan. I assume there's no > way to detect an improvement, but how can we confirm that this change hasn't > broken anything? For this patch , the t/db_dependent/ClassSource.t exists. So we can be sure that nothing is broken by doing 'prove t/db_dependent/ClassSource.t' after applying this patch: t/db_dependent/ClassSource.t .. 1/24 attempting to use non-existent class sorting routine routine1 t/db_dependent/ClassSource.t .. ok All tests successful. Files=1, Tests=24, 0 wallclock secs ( 0.02 usr 0.00 sys + 0.06 cusr 0.01 csys = 0.09 CPU) Result: PASS Created attachment 20120 [details] [review] [SIGNED-OFF] Bug 10643: Inappropriate uses of $sth->finish() in C4::ClassSource.pm This patch gets rid of finish() and replace prepare_cached by prepare. From the man page finish() Indicate that no more data will be fetched from this statement handle before it is either executed again or destroyed. You almost certainly do not need to call this method. Adding calls to "finish" after loop that fetches all rows is a common mistake, don't do it, it can mask genuine problems like uncaught fetch errors. Signed-off-by: Srdjan <srdjan@catalyst.net.nz> Created attachment 20236 [details] [review] Bug 10643: Inappropriate uses of $sth->finish() in C4::ClassSource.pm This patch gets rid of finish() and replace prepare_cached by prepare. From the man page finish() Indicate that no more data will be fetched from this statement handle before it is either executed again or destroyed. You almost certainly do not need to call this method. Adding calls to "finish" after loop that fetches all rows is a common mistake, don't do it, it can mask genuine problems like uncaught fetch errors. Signed-off-by: Srdjan <srdjan@catalyst.net.nz> Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com> Pushed to master. Thanks, Kenza! I notice, however, that the author line is wrong: root <root@kenza-VirtualBox> Please use git config to set its user.name and user.email attributes to your correct name and email address. This patch has been pushed to 3.12.x, will be in 3.12.4. Thanks Kenza! Pushed to 3.10.x, will be in 3.10.11 Pushed to 3.8.x, will be in 3.8.18 |