Adding config_fetch(..) universal function which accepts ConfigFetchParams, config_fetch_ex is now considered deprecated
Publish PHP Package / docker (push) Successful in 6s
Details
Publish PHP Package / docker (push) Successful in 6s
Details
This commit is contained in:
parent
37255ba9ec
commit
660f7f0c1a
|
@ -106,7 +106,8 @@ function config_pack_bundle(
|
|||
bool $use_lz4 = false,
|
||||
bool $use_config_refs = false,
|
||||
int $binary_format = 1,
|
||||
?int $version = null
|
||||
?int $version = null,
|
||||
bool $debug = true
|
||||
) : string
|
||||
{
|
||||
global $GAME_ROOT;
|
||||
|
@ -137,8 +138,9 @@ function config_pack_bundle(
|
|||
else
|
||||
throw new Exception("Unknown binary format: $binary_format");
|
||||
|
||||
echo "CONF.BUNDLE: entries " . sizeof($cache_entries) . "; total " . kb($packed_data) .
|
||||
"; format $binary_format; lz4 $use_lz4; refs $use_config_refs; CRC " . crc32($packed_data) . "\n";
|
||||
if($debug)
|
||||
echo "CONF.BUNDLE: entries " . sizeof($cache_entries) . "; total " . kb($packed_data) .
|
||||
"; format $binary_format; lz4 $use_lz4; refs $use_config_refs; CRC " . crc32($packed_data) . "\n";
|
||||
|
||||
return $packed_data;
|
||||
}
|
||||
|
@ -437,24 +439,27 @@ class ConfigFetchResult
|
|||
public array $by_alias = array();
|
||||
}
|
||||
|
||||
function config_fetch_ex(
|
||||
array $files,
|
||||
bool $force_stale = false,
|
||||
bool $verbose = false,
|
||||
//TODO: removing this will break BC, keep it for a while
|
||||
$not_used = null,
|
||||
?int $max_workers = null
|
||||
) : ConfigFetchResult
|
||||
class ConfigFetchParams
|
||||
{
|
||||
if(!$files)
|
||||
public array $files = array();
|
||||
public bool $force_stale = false;
|
||||
public bool $verbose = false;
|
||||
public ?int $max_workers = null;
|
||||
public bool $touch_files_with_includes = true;
|
||||
}
|
||||
|
||||
function config_fetch(ConfigFetchParams $params) : ConfigFetchResult
|
||||
{
|
||||
if(!$params->files)
|
||||
return new ConfigFetchResult();
|
||||
|
||||
$max_workers = $params->max_workers;
|
||||
if($max_workers === null)
|
||||
$max_workers = sizeof($files) < 20 ? 1 : 4;
|
||||
$max_workers = sizeof($params->files) < 20 ? 1 : 4;
|
||||
|
||||
$chunk_size = (int)ceil(sizeof($files)/$max_workers);
|
||||
$chunk_size = (int)ceil(sizeof($params->files)/$max_workers);
|
||||
$jobs = array();
|
||||
foreach(array_chunk($files, $chunk_size) as $idx => $chunk_files)
|
||||
foreach(array_chunk($params->files, $chunk_size) as $idx => $chunk_files)
|
||||
$jobs[] = array($idx, $chunk_files);
|
||||
|
||||
$results_by_job = null;
|
||||
|
@ -463,11 +468,11 @@ function config_fetch_ex(
|
|||
|
||||
if(!$serial)
|
||||
{
|
||||
$results_by_job = _config_worker_run_procs($jobs, $force_stale, $verbose);
|
||||
$results_by_job = _config_worker_run_procs($jobs, $params->force_stale, $params->verbose);
|
||||
//in case of any result error try serial processing
|
||||
if(array_search(false, $results_by_job, true/*strict*/) !== false)
|
||||
{
|
||||
if($verbose)
|
||||
if($params->verbose)
|
||||
echo "Result error detected, trying serial processing...\n";
|
||||
$serial = true;
|
||||
}
|
||||
|
@ -477,18 +482,37 @@ function config_fetch_ex(
|
|||
{
|
||||
$results_by_job = array();
|
||||
foreach($jobs as $job)
|
||||
$results_by_job[] = _config_worker_func($job, $force_stale, $verbose);
|
||||
$results_by_job[] = _config_worker_func($job, $params->force_stale, $params->verbose);
|
||||
}
|
||||
|
||||
list($result, $total_stales) = _config_fetch_cache_ex($results_by_job);
|
||||
list($result, $total_stales) = _config_fetch_cache_ex($results_by_job, $params->touch_files_with_includes);
|
||||
|
||||
if($verbose)
|
||||
if($params->verbose)
|
||||
echo "Miss/All: $total_stales/" . sizeof($result->all) . "\n";
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function _config_fetch_cache_ex(array $results_by_job) : array
|
||||
//TODO: deprecated function, kept for BC
|
||||
function config_fetch_ex(
|
||||
array $files,
|
||||
bool $force_stale = false,
|
||||
bool $verbose = false,
|
||||
//TODO: removing this will break BC, keepint it for a while
|
||||
$not_used = null,
|
||||
?int $max_workers = null
|
||||
) : ConfigFetchResult
|
||||
{
|
||||
$params = new ConfigFetchParams();
|
||||
$params->files = $files;
|
||||
$params->force_stale = $force_stale;
|
||||
$params->verbose = $verbose;
|
||||
$params->max_workers = $max_workers;
|
||||
|
||||
return config_fetch($params);
|
||||
}
|
||||
|
||||
function _config_fetch_cache_ex(array $results_by_job, bool $touch_files_with_includes = true) : array
|
||||
{
|
||||
$result = new ConfigFetchResult();
|
||||
$total_stales = 0;
|
||||
|
@ -516,7 +540,8 @@ function _config_fetch_cache_ex(array $results_by_job) : array
|
|||
//NOTE: let's change the mtime of the file which include other files,
|
||||
// so that on tne next build it will be 'older' than its includes
|
||||
// and won't trigger rebuild
|
||||
touch($file);
|
||||
if($touch_files_with_includes)
|
||||
touch($file);
|
||||
}
|
||||
|
||||
if($is_stale)
|
||||
|
|
Loading…
Reference in New Issue