Better ConfigGlobals
Publish PHP Package / docker (push) Successful in 6s Details

This commit is contained in:
Pavel Shevaev 2025-04-17 19:15:42 +03:00
parent 118fd1903d
commit ed2e8a4cb3
2 changed files with 19 additions and 17 deletions

View File

@ -353,25 +353,22 @@ class ConfigCacheUpdateParams
public ConfigGlobals $globals;
public ConfigDirFiles $affected_files;
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)
function __construct(ConfigGlobals $globals, ConfigDirFiles $affected_files, bool $verbose = false)
{
$this->globals = $globals;
$this->affected_files = $affected_files;
$this->verbose = $verbose;
$this->max_workers = $max_workers;
}
function calcMaxWorkers() : int
{
if($this->affected_files->count() < self::FILES_THRESHOLD_ONE_WORKER)
return 1;
return $this->max_workers ?? self::MAX_DEFAULT_WORKERS;
return $this->globals->max_workers ?? self::MAX_DEFAULT_WORKERS;
}
function splitFilesByChunks(int $max_workers, bool $sort = true) : array

View File

@ -11,16 +11,25 @@ require_once(__DIR__ . '/msgpack.inc.php');
class ConfigGlobals
{
public array $base_dirs = array();
public ?string $worker_init_fn = null;
public string $base_class = '\ConfBase';
public string $build_dir;
public readonly array $base_dirs;
public readonly ?string $worker_init_fn;
public readonly int $workers_num;
public readonly string $base_class;
public readonly string $build_dir;
function __construct(array $base_dirs, string $build_dir, ?string $worker_init_fn = null)
function __construct(
array $base_dirs,
string $build_dir,
?string $worker_init_fn = null,
int $workers_num = 1,
string $base_class = '\ConfBase'
)
{
$this->base_dirs = array_map(fn($path) => normalize_path($path), $base_dirs);
$this->build_dir = $build_dir;
$this->worker_init_fn = $worker_init_fn;
$this->workers_num = $workers_num;
$this->base_class = $base_class;
}
function initWorker(bool $is_master_proc)
@ -79,15 +88,12 @@ class ConfigUpdateRequest
class ConfigManager
{
private ConfigGlobals $globals;
private int $workers_num;
private ConfigCache $cache;
private ?ConfigCacheFileMap $file_map;
function __construct(ConfigGlobals $globals, int $workers_num)
function __construct(ConfigGlobals $globals)
{
$this->globals = $globals;
$this->workers_num = $workers_num;
$this->cache = new ConfigCache($globals);
$this->file_map = null;
@ -115,7 +121,7 @@ class ConfigManager
$this->file_map = $this->_tryLoadMap();
if($this->file_map === null)
{
$this->file_map = self::_makeMap($files ?? $this->scanFiles(extension: '.js'));
$this->file_map = self::_makeMap($this->scanFiles(extension: '.js'));
$this->_saveFileMap();
}
}
@ -143,8 +149,7 @@ class ConfigManager
$update_params = new ConfigCacheUpdateParams(
globals: $this->globals,
affected_files: $affected_files,
verbose: $verbose,
max_workers: $this->workers_num
verbose: $verbose
);
$update_result = self::_updateCache($update_params);