Removing unused includes file map
Publish PHP Package / docker (push) Successful in 6s
Details
Publish PHP Package / docker (push) Successful in 6s
Details
This commit is contained in:
parent
7a19d509b1
commit
37255ba9ec
|
@ -18,8 +18,8 @@ task('config_worker', function(array $args)
|
|||
|
||||
try
|
||||
{
|
||||
list($job, $includes_map_file, $force, $verbose) = unserialize(ensure_read($in_file));
|
||||
$result = _config_worker_func($job, config_load_includes_map($includes_map_file), $force, $verbose);
|
||||
list($job, $force, $verbose) = unserialize(ensure_read($in_file));
|
||||
$result = _config_worker_func($job, $force, $verbose);
|
||||
ensure_write($out_file, serialize($result));
|
||||
}
|
||||
catch(Exception $e)
|
||||
|
@ -429,51 +429,6 @@ function config_get_tmp_build_path(string $file) : string
|
|||
return normalize_path(config_build_dir() . "/$name");
|
||||
}
|
||||
|
||||
function config_get_includes_map_path() : string
|
||||
{
|
||||
return config_build_dir() . "/includes.map";
|
||||
}
|
||||
|
||||
function config_load_includes_map(?string $file = null) : array
|
||||
{
|
||||
$file = $file ? $file : config_get_includes_map_path();
|
||||
//NOTE: workaround for Windows file locking issues
|
||||
$attempts = 3;
|
||||
while($attempts-- > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _config_load_includes_map($file);
|
||||
}
|
||||
catch(Exception $e)
|
||||
{}
|
||||
usleep(100);
|
||||
echo "Reading includes file '$file' next attempt (left $attempts) ...\n";
|
||||
}
|
||||
throw new Exception("Could not read includes file '$file'");
|
||||
}
|
||||
|
||||
function _config_load_includes_map(string $file = null) : array
|
||||
{
|
||||
$includes_map = array(array(), array());
|
||||
|
||||
if(is_file($file))
|
||||
{
|
||||
$tmp_map = @unserialize(ensure_read($file));
|
||||
if(is_array($tmp_map))
|
||||
$includes_map = $tmp_map;
|
||||
}
|
||||
|
||||
return $includes_map;
|
||||
}
|
||||
|
||||
function config_save_includes_map(array $includes_map, ?string $file = null)
|
||||
{
|
||||
$file = $file ? $file : config_get_includes_map_path();
|
||||
|
||||
ensure_write($file, serialize($includes_map));
|
||||
}
|
||||
|
||||
class ConfigFetchResult
|
||||
{
|
||||
public array $all = array();
|
||||
|
@ -486,7 +441,8 @@ function config_fetch_ex(
|
|||
array $files,
|
||||
bool $force_stale = false,
|
||||
bool $verbose = false,
|
||||
?string $includes_map_file = null,
|
||||
//TODO: removing this will break BC, keep it for a while
|
||||
$not_used = null,
|
||||
?int $max_workers = null
|
||||
) : ConfigFetchResult
|
||||
{
|
||||
|
@ -496,9 +452,6 @@ function config_fetch_ex(
|
|||
if($max_workers === null)
|
||||
$max_workers = sizeof($files) < 20 ? 1 : 4;
|
||||
|
||||
$includes_map_file = $includes_map_file ? $includes_map_file : config_get_includes_map_path();
|
||||
$includes_map = config_load_includes_map($includes_map_file);
|
||||
|
||||
$chunk_size = (int)ceil(sizeof($files)/$max_workers);
|
||||
$jobs = array();
|
||||
foreach(array_chunk($files, $chunk_size) as $idx => $chunk_files)
|
||||
|
@ -510,7 +463,7 @@ function config_fetch_ex(
|
|||
|
||||
if(!$serial)
|
||||
{
|
||||
$results_by_job = _config_worker_run_procs($jobs, $includes_map_file, $force_stale, $verbose);
|
||||
$results_by_job = _config_worker_run_procs($jobs, $force_stale, $verbose);
|
||||
//in case of any result error try serial processing
|
||||
if(array_search(false, $results_by_job, true/*strict*/) !== false)
|
||||
{
|
||||
|
@ -524,7 +477,7 @@ function config_fetch_ex(
|
|||
{
|
||||
$results_by_job = array();
|
||||
foreach($jobs as $job)
|
||||
$results_by_job[] = _config_worker_func($job, $includes_map, $force_stale, $verbose);
|
||||
$results_by_job[] = _config_worker_func($job, $force_stale, $verbose);
|
||||
}
|
||||
|
||||
list($result, $total_stales) = _config_fetch_cache_ex($results_by_job);
|
||||
|
@ -532,8 +485,6 @@ function config_fetch_ex(
|
|||
if($verbose)
|
||||
echo "Miss/All: $total_stales/" . sizeof($result->all) . "\n";
|
||||
|
||||
config_save_includes_map($includes_map, $includes_map_file);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -541,6 +492,7 @@ function _config_fetch_cache_ex(array $results_by_job) : array
|
|||
{
|
||||
$result = new ConfigFetchResult();
|
||||
$total_stales = 0;
|
||||
|
||||
foreach($results_by_job as $results)
|
||||
{
|
||||
foreach($results as $file => $item)
|
||||
|
@ -556,7 +508,6 @@ function _config_fetch_cache_ex(array $results_by_job) : array
|
|||
}
|
||||
|
||||
$includes = $cache_entry->includes;
|
||||
$includes_map[$file] = $includes;
|
||||
|
||||
if(!$is_stale && count($includes) > 0 && need_to_regen($file, $includes))
|
||||
{
|
||||
|
@ -583,16 +534,16 @@ function _config_fetch_cache_ex(array $results_by_job) : array
|
|||
return array($result, $total_stales);
|
||||
}
|
||||
|
||||
function _config_worker_run_procs(array $jobs, string $includes_map_file, bool $force, bool $verbose) : array
|
||||
function _config_worker_run_procs(array $jobs, bool $force, bool $verbose) : array
|
||||
{
|
||||
$worker_args = array();
|
||||
foreach($jobs as $idx => $job)
|
||||
$worker_args[] = array($job, $includes_map_file, $force, $verbose);
|
||||
$worker_args[] = array($job, $force, $verbose);
|
||||
|
||||
return run_background_gamectl_workers('config_worker', $worker_args);
|
||||
}
|
||||
|
||||
function _config_worker_func(array $job, array $includes_map, bool $force, bool $verbose) : array
|
||||
function _config_worker_func(array $job, bool $force, bool $verbose) : array
|
||||
{
|
||||
global $CONFIG_INIT_WORKER_FUNC;
|
||||
if(is_callable($CONFIG_INIT_WORKER_FUNC))
|
||||
|
@ -612,12 +563,7 @@ function _config_worker_func(array $job, array $includes_map, bool $force, bool
|
|||
|
||||
$is_stale = true;
|
||||
if(!$force)
|
||||
{
|
||||
$file_deps = array($file);
|
||||
if(isset($includes_map[$file]))
|
||||
$file_deps = array_merge($file_deps, $includes_map[$file]);
|
||||
$is_stale = need_to_regen($cache_file, $file_deps);
|
||||
}
|
||||
$is_stale = need_to_regen($cache_file, array($file));
|
||||
|
||||
if($is_stale)
|
||||
_config_invalidate_cache($file, $cache_file);
|
||||
|
|
Loading…
Reference in New Issue