Better ConfigGlobals
Publish PHP Package / docker (push) Successful in 6s
Details
Publish PHP Package / docker (push) Successful in 6s
Details
This commit is contained in:
parent
118fd1903d
commit
ed2e8a4cb3
|
@ -353,25 +353,22 @@ class ConfigCacheUpdateParams
|
||||||
public ConfigGlobals $globals;
|
public ConfigGlobals $globals;
|
||||||
public ConfigDirFiles $affected_files;
|
public ConfigDirFiles $affected_files;
|
||||||
public bool $verbose = false;
|
public bool $verbose = false;
|
||||||
public ?int $max_workers = null;
|
|
||||||
public bool $check_junk = true;
|
public bool $check_junk = true;
|
||||||
public int $max_errors_num = 15;
|
public int $max_errors_num = 15;
|
||||||
public bool $return_affected_entries = false;
|
public bool $return_affected_entries = false;
|
||||||
|
|
||||||
function __construct(ConfigGlobals $globals, ConfigDirFiles $affected_files,
|
function __construct(ConfigGlobals $globals, ConfigDirFiles $affected_files, bool $verbose = false)
|
||||||
bool $verbose = false, ?int $max_workers = null)
|
|
||||||
{
|
{
|
||||||
$this->globals = $globals;
|
$this->globals = $globals;
|
||||||
$this->affected_files = $affected_files;
|
$this->affected_files = $affected_files;
|
||||||
$this->verbose = $verbose;
|
$this->verbose = $verbose;
|
||||||
$this->max_workers = $max_workers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function calcMaxWorkers() : int
|
function calcMaxWorkers() : int
|
||||||
{
|
{
|
||||||
if($this->affected_files->count() < self::FILES_THRESHOLD_ONE_WORKER)
|
if($this->affected_files->count() < self::FILES_THRESHOLD_ONE_WORKER)
|
||||||
return 1;
|
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
|
function splitFilesByChunks(int $max_workers, bool $sort = true) : array
|
||||||
|
|
|
@ -11,16 +11,25 @@ require_once(__DIR__ . '/msgpack.inc.php');
|
||||||
|
|
||||||
class ConfigGlobals
|
class ConfigGlobals
|
||||||
{
|
{
|
||||||
public array $base_dirs = array();
|
public readonly array $base_dirs;
|
||||||
public ?string $worker_init_fn = null;
|
public readonly ?string $worker_init_fn;
|
||||||
public string $base_class = '\ConfBase';
|
public readonly int $workers_num;
|
||||||
public string $build_dir;
|
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->base_dirs = array_map(fn($path) => normalize_path($path), $base_dirs);
|
||||||
$this->build_dir = $build_dir;
|
$this->build_dir = $build_dir;
|
||||||
$this->worker_init_fn = $worker_init_fn;
|
$this->worker_init_fn = $worker_init_fn;
|
||||||
|
$this->workers_num = $workers_num;
|
||||||
|
$this->base_class = $base_class;
|
||||||
}
|
}
|
||||||
|
|
||||||
function initWorker(bool $is_master_proc)
|
function initWorker(bool $is_master_proc)
|
||||||
|
@ -79,15 +88,12 @@ class ConfigUpdateRequest
|
||||||
class ConfigManager
|
class ConfigManager
|
||||||
{
|
{
|
||||||
private ConfigGlobals $globals;
|
private ConfigGlobals $globals;
|
||||||
private int $workers_num;
|
|
||||||
|
|
||||||
private ConfigCache $cache;
|
private ConfigCache $cache;
|
||||||
private ?ConfigCacheFileMap $file_map;
|
private ?ConfigCacheFileMap $file_map;
|
||||||
|
|
||||||
function __construct(ConfigGlobals $globals, int $workers_num)
|
function __construct(ConfigGlobals $globals)
|
||||||
{
|
{
|
||||||
$this->globals = $globals;
|
$this->globals = $globals;
|
||||||
$this->workers_num = $workers_num;
|
|
||||||
|
|
||||||
$this->cache = new ConfigCache($globals);
|
$this->cache = new ConfigCache($globals);
|
||||||
$this->file_map = null;
|
$this->file_map = null;
|
||||||
|
@ -115,7 +121,7 @@ class ConfigManager
|
||||||
$this->file_map = $this->_tryLoadMap();
|
$this->file_map = $this->_tryLoadMap();
|
||||||
if($this->file_map === null)
|
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();
|
$this->_saveFileMap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,8 +149,7 @@ class ConfigManager
|
||||||
$update_params = new ConfigCacheUpdateParams(
|
$update_params = new ConfigCacheUpdateParams(
|
||||||
globals: $this->globals,
|
globals: $this->globals,
|
||||||
affected_files: $affected_files,
|
affected_files: $affected_files,
|
||||||
verbose: $verbose,
|
verbose: $verbose
|
||||||
max_workers: $this->workers_num
|
|
||||||
);
|
);
|
||||||
$update_result = self::_updateCache($update_params);
|
$update_result = self::_updateCache($update_params);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue