Skip to content

Commit

Permalink
* Generation times shouldn't take into account the time needed to gen…
Browse files Browse the repository at this point in the history
…erate a cached CSS or JS file. These operations only happen when you update a CSS or JS file, which should be rare enough if you don't update your site every other minute. (Subs-Cache.php)

* Also added a warning about Wess breaking calc() calls if they include a + or - sign. Sorry about that, will look into fixing it in the future. (Subs-Cache.php)
  • Loading branch information
Nao committed Aug 11, 2014
1 parent 298d4fc commit 3f4cfeb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions core/app/Subs-Cache.php
Expand Up @@ -575,7 +575,7 @@ function wedge_get_css_filename($add)
*/
function wedge_cache_css_files($folder, $ids, $latest_date, $css, $gzip = false, $ext = '.css', $additional_vars = array())
{
global $css_vars, $context, $settings;
global $css_vars, $context, $settings, $time_start;

$final_folder = substr(CACHE_DIR . '/css/' . $folder, 0, -1);
$cachekey = 'css_files-' . $folder . implode('-', $ids);
Expand All @@ -593,6 +593,7 @@ function wedge_cache_css_files($folder, $ids, $latest_date, $css, $gzip = false,
return $folder . $full_name;
}

$sleep_time = microtime(true);
we::$user['extra_tests'] = array();

if (!empty($folder) && $folder != '/' && !file_exists($final_folder))
Expand Down Expand Up @@ -718,7 +719,8 @@ function wedge_cache_css_files($folder, $ids, $latest_date, $css, $gzip = false,
// Remove the 'final' keyword.
$final = preg_replace('~\s+final\b~', '', $final);

// Remove extra whitespace.
// Remove extra whitespace. Note that this breaks additions and substractions in calc(), as they need their own whitespace.
// I'll be fixing this, eventually. But needs more regexes, more CPU time, and this means more kitties getting slaughtered. :(
$final = preg_replace('~\s*([][+:;,>{}\s])\s*~', '$1', $final);

// This is a bit quirky, like me, as we want to simplify paths but may still break non-path strings in the process.
Expand Down Expand Up @@ -799,6 +801,9 @@ function wedge_cache_css_files($folder, $ids, $latest_date, $css, $gzip = false,

@file_put_contents($final_file, $final);

// Don't take generation times into account for our stats. It's only done once in a while anyway...
$time_start += microtime(true) - $sleep_time;

return $folder . $full_name;
}

Expand Down Expand Up @@ -982,9 +987,10 @@ function array_search_key($needle, &$arr)
*/
function wedge_cache_js($id, &$lang_name, $latest_date, $ext, $js, $gzip = false, $full_path = false)
{
global $settings, $comments, $txt;
global $settings, $comments, $txt, $time_start;
static $closure_failed = false;

$sleep_time = microtime(true);
$final = '';
$dir = $full_path ? '' : ROOT_DIR . '/core/javascript/';
$no_packing = array();
Expand Down Expand Up @@ -1251,7 +1257,10 @@ function ($match) { return !empty(we::$is[$match[1]]) ? $match[3] : (isset($matc
if ($gzip)
$final = gzencode($final, 9);

file_put_contents(CACHE_DIR . '/js/' . $id . $lang_name . $latest_date . $ext, $final);
@file_put_contents(CACHE_DIR . '/js/' . $id . $lang_name . $latest_date . $ext, $final);

// Don't take generation times into account for our stats. It's only done once in a while anyway...
$time_start += microtime(true) - $sleep_time;
}

/**
Expand Down

0 comments on commit 3f4cfeb

Please sign in to comment.