feat(updater): optional httpCheck + IA optimisations
Some checks are pending
/ test (push) Waiting to run
Some checks are pending
/ test (push) Waiting to run
This commit is contained in:
parent
48ff8144fe
commit
1fcf0bf1da
2 changed files with 87 additions and 28 deletions
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
require 'vendor/autoload.php';
|
require 'vendor/autoload.php';
|
||||||
|
|
||||||
use Amp\Future;
|
|
||||||
use Amp\Http\Client\HttpClientBuilder;
|
use Amp\Http\Client\HttpClientBuilder;
|
||||||
use Amp\Http\Client\Request;
|
use Amp\Http\Client\Request;
|
||||||
|
|
||||||
|
@ -484,41 +483,94 @@ function addStatistics()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function searchWikis($path, $pattern, $depth = 1)
|
function searchWikis($path, $pattern, $depth = 1, $httpCheck = false)
|
||||||
{
|
{
|
||||||
$it = new RecursiveDirectoryIterator($path);
|
// Use a more efficient iterator that filters files by name
|
||||||
$list = array();
|
$dirIterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
|
||||||
$httpClient = HttpClientBuilder::buildDefault();
|
$iterator = new RecursiveIteratorIterator($dirIterator);
|
||||||
$nb = 0;
|
$iterator->setMaxDepth($depth);
|
||||||
$files = new RecursiveIteratorIterator($it);
|
|
||||||
$files->setMaxDepth($depth);
|
$list = [];
|
||||||
foreach ($files as $file) {
|
$count = 0;
|
||||||
if (preg_match('/' . preg_quote($pattern) . '$/i', $file)) {
|
|
||||||
$nb++;
|
// Process filesystem operations first
|
||||||
$wakkaConfig = [];
|
foreach ($iterator as $file) {
|
||||||
include_once($file);
|
// Direct basename comparison instead of regex
|
||||||
$list[$nb] = [
|
if ($file->isFile() && basename($file) === $pattern) {
|
||||||
'PATH' => dirname($file),
|
$count++;
|
||||||
|
$filePath = $file->getPathname();
|
||||||
|
|
||||||
|
// Extract config without using include_once which is slow
|
||||||
|
$wakkaConfig = extractWakkaConfig($filePath);
|
||||||
|
|
||||||
|
$list[$count] = [
|
||||||
|
'PATH' => dirname($filePath),
|
||||||
'URL' => $wakkaConfig['base_url'] ?? 'KO',
|
'URL' => $wakkaConfig['base_url'] ?? 'KO',
|
||||||
'VERSION' => $wakkaConfig['yeswiki_version'] ?? 'KO',
|
'VERSION' => $wakkaConfig['yeswiki_version'] ?? 'KO',
|
||||||
'RELEASE' => $wakkaConfig['yeswiki_release'] ?? 'KO',
|
'RELEASE' => $wakkaConfig['yeswiki_release'] ?? 'KO',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Process HTTP requests in smaller batches to avoid overwhelming resources
|
||||||
|
if (!empty($list) && $httpCheck) {
|
||||||
try {
|
try {
|
||||||
$responses = Future\awaitAll(array_map(function ($l) use ($httpClient) {
|
// Process in batches of 10 for better performance
|
||||||
return Amp\async(fn () => $httpClient->request(new Request($l['URL'], 'HEAD')));
|
$batchSize = 10;
|
||||||
}, $list));
|
$batches = array_chunk($list, $batchSize, true);
|
||||||
foreach ($responses[0] as $key => $response) {
|
|
||||||
|
foreach ($batches as $batch) {
|
||||||
|
$httpClient = HttpClientBuilder::buildDefault();
|
||||||
|
$futures = [];
|
||||||
|
|
||||||
|
foreach ($batch as $key => $item) {
|
||||||
|
if ($item['URL'] !== 'KO') {
|
||||||
|
$futures[$key] = Amp\async(fn () => $httpClient->request(new Request($item['URL'], 'HEAD')));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$responses = Amp\Future\awaitAll($futures);
|
||||||
|
|
||||||
|
// Update statuses from responses
|
||||||
|
foreach ($responses[0] as $key => $error) {
|
||||||
$list[$key]['STATUS'] = 'ERROR';
|
$list[$key]['STATUS'] = 'ERROR';
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($responses[1] as $key => $response) {
|
foreach ($responses[1] as $key => $response) {
|
||||||
$list[$key]['STATUS'] = $response->getStatus() . ' ' . $response->getReason();
|
$list[$key]['STATUS'] = $response->getStatus() . ' ' . $response->getReason();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// If any one of the requests fails the combo will fail
|
|
||||||
echo $e->getMessage(), "\n";
|
echo $e->getMessage(), "\n";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract configuration from a wakka.config.php file without using include
|
||||||
|
* which is much faster for many files
|
||||||
|
*/
|
||||||
|
function extractWakkaConfig($filePath)
|
||||||
|
{
|
||||||
|
$config = [];
|
||||||
|
$content = file_get_contents($filePath);
|
||||||
|
|
||||||
|
// Extract base_url
|
||||||
|
if (preg_match('/[\'"]base_url[\'"]\s*=>\s*[\'"]([^\'"]+)[\'"]/i', $content, $matches)) {
|
||||||
|
$config['base_url'] = $matches[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract yeswiki_version
|
||||||
|
if (preg_match('/[\'"]yeswiki_version[\'"]\s*=>\s*[\'"]([^\'"]+)[\'"]/i', $content, $matches)) {
|
||||||
|
$config['yeswiki_version'] = $matches[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract yeswiki_release
|
||||||
|
if (preg_match('/[\'"]yeswiki_release[\'"]\s*=>\s*[\'"]([^\'"]+)[\'"]/i', $content, $matches)) {
|
||||||
|
$config['yeswiki_release'] = $matches[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $config;
|
||||||
|
}
|
||||||
|
|
|
@ -51,6 +51,12 @@ if ($isRoot) {
|
||||||
'description' => 'Depth to scan folders for wikis',
|
'description' => 'Depth to scan folders for wikis',
|
||||||
'defaultValue' => 1
|
'defaultValue' => 1
|
||||||
],
|
],
|
||||||
|
'httpcheck' => [
|
||||||
|
'prefix' => 'http',
|
||||||
|
'longPrefix' => 'httpcheck',
|
||||||
|
'description' => 'Perform an http request to check if the yeswikis are working',
|
||||||
|
'noValue' => true
|
||||||
|
],
|
||||||
]);
|
]);
|
||||||
try {
|
try {
|
||||||
$climate->arguments->parse();
|
$climate->arguments->parse();
|
||||||
|
@ -68,7 +74,8 @@ if ($isRoot) {
|
||||||
$output = $climate->arguments->get('output');
|
$output = $climate->arguments->get('output');
|
||||||
$nobackup = $climate->arguments->get('nobackup');
|
$nobackup = $climate->arguments->get('nobackup');
|
||||||
$depth = $climate->arguments->get('depth');
|
$depth = $climate->arguments->get('depth');
|
||||||
$matches = searchWikis($path, 'wakka.config.php', $depth);
|
$httpCheck = $climate->arguments->get('httpcheck');
|
||||||
|
$matches = searchWikis($path, 'wakka.config.php', $depth, $httpCheck);
|
||||||
if (count($matches) == 0) {
|
if (count($matches) == 0) {
|
||||||
$climate->info('No yeswiki found on path ' . $path . ' with depth ' . $depth);
|
$climate->info('No yeswiki found on path ' . $path . ' with depth ' . $depth);
|
||||||
exit;
|
exit;
|
||||||
|
|
Loading…
Add table
Reference in a new issue