Bugzilla – Attachment 152995 Details for
Bug 34088
Schema upgrade should short circuit faster if no upgrade needs to be done
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34088: Short circuit database upgrade check
Bug-34088-Short-circuit-database-upgrade-check.patch (text/plain), 3.50 KB, created by
David Cook
on 2023-07-04 00:57:27 UTC
(
hide
)
Description:
Bug 34088: Short circuit database upgrade check
Filename:
MIME Type:
Creator:
David Cook
Created:
2023-07-04 00:57:27 UTC
Size:
3.50 KB
patch
obsolete
>From 9d9a47b5ca1d408578aff7c28e95be8d54685b0c Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Thu, 22 Jun 2023 00:56:12 +0000 >Subject: [PATCH] Bug 34088: Short circuit database upgrade check > >If the database version and the code version are the same, we should >short circuit and exit immediately. > >This patch adds the Koha::Installer module which can very quickly >check if an update is needed (based off database version and code >version). > >It also moves the logic for C4::Installer::TransformToNum to >Koha::Installer::TransformToNum for performance reasons. > >Test plan: >1. Apply patch >2. Run `time koha-upgrade-schema kohadev` >3. Note that it completes in less than .1 seconds >4. To test C4::Installer, change the database Version to a number >slightly behind the code version, and run >`time koha-upgrade-schema kohadev` >5. Note that the correct version update is processed >--- > C4/Installer.pm | 8 ++--- > Koha/Installer.pm | 44 ++++++++++++++++++++++++++ > installer/data/mysql/updatedatabase.pl | 7 ++++ > 3 files changed, 53 insertions(+), 6 deletions(-) > create mode 100644 Koha/Installer.pm > >diff --git a/C4/Installer.pm b/C4/Installer.pm >index 9a587cac0f..55a99e4787 100644 >--- a/C4/Installer.pm >+++ b/C4/Installer.pm >@@ -29,6 +29,7 @@ use DBI; > use C4::Context; > use Koha::Schema; > use Koha; >+use Koha::Installer; > > use vars qw(@ISA @EXPORT); > BEGIN { >@@ -929,12 +930,7 @@ to a number, with just 1 . > > sub TransformToNum { > my $version = shift; >- # remove the 3 last . to have a Perl number >- $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; >- # three X's at the end indicate that you are testing patch with dbrev >- # change it into 999 >- # prevents error on a < comparison between strings (should be: lt) >- $version =~ s/XXX$/999/; >+ $version = Koha::Installer::TransformToNum($version); > return $version; > } > >diff --git a/Koha/Installer.pm b/Koha/Installer.pm >new file mode 100644 >index 0000000000..ab63659b7b >--- /dev/null >+++ b/Koha/Installer.pm >@@ -0,0 +1,44 @@ >+package Koha::Installer; >+ >+use Modern::Perl; >+ >+require Koha; >+require Koha::Database; >+ >+sub needs_update { >+ my $dbh = Koha::Database::dbh(); >+ my $sql = "SELECT value FROM systempreferences WHERE variable = 'Version'"; >+ my $sth = $dbh->prepare($sql); >+ $sth->execute(); >+ my $row = $sth->fetchrow_arrayref(); >+ my $db_version = $row->[0]; >+ my $koha_version = Koha->version; >+ my $code_version = TransformToNum($koha_version); >+ >+ if ( $db_version == $code_version ) { >+ return; >+ } >+ return 1; >+} >+ >+=head2 TransformToNum >+ >+Transform the Koha version from a 4 parts string >+to a number, with just 1 . >+ >+=cut >+ >+sub TransformToNum { >+ my $version = shift; >+ >+ # remove the 3 last . to have a Perl number >+ $version =~ s/(.*\..*)\.(.*)\.(.*)/$1$2$3/; >+ >+ # three X's at the end indicate that you are testing patch with dbrev >+ # change it into 999 >+ # prevents error on a < comparison between strings (should be: lt) >+ $version =~ s/XXX$/999/; >+ return $version; >+} >+ >+1; >diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl >index 06f98e8e61..b3e5db9ce5 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -27,6 +27,13 @@ > > # NOTE: Please keep the version in kohaversion.pl up-to-date! > >+BEGIN { >+ use Koha::Installer; >+ if ( !Koha::Installer->needs_update ) { >+ exit; >+ } >+} >+ > use Modern::Perl; > > use feature 'say'; >-- >2.30.2
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 34088
:
152543
|
152995
|
152996
|
152997
|
152998
|
154230
|
170554
|
170555
|
171050
|
174441
|
174443