From cc0867d8996292f475ffc0832f919a4ad260067f Mon Sep 17 00:00:00 2001 From: Julian FIOL Date: Fri, 15 May 2015 12:06:01 +0200 Subject: [PATCH] [SIGNED-OFF] Bug 14207: Improving circulation performance by caching yaml file This patch improve circulation performance by caching yaml file With this patch we saved between 300ms and 500ms on circulation page. Signed-off-by: Bernardo Gonzalez Kriegel Times can be different, but is a gain anyway. Work as described following test plan (pdf) No koha-qa errors --- C4/Utils/DataTables/ColumnsSettings.pm | 38 ++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/C4/Utils/DataTables/ColumnsSettings.pm b/C4/Utils/DataTables/ColumnsSettings.pm index ed8d9ac..17b5f6a 100644 --- a/C4/Utils/DataTables/ColumnsSettings.pm +++ b/C4/Utils/DataTables/ColumnsSettings.pm @@ -5,14 +5,22 @@ use List::Util qw( first ); use YAML; use C4::Context; use Koha::Database; +use Koha::Cache; sub get_yaml { - my $yml_path = - C4::Context->config('intranetdir') . '/admin/columns_settings.yml'; - my $yaml = eval { YAML::LoadFile($yml_path) }; - warn -"ERROR: the yaml file for DT::ColumnsSettings is not correctly formated: $@" - if $@; + my $yml_path = C4::Context->config('intranetdir') . '/admin/columns_settings.yml'; + + my $cache = Koha::Cache->get_instance(); + my $yaml = $cache->get_from_cache('ColumnsSettingsYaml'); + unless ($yaml) { + $yaml = eval { YAML::LoadFile($yml_path) }; + warn "############################# Not In Cache #############################" if $ENV{DEBUG}; + warn "ERROR: the yaml file for DT::ColumnsSettings is not correctly formated: $@" + if $@; + $cache->set_in_cache( 'ColumnsSettingsYaml', $yaml, { expiry => 3600 } ); + } else { + warn "############################# In Cache #############################" if $ENV{DEBUG}; + } return $yaml; } @@ -24,16 +32,14 @@ sub get_columns { my $schema = Koha::Database->new->schema; my $rs = $schema->resultset('ColumnsSetting')->search( - { - module => $module, + { module => $module, page => $page, tablename => $tablename, } ); while ( my $c = $rs->next ) { - my $column = first { $c->columnname eq $_->{columnname} } - @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; + my $column = first { $c->columnname eq $_->{columnname} } @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; $column->{is_hidden} = $c->is_hidden; $column->{cannot_be_toggled} = $c->cannot_be_toggled; } @@ -48,8 +54,7 @@ sub get_modules { my $rs = $schema->resultset('ColumnsSetting')->search; while ( my $c = $rs->next ) { - my $column = first { $c->columnname eq $_->{columnname} } - @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; + my $column = first { $c->columnname eq $_->{columnname} } @{ $list->{modules}{ $c->module }{ $c->page }{ $c->tablename } }; $column->{is_hidden} = $c->is_hidden; $column->{cannot_be_toggled} = $c->cannot_be_toggled; } @@ -68,11 +73,10 @@ sub update_columns { $c->{cannot_be_toggled} //= 0; $schema->resultset('ColumnsSetting')->update_or_create( - { - module => $c->{module}, - page => $c->{page}, - tablename => $c->{tablename}, - columnname => $c->{columnname}, + { module => $c->{module}, + page => $c->{page}, + tablename => $c->{tablename}, + columnname => $c->{columnname}, is_hidden => $c->{is_hidden}, cannot_be_toggled => $c->{cannot_be_toggled}, } -- 1.7.9.5