mirror of
https://github.com/Terranom674/Piwigo_Bratonien_Tools.git
synced 2026-09-20 22:43:18 +00:00
Make cache build incremental from worker index
This commit is contained in:
@@ -185,7 +185,7 @@ function bratonien_tools_start_webdav_warmup_mode($mode, $message)
|
|||||||
'queued',
|
'queued',
|
||||||
$mode === 'rebuild'
|
$mode === 'rebuild'
|
||||||
? 'Cache-Rebuild wurde angefordert. Der Worker wartet auf den Start und gleicht danach Shadow-Tree und eigenen Index ab.'
|
? 'Cache-Rebuild wurde angefordert. Der Worker wartet auf den Start und gleicht danach Shadow-Tree und eigenen Index ab.'
|
||||||
: 'Cache-Fortsetzung wurde angefordert. Bereits erfolgreich abgeschlossene Stufen bleiben erhalten; verarbeitet werden nur noch fehlende oder geänderte Quellen.',
|
: 'Cache-Abgleich wurde angefordert. Bereits erfolgreich abgeschlossene Stufen bleiben erhalten; geladen werden nur Quellen mit fehlender Stufe 1 oder Stufe 2.',
|
||||||
array('mode'=>$mode, 'run_id'=>$run_id)
|
array('mode'=>$mode, 'run_id'=>$run_id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -212,7 +212,7 @@ function bratonien_tools_start_webdav_warmup_manual()
|
|||||||
{
|
{
|
||||||
return bratonien_tools_start_webdav_warmup_mode(
|
return bratonien_tools_start_webdav_warmup_mode(
|
||||||
'manual',
|
'manual',
|
||||||
'WebDAV-Worker: Shadow-Tree wird mit dem eigenen Index auf neue, geänderte oder noch nicht vollständig verarbeitete Quellen abgeglichen.'
|
'WebDAV-Worker: Shadow-Tree und Worker-Index werden abgeglichen; vollständig erledigte Quellen werden nicht aus Nextcloud geladen.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,29 +224,6 @@ function bratonien_tools_start_webdav_cache_rebuild()
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function bratonien_tools_webdav_cache_build_should_resume()
|
|
||||||
{
|
|
||||||
$now = time();
|
|
||||||
foreach (bratonien_tools_webdav_warmup_connections() as $connection_id=>$runtime)
|
|
||||||
{
|
|
||||||
$file = bratonien_tools_webdav_warmup_status_file_for_connection($connection_id);
|
|
||||||
if (!is_file($file) || !is_readable($file)) continue;
|
|
||||||
$raw = @file_get_contents($file);
|
|
||||||
$status = $raw !== false ? json_decode($raw, true) : null;
|
|
||||||
if (!is_array($status)) continue;
|
|
||||||
|
|
||||||
$state = (string)($status['state'] ?? 'idle');
|
|
||||||
if (in_array($state, array('preempted','error','fatal'), true)) return true;
|
|
||||||
|
|
||||||
if (in_array($state, array('queued','scan','running'), true))
|
|
||||||
{
|
|
||||||
$updated = (int)($status['updated_at'] ?? 0);
|
|
||||||
if ($updated > 0 && ($now - $updated) > 120) return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function bratonien_tools_has_local_cache_sources()
|
function bratonien_tools_has_local_cache_sources()
|
||||||
{
|
{
|
||||||
if (!function_exists('bratonien_tools_webdav_materialize_source_info')) return true;
|
if (!function_exists('bratonien_tools_webdav_materialize_source_info')) return true;
|
||||||
@@ -263,17 +240,13 @@ function bratonien_tools_has_local_cache_sources()
|
|||||||
|
|
||||||
function bratonien_tools_start_combined_image_cache_build()
|
function bratonien_tools_start_combined_image_cache_build()
|
||||||
{
|
{
|
||||||
// Ein unvollständiger WebDAV-Lauf wird fortgesetzt. Nur wenn kein
|
// Der normale "Piwigo-Bildcache aufbauen"-Lauf ist immer inkrementell.
|
||||||
// fortsetzbarer Lauf existiert, startet der Button einen echten Rebuild.
|
// Der Worker liest zuerst ausschließlich Shadow-Tree/Mapping und seinen
|
||||||
// Dadurch bleiben bereits gesetzte stage1/stage2-Signaturen erhalten und
|
// eigenen Index. Nur Quellen, denen laut Index Stufe 1 oder Stufe 2 fehlt,
|
||||||
// ein Abbruch nach Stufe 1 führt nicht erneut zu einem Start bei 0.
|
// dürfen anschließend aus Nextcloud geladen werden. Ein kompletter
|
||||||
$resume = bratonien_tools_webdav_cache_build_should_resume();
|
// Neuaufbau entsteht nur nach einer echten Cache-Invalidierung (z.B. Cache
|
||||||
$webdav = $resume
|
// leeren), denn genau dort werden die Stage-Signaturen bewusst entfernt.
|
||||||
? bratonien_tools_start_webdav_warmup_mode(
|
$webdav = bratonien_tools_start_webdav_warmup_manual();
|
||||||
'manual',
|
|
||||||
'WebDAV-Bildcache: unterbrochener Lauf wird aus dem vorhandenen Worker-Index fortgesetzt; fertige Stufen werden nicht erneut verarbeitet.'
|
|
||||||
)
|
|
||||||
: bratonien_tools_start_webdav_cache_rebuild();
|
|
||||||
$main = array('started'=>false, 'message'=>'');
|
$main = array('started'=>false, 'message'=>'');
|
||||||
|
|
||||||
if (bratonien_tools_has_local_cache_sources())
|
if (bratonien_tools_has_local_cache_sources())
|
||||||
@@ -343,4 +316,4 @@ function bratonien_tools_get_webdav_warmup_status()
|
|||||||
if ($latest === null || (int)($data['updated_at'] ?? 0) > (int)($latest['updated_at'] ?? 0)) $latest = $data;
|
if ($latest === null || (int)($data['updated_at'] ?? 0) > (int)($latest['updated_at'] ?? 0)) $latest = $data;
|
||||||
}
|
}
|
||||||
return is_array($latest) ? array_merge($status, $latest) : $status;
|
return is_array($latest) ? array_merge($status, $latest) : $status;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user