Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,6 +140,7 @@ class Self_learning_cache | |
private $pending_save = false; | ||
public $paused = false; | ||
public $empty = true; | ||
private $already_invalidated = false; | ||
|
||
/** | ||
* Constructor. Initialise our cache. | ||
|
@@ -338,6 +339,11 @@ public function invalidate() | |
return; | ||
} | ||
|
||
if ($this->already_invalidated) { | ||
This comment has been minimized.
Sorry, something went wrong.
chrisgraham
Author
Contributor
|
||
return; | ||
} | ||
$this->already_invalidated = true; | ||
|
||
if (!is_null($this->path)) { | ||
@unlink($this->path); | ||
} else { | ||
|
@@ -356,6 +362,12 @@ public static function erase_smart_cache() | |
return; | ||
} | ||
|
||
static $done_once = false; | ||
This comment has been minimized.
Sorry, something went wrong.
chrisgraham
Author
Contributor
|
||
if ($done_once) { | ||
return; | ||
} | ||
$done_once = true; | ||
|
||
$dh = @opendir(get_custom_file_base() . '/caches/self_learning'); | ||
if ($dh !== false) { | ||
while (($f = readdir($dh)) !== false) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -216,6 +216,12 @@ function erase_thumb_cache() | |
*/ | ||
function erase_cached_language() | ||
{ | ||
static $done_once = false; | ||
if ($done_once) { | ||
return; | ||
} | ||
$done_once = true; | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
chrisgraham
Author
Contributor
|
||
cms_profile_start_for('erase_cached_language'); | ||
|
||
$langs = find_all_langs(true); | ||
|
@@ -284,6 +290,16 @@ function erase_cached_templates($preserve_some = false, $only_templates = null, | |
return; // Optimisation | ||
} | ||
|
||
if ((!$rebuild_some_deleted_files) && ($preserve_some)) { | ||
static $done_sweeping_decache_already = false; | ||
if ($done_sweeping_decache_already) { | ||
return; | ||
} | ||
if (($only_templates === null) && ($raw_file_regexp === null)) { | ||
$done_sweeping_decache_already = true; | ||
} | ||
} | ||
|
||
This comment has been minimized.
Sorry, something went wrong.
chrisgraham
Author
Contributor
|
||
cms_profile_start_for('erase_cached_templates'); | ||
|
||
global $ERASED_TEMPLATES_ONCE; | ||
|
@@ -344,7 +360,7 @@ function erase_cached_templates($preserve_some = false, $only_templates = null, | |
foreach ($themes as $theme) { | ||
$using_less = | ||
(addon_installed('less')) || /*LESS-regeneration is too intensive and assumed cache-safe anyway*/ | ||
is_file(get_custom_file_base() . '/themes/' . $theme . '/css/global.less') || | ||
is_file(get_custom_file_base() . '/themes/' . $theme . '/css/global.less') || | ||
is_file(get_custom_file_base() . '/themes/' . $theme . '/css_custom/global.less'); | ||
|
||
This comment has been minimized.
Sorry, something went wrong. |
||
foreach (array_keys($langs) as $lang) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,7 +150,7 @@ function cms_file_put_contents_safe($path, $contents, $flags = 4, $retry_depth = | |
} | ||
|
||
// Find file size | ||
clearstatcache(); | ||
clearstatcache(true, $path); | ||
This comment has been minimized.
Sorry, something went wrong.
chrisgraham
Author
Contributor
|
||
$size = @filesize($path); | ||
|
||
// Special condition: File already deleted | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -414,7 +414,11 @@ function php_function_allowed($function) | |
return false; | ||
} | ||
} | ||
$cache[$function] = (@preg_match('#(\s|,|^)' . str_replace('#', '\#', preg_quote($function)) . '(\s|$|,)#', strtolower(@ini_get('disable_functions') . ',' . ini_get('suhosin.executor.func.blacklist') . ',' . ini_get('suhosin.executor.include.blacklist') . ',' . ini_get('suhosin.executor.eval.blacklist'))) == 0); | ||
This comment has been minimized.
Sorry, something went wrong.
chrisgraham
Author
Contributor
|
||
static $disabled_functions = null; | ||
if ($disabled_functions === null) { | ||
$disabled_functions = strtolower(@ini_get('disable_functions') . ',' . ini_get('suhosin.executor.func.blacklist') . ',' . ini_get('suhosin.executor.include.blacklist') . ',' . ini_get('suhosin.executor.eval.blacklist')); | ||
} | ||
$cache[$function] = (@preg_match('#(\s|,|^)' . preg_quote($function, '#') . '(\s|$|,)#', $disabled_functions) == 0); | ||
return $cache[$function]; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ function init__global2() | |
} | ||
$error_log_path = get_custom_file_base() . '/data_custom/errorlog.php'; | ||
safe_ini_set('error_log', $error_log_path); | ||
if (is_file($error_log_path) && filesize($error_log_path) < 17) { | ||
if ((is_file($error_log_path)) && (filesize($error_log_path) < 17)) { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
@file_put_contents($error_log_path, "<" . "?php return; ?" . ">\n", LOCK_EX); | ||
} | ||
|
||
|
@@ -350,7 +350,7 @@ function init__global2() | |
setlocale(LC_ALL, explode(',', do_lang('locale'))); | ||
if (substr(@strftime('%M'), 0, 2) == '??') { // Windows may do this because it can't output a utf-8 character set, so gets mangled to question marks by PHP | ||
setlocale(LC_ALL, explode(',', 'en-GB.UTF-8,en_GB.UTF-8,en-US.UTF-8,en_US.UTF-8,en.UTF-8,en-GB,en_GB,en-US,en_US,en')); // The user will have to define locale_subst correctly | ||
} | ||
} | ||
|
||
// Check RBLs | ||
$spam_check_level = get_option('spam_check_level'); | ||
|
@@ -874,6 +874,7 @@ function is_browser_decaching() | |
} | ||
|
||
if (GOOGLE_APPENGINE) { | ||
$BROWSER_DECACHEING_CACHE = false; | ||
return false; // Decaching by mistake is real-bad when Google Cloud Storage is involved | ||
This comment has been minimized.
Sorry, something went wrong.
chrisgraham
Author
Contributor
|
||
} | ||
|
||
|
@@ -883,15 +884,18 @@ function is_browser_decaching() | |
$config_file = rtrim(str_replace(array('if (!defined(\'DO_PLANNED_DECACHE\')) ', 'define(\'DO_PLANNED_DECACHE\', true);'), array('', ''), $config_file)) . "\n\n"; | ||
require_code('files'); | ||
cms_file_put_contents_safe(get_file_base() . '/_config.php', $config_file, FILE_WRITE_FIX_PERMISSIONS); | ||
$BROWSER_DECACHEING_CACHE = true; | ||
return true; | ||
} | ||
|
||
if (get_value('ran_once') === null) { // Track whether Composr has run at least once | ||
set_value('ran_once', '1'); | ||
$BROWSER_DECACHEING_CACHE = true; | ||
return true; | ||
} | ||
|
||
return false; // This technique stopped working well, Chrome sends cache-control too freely | ||
$BROWSER_DECACHEING_CACHE = false; | ||
return false; // This technique stopped working well, Chrome sends cache-control too freely | ||
|
||
/* | ||
$header_method = (array_key_exists('HTTP_CACHE_CONTROL', $_SERVER)) && ($_SERVER['HTTP_CACHE_CONTROL'] == 'no-cache') && (cms_srv('REQUEST_METHOD') != 'POST') && ((!function_exists('browser_matches'))); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2582,7 +2582,7 @@ function is_mobile($user_agent = null, $truth = false) | |
return false; | ||
} | ||
} else { | ||
if (preg_match('#(^|,)\s*' . str_replace('#', '\#', preg_quote(get_page_name())) . '\s*(,|$)#', $details['mobile_pages']) == 0 && preg_match('#(^|,)\s*' . str_replace('#', '\#', preg_quote(get_zone_name() . ':' . get_page_name())) . '\s*(,|$)#', $details['mobile_pages']) == 0) { | ||
This comment has been minimized.
Sorry, something went wrong.
chrisgraham
Author
Contributor
|
||
if (preg_match('#(^|,)\s*' . preg_quote(get_page_name(), '#') . '\s*(,|$)#', $details['mobile_pages']) == 0 && preg_match('#(^|,)\s*' . preg_quote(get_zone_name() . ':' . get_page_name(), '#') . '\s*(,|$)#', $details['mobile_pages']) == 0) { | ||
$IS_MOBILE_CACHE = false; | ||
return false; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -87,13 +87,19 @@ function _find_all_langs($even_empty_langs = false) | |
{ | ||
require_code('files'); | ||
|
||
static $cached = array(); | ||
if (isset($cached[$even_empty_langs])) { | ||
return $cached[$even_empty_langs]; | ||
} | ||
|
||
// NB: This code is heavily optimised | ||
This comment has been minimized.
Sorry, something went wrong.
chrisgraham
Author
Contributor
|
||
|
||
$_langs = array(fallback_lang() => 'lang'); | ||
|
||
if (!in_safe_mode()) { | ||
$test = persistent_cache_get('LANGS_LIST'); | ||
if ($test !== null) { | ||
$cached[$even_empty_langs] = $test; | ||
return $test; | ||
} | ||
|
||
|
@@ -160,6 +166,7 @@ function _find_all_langs($even_empty_langs = false) | |
persistent_cache_set('LANGS_LIST', $_langs); | ||
} | ||
|
||
$cached[$even_empty_langs] = $_langs; | ||
return $_langs; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,19 +79,19 @@ function require_lang_compile($codename, $lang, $type, $cache_path, $ignore_erro | |
|
||
This comment has been minimized.
Sorry, something went wrong.
chrisgraham
Author
Contributor
|
||
// Load originals | ||
$lang_file = get_file_base() . '/lang/' . $lang . '/' . filter_naughty($codename) . '.ini'; | ||
if (file_exists($lang_file)) { // Non-custom, Proper language | ||
if (is_file($lang_file)) { // Non-custom, Proper language | ||
_get_lang_file_map($lang_file, $load_target, 'strings', false, true, $lang); | ||
$bad = false; | ||
} | ||
|
||
// Load overrides now if they are there | ||
if ($type !== 'lang') { | ||
$lang_file = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini'; | ||
if ((!file_exists($lang_file)) && (get_file_base() !== get_custom_file_base())) { | ||
if ((!is_file($lang_file)) && (get_file_base() !== get_custom_file_base())) { | ||
$lang_file = get_file_base() . '/lang_custom/' . $lang . '/' . $codename . '.ini'; | ||
} | ||
} | ||
if (($type !== 'lang') && (file_exists($lang_file))) { | ||
if (($type !== 'lang') && (is_file($lang_file))) { | ||
_get_lang_file_map($lang_file, $load_target, 'strings', false, true, $lang); | ||
$bad = false; | ||
$dirty = true; // Tainted from the official pack, so can't store server wide | ||
|
@@ -103,7 +103,7 @@ function require_lang_compile($codename, $lang, $type, $cache_path, $ignore_erro | |
require_lang($codename, fallback_lang(), $type, $ignore_errors); | ||
$REQUIRE_LANG_LOOP--; | ||
$fallback_cache_path = get_custom_file_base() . '/caches/lang/' . fallback_lang() . '/' . $codename . '.lcd'; | ||
if (file_exists($fallback_cache_path)) { | ||
if (is_file($fallback_cache_path)) { | ||
require_code('files'); | ||
@copy($fallback_cache_path, $cache_path); | ||
fix_permissions($cache_path); | ||
|
@@ -203,14 +203,14 @@ function get_lang_file_section($lang, $file = null, $section = 'descriptions') | |
function get_lang_file_map($lang, $file, $non_custom = false, $apply_filter = true) | ||
{ | ||
$a = get_custom_file_base() . '/lang_custom/' . $lang . '/' . $file . '.ini'; | ||
if ((get_custom_file_base() !== get_file_base()) && (!file_exists($a))) { | ||
if ((get_custom_file_base() !== get_file_base()) && (!is_file($a))) { | ||
$a = get_file_base() . '/lang_custom/' . $lang . '/' . $file . '.ini'; | ||
} | ||
|
||
if ((!file_exists($a)) || ($non_custom)) { | ||
if ((!is_file($a)) || ($non_custom)) { | ||
$b = get_custom_file_base() . '/lang/' . $lang . '/' . $file . '.ini'; | ||
|
||
if (file_exists($b)) { | ||
if (is_file($b)) { | ||
$a = $b; | ||
} else { | ||
if ($non_custom) { | ||
|
@@ -239,7 +239,7 @@ function get_lang_file_map($lang, $file, $non_custom = false, $apply_filter = tr | |
function _get_lang_file_map($b, &$entries, $section = 'strings', $given_whole_file = false, $apply_filter = true, $lang = null) | ||
{ | ||
if (!$given_whole_file) { | ||
if (!file_exists($b)) { | ||
if (!is_file($b)) { | ||
return; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,9 +220,10 @@ public function compile_time($key, $value, $lang = null) | |
|
||
// Put in correct brand name | ||
if (!is_null($key)) { | ||
$remapping['the software'] = preg_quote(brand_name(), '#'); | ||
$remapping['the website software'] = preg_quote(brand_name(), '#'); | ||
$remapping['other webmasters'] = 'other ' . preg_quote(brand_name(), '#') . ' users'; | ||
$brand_name = brand_name(); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
$remapping['the software'] = preg_quote($brand_name, '#'); | ||
$remapping['the website software'] = preg_quote($brand_name, '#'); | ||
$remapping['other webmasters'] = 'other ' . preg_quote($brand_name, '#') . ' users'; | ||
} | ||
|
||
// Fix bad contextualisation | ||
|
@@ -247,29 +248,36 @@ public function compile_time($key, $value, $lang = null) | |
if ($is_american) { | ||
// NB: Below you will see there are exceptions, typically when the base word already naturally ends with "se" on the end, it uses "s" not "z" | ||
|
||
$value = str_replace('sation', 'zation', $value); | ||
$value = str_replace('converzation', 'conversation', $value); // Exception, put this back | ||
$value = str_replace('Converzation', 'Conversation', $value); // Exception, put this back | ||
if (strpos($value, 'sation') !== false) { | ||
This comment has been minimized.
Sorry, something went wrong.
chrisgraham
Author
Contributor
|
||
$value = str_replace('sation', 'zation', $value); | ||
$value = str_replace('converzation', 'conversation', $value); // Exception, put this back | ||
$value = str_replace('Converzation', 'Conversation', $value); // Exception, put this back | ||
} | ||
|
||
$value = str_replace('sable', 'zable', $value); | ||
$value = str_replace('dizable', 'disable', $value); // Exception, put this back | ||
$value = str_replace('Dizable', 'Disable', $value); // Exception, put this back | ||
$value = str_replace('advizable', 'advisable', $value); // Exception, put this back | ||
$value = str_replace('Advizable', 'Advisable', $value); // Exception, put this back | ||
$value = str_replace('purchazable', 'purchasable', $value); // Exception, put this back | ||
$value = str_replace('Purchazable', 'Purchasable', $value); // Exception, put this back | ||
$value = str_replace('uzable', 'usable', $value); // Exception, put this back | ||
if (strpos($value, 'sable') !== false) { | ||
$value = str_replace('sable', 'zable', $value); | ||
$value = str_replace('dizable', 'disable', $value); // Exception, put this back | ||
$value = str_replace('Dizable', 'Disable', $value); // Exception, put this back | ||
$value = str_replace('advizable', 'advisable', $value); // Exception, put this back | ||
$value = str_replace('Advizable', 'Advisable', $value); // Exception, put this back | ||
$value = str_replace('purchazable', 'purchasable', $value); // Exception, put this back | ||
$value = str_replace('Purchazable', 'Purchasable', $value); // Exception, put this back | ||
$value = str_replace('uzable', 'usable', $value); // Exception, put this back | ||
} | ||
|
||
$value = str_replace('sational', 'zational', $value); | ||
$value = str_replace('senzational', 'sensational', $value); // Exception, put this back | ||
if (strpos($value, 'sational') !== false) { | ||
$value = str_replace('sational', 'zational', $value); | ||
$value = str_replace('senzational', 'sensational', $value); // Exception, put this back | ||
} | ||
|
||
$remapping = $this->make_uncle_sam_happy; | ||
} else { | ||
$remapping = $this->the_sun_never_sets_on_the_british_empire; | ||
} | ||
|
||
$lc_value = strtolower($value); | ||
foreach ($remapping as $authentic => $perverted) { | ||
if (stripos($value, $authentic) !== false) { | ||
if (strpos($lc_value, $authentic) !== false) { | ||
$value = preg_replace( | ||
'#(^|\s)' . preg_quote($authentic, '#') . '#', | ||
'$1' . $perverted, | ||
|
1 comment
on commit f723e60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On my last live chat my Composr install was running slow on some page requests.
I have since found that this was due to my Mac's Time Machine backup running in the background (Apple's iterative backup service). As I use an SSD, it's silent - but it will saturate my I/O quite badly if that happens.
Additionally doing cam streaming can use up CPU as it has to compress the MPEG stream on the fly.
Never-the-less, it's always good to do some performance optimisation, and I've done some profiling on an "empty" cache scenario.
Here are the main issues found and fixed...
- re-reading/re-writing _config in support_smart_decaching function many times immediately after decache.sh script run (i.e. lots of unnecessary disk IO)
- slow running with comcode_whitelists addons (read_file was recalled on comcode_whitelist.txt for every bit of Comcode parsed)
- sub-optimal US English compilation (when the US English is option on language string compilation has extra overhead, and I've optimised it now)
- unneeded non-parallelised JS compile (one particular JS cache file was regenerating on the first screen after a decache, which was not necessary)
- double decaching (some unnecessary double decaching was happening after decache.sh was run; decaching has some overhead)
- clearstatcache call when writing files (this flushes out the stats cache on files, slowing the rest of the page load; only happened after decache as it rewrote the cache files - now it's changed to only clear stat caching on the file being written, for PHP5.3+)
- get_root_comcode_pages multiple calls (this method called more than once when generating site-map, now cached)
All these issues are related either to decaching, or subsequent recaching. On a normal machine it would likely be less than a second of overhead, happening at an exceptional situation. However when debugging on a machine with saturated I/O it's much more noticeable.
Unnecessary str_replace, preg_quote can handle the extra escaping.