Getting rid of config_update_cache, moving it into ConfigManager
This commit is contained in:
parent
fc0aa1636e
commit
0c7f8f3d06
|
@ -332,6 +332,7 @@ class ConfigCacheFileMap
|
|||
class ConfigCacheUpdateResult
|
||||
{
|
||||
public ConfigDirFiles $affected_files;
|
||||
public array $affected_entries = array();
|
||||
|
||||
/** @var array<string, string> */
|
||||
public array $errors = array();
|
||||
|
@ -354,6 +355,8 @@ class ConfigCacheUpdateParams
|
|||
public bool $verbose = false;
|
||||
public ?int $max_workers = null;
|
||||
public bool $check_junk = true;
|
||||
public int $max_errors_num = 15;
|
||||
public bool $return_affected_entries = false;
|
||||
|
||||
function __construct(ConfigGlobals $globals, ConfigDirFiles $affected_files,
|
||||
bool $verbose = false, ?int $max_workers = null)
|
||||
|
@ -422,34 +425,6 @@ function _config_cache_update(ConfigCacheUpdateParams $params) : ConfigCacheUpda
|
|||
return $result;
|
||||
}
|
||||
|
||||
function config_cache_update(ConfigCacheUpdateParams $params) : ConfigCacheUpdateResult
|
||||
{
|
||||
if($params->affected_files->isEmpty())
|
||||
return new ConfigCacheUpdateResult($params);
|
||||
|
||||
$t = microtime(true);
|
||||
|
||||
$result = _config_cache_update($params);
|
||||
|
||||
if($result->errors)
|
||||
{
|
||||
$errors = array();
|
||||
foreach($result->errors as $file => $error)
|
||||
{
|
||||
$errors[] = (count($errors) + 1) . ") Error in file '$file': $error";
|
||||
if(count($errors) > 15)
|
||||
break;
|
||||
}
|
||||
|
||||
throw new Exception(implode("\n", $errors));
|
||||
}
|
||||
|
||||
if($params->verbose)
|
||||
config_log("Update cache: " . round(microtime(true) - $t,2) . " sec.");
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function _config_merge_update_results(ConfigCacheUpdateParams $params, array $results_by_job) : ConfigCacheUpdateResult
|
||||
{
|
||||
$result = new ConfigCacheUpdateResult($params);
|
||||
|
|
|
@ -117,16 +117,17 @@ class ConfigManager
|
|||
{
|
||||
if($this->file_map === null)
|
||||
{
|
||||
$map = $this->_tryLoadMap();
|
||||
if($map === null)
|
||||
$map = self::_makeMap($files ?? $this->scanFiles(extension: '.js'));
|
||||
$this->file_map = $map;
|
||||
$this->_saveFileMap();
|
||||
$this->file_map = $this->_tryLoadMap();
|
||||
if($this->file_map === null)
|
||||
{
|
||||
$this->file_map = self::_makeMap($files ?? $this->scanFiles(extension: '.js'));
|
||||
$this->_saveFileMap();
|
||||
}
|
||||
}
|
||||
return $this->file_map;
|
||||
}
|
||||
|
||||
function updateCache(ConfigUpdateRequest $req, bool $verbose = false) : ConfigCacheUpdateResult
|
||||
function updateCache(ConfigUpdateRequest $req, bool $return_entries = false, bool $verbose = false) : ConfigCacheUpdateResult
|
||||
{
|
||||
config_log("Updating cache, mode '{$req->mode->name}'...");
|
||||
|
||||
|
@ -150,15 +151,52 @@ class ConfigManager
|
|||
verbose: $verbose,
|
||||
max_workers: $this->workers_num
|
||||
);
|
||||
$update_result = config_cache_update($update_params);
|
||||
$update_result = self::_updateCache($update_params);
|
||||
|
||||
$this->cache->clear();
|
||||
|
||||
$this->_updateFileMap($req, $affected_files, $added_files, $removed_files);
|
||||
|
||||
if($return_entries)
|
||||
{
|
||||
foreach($affected_files as $file)
|
||||
{
|
||||
$entry = $this->cache->getOrLoadByPath($file);
|
||||
$update_result->affected_entries[] = $entry;
|
||||
}
|
||||
}
|
||||
|
||||
return $update_result;
|
||||
}
|
||||
|
||||
private function _updateCache(ConfigCacheUpdateParams $params) : ConfigCacheUpdateResult
|
||||
{
|
||||
if($params->affected_files->isEmpty())
|
||||
return new ConfigCacheUpdateResult($params);
|
||||
|
||||
$t = microtime(true);
|
||||
|
||||
$result = _config_cache_update($params);
|
||||
|
||||
if($result->errors)
|
||||
{
|
||||
$errors = array();
|
||||
foreach($result->errors as $file => $error)
|
||||
{
|
||||
$errors[] = (count($errors) + 1) . ") Error in file '$file': $error";
|
||||
if(count($errors) > $params->max_errors_num)
|
||||
break;
|
||||
}
|
||||
|
||||
throw new Exception(implode("\n", $errors));
|
||||
}
|
||||
|
||||
if($params->verbose)
|
||||
config_log("Update cache: " . round(microtime(true) - $t,2) . " sec.");
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function _checkFileMap(ConfigUpdateRequest $req, array &$added_files, array &$removed_files)
|
||||
{
|
||||
$fs_cache_map = $this->getFileMap();
|
||||
|
@ -293,7 +331,9 @@ class ConfigManager
|
|||
|
||||
private function _saveFileMap()
|
||||
{
|
||||
ensure_write($this->_getMapPath(), ConfigCacheFileMap::serialize($this->getFileMap()));
|
||||
$data = ConfigCacheFileMap::serialize($this->getFileMap());
|
||||
config_log("Saving file map: " . kb($data));
|
||||
ensure_write($this->_getMapPath(), $data);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue