From 640dfe1d371f52819e46b76b120d0f9914412131 Mon Sep 17 00:00:00 2001 From: filip Date: Thu, 17 Jul 2014 21:37:26 +0200 Subject: added caching to improve report speed --- en/about/license/license.php | 85 ++++++++++++++++++++++++++++++++++++++++++++ langs/report_test.php | 39 +++++--------------- 2 files changed, 93 insertions(+), 31 deletions(-) diff --git a/en/about/license/license.php b/en/about/license/license.php index 5745e0826..7ae6d1cd7 100644 --- a/en/about/license/license.php +++ b/en/about/license/license.php @@ -53,3 +53,88 @@ function read_license_from_vcs($locale) { return $prepared_license_strings; } + +function load_license_numbers($lang, $skip_rebuilding_cache = false) +{ + $pot_filename = 'libDrakX.pot'; + $po_files_path = "http://gitweb.mageia.org/software/drakx/plain/perl-install/share/po/"; + $cache_file = __DIR__ . '/../../../_nav/var/tmp/cache/license_numbers_' . $lang . '.php'; + $rebuild_cache = false; + date_default_timezone_set(@date_default_timezone_get()); + if($lang == 'en') { + $filename = $pot_filename; + $start_text = '"POT-Creation-Date:'; + } else { + $filename = locale_hyphen_underscore($lang, true) . '.po'; // create pt_BR.po from pt-br and alike + $start_text = '"PO-Revision-Date:'; + } + if(!$skip_rebuilding_cache) { + $po_file = $po_files_path . $filename; + $filehandle = @fopen($po_file, 'r'); // read $po_file + if($filehandle !== false) { // could open $po_fil + fclose($filehandle); + $po_time = get_po_time($po_file, $start_text); + } else { + $po_time = get_po_time($po_files_path . $pot_filename, $start_text); + if(!$po_time) { $po_time = 0; } // fallback + } + if(file_exists($cache_file)) { + include $cache_file; + if($cached_time < $po_time) { + $rebuild_cache = true; + } + } else { + $rebuild_cache = true; + } + if($rebuild_cache) { + $license_array = read_license_from_vcs($lang); + $license_numbers = array_pop($license_array); + $license_num_all = $license_numbers["all"]; + $license_num_unt = $license_numbers["untran"]; + $cache_content = <<

'downloads/get/index.php?q=Mageia-2-dual-CD.iso&d=1', // " style="display: block; @@ -372,7 +356,6 @@ $thfiles = '' . implode('', $lang_line) . '' . PHP_EOL; if (!$restore_languages && !$restore_resources) { - echo '

Note that navigation resource and license resource are currently not shown in this full report as they take a significant amount of time to process.

'; $count = ' '; } if ($restore_languages) { @@ -414,7 +397,6 @@ $times[] = time_debug('end_time'); $sum = 0; $read_license_from_vcs_ = array(); -$mognas_f_ = array(); $_diff_ = array(); foreach ($times as $time) { if($time[1] >= 0.01) { @@ -424,10 +406,6 @@ foreach ($times as $time) { if ($pos !== false) { $read_license_from_vcs_[] = array($time[0], $time[1]); } - $pos = strpos($time[0], 'mognas_f'); - if ($pos !== false) { - $mognas_f_[] = array($time[0], $time[1]); - } $pos = strpos($time[0], '_diff'); if ($pos !== false) { $_diff_[] = array($time[0], $time[1]); @@ -447,11 +425,6 @@ foreach ($read_license_from_vcs_ as $part) { } $snails_time += $read_license_from_vcs_time_sum = array_sum($read_license_from_vcs_time); -foreach ($mognas_f_ as $part) { - $mognas_f_time[] = $part[1]; -} -$snails_time += $mognas_f_time_sum = array_sum($mognas_f_time); - foreach ($_diff_ as $part) { $_diff_time[] = $part[1]; } @@ -466,8 +439,6 @@ echo '
' . PHP_EOL;
 
 echo  '
' .'rlv: '; print_r($read_license_from_vcs_time_sum) . '
' . PHP_EOL; -echo '
' .'mog: '; -print_r($mognas_f_time_sum) . '
' . PHP_EOL; echo '
' .'dif: '; print_r($_diff_time_sum) . '
' . PHP_EOL; echo '
' .'Sst: '; @@ -487,4 +458,10 @@ echo '
' . PHP_EOL; - \ No newline at end of file +