Bug 14207: Improving circulation performance
authorJulian FIOL <julian.fiol@biblibre.com>
Tue, 26 May 2015 12:49:20 +0000 (14:49 +0200)
committerTomas Cohen Arazi <tomascohen@unc.edu.ar>
Tue, 7 Jul 2015 18:23:48 +0000 (15:23 -0300)
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.

Following Comment #3 :
No useless warn
No tidy

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Less lines, same result.
Comments were useful on testing :)
No errors

Signed-off-by: Jonathan Druart <jonathan.druart@koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@unc.edu.ar>
C4/Utils/DataTables/ColumnsSettings.pm

index c84f157..eb0ca54 100644 (file)
@@ -5,14 +5,20 @@ 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 formatted: $@"
-      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 "ERROR: the yaml file for DT::ColumnsSettings is not correctly formated: $@"
+          if $@;
+        $cache->set_in_cache( 'ColumnsSettingsYaml', $yaml, { expiry => 3600 } );
+    }
+
     return $yaml;
 }