add chunk limiter

This commit is contained in:
team 1
2026-02-16 15:29:31 +01:00
parent b04f972971
commit feff95ffe5
7 changed files with 239 additions and 31 deletions

View File

@@ -7,19 +7,24 @@ namespace App\Index;
final class IndexMetaManager
{
private string $metaPath;
private string $runtimePath;
private IndexConfigurationProvider $provider;
public function __construct(
string $metaPath,
string $runTimePath,
IndexConfigurationProvider $provider
) {
$this->metaPath = $metaPath;
$this->provider = $provider;
// runtime liegt im selben Verzeichnis
$this->runtimePath = $runTimePath;
}
// -----------------------------------------------------
// Public API
// -----------------------------------------------------
// =====================================================
// META (Governance unverändert lassen!)
// =====================================================
public function ensureExists(): void
{
@@ -93,4 +98,58 @@ final class IndexMetaManager
)
);
}
// =====================================================
// RUNTIME (Chunk Counter etc.)
// =====================================================
private function ensureRuntimeFileExists(): void
{
if (is_file($this->runtimePath)) {
return;
}
$dir = dirname($this->runtimePath);
if (!is_dir($dir)) {
mkdir($dir, 0777, true);
}
$payload = [
'chunk_count' => 0,
'last_rebuild_at' => null,
];
file_put_contents(
$this->runtimePath,
json_encode($payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
public function updateRuntimeStats(int $chunkCount): void
{
$this->ensureRuntimeFileExists();
$payload = [
'chunk_count' => $chunkCount,
'last_rebuild_at' => (new \DateTimeImmutable())->format(DATE_ATOM),
];
file_put_contents(
$this->runtimePath,
json_encode($payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
}
public function getRuntimeChunkCount(): int
{
$this->ensureRuntimeFileExists();
$data = json_decode(
(string) file_get_contents($this->runtimePath),
true
);
return (int)($data['chunk_count'] ?? 0);
}
}