add chunk limiter
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user