M2: local cache of pack indexes (ngb_index)

Opening a repository lists index/ once and downloads only index files
that are not cached; packs written by this server are cached on write,
stale cache rows are dropped. Each resumable step therefore no longer
downloads every index file from the location.
This commit is contained in:
2026-10-02 00:55:46 +02:00
parent 2ab4b2e7d5
commit 50acd5dc0e
9 changed files with 210 additions and 7 deletions
+9 -1
View File
@@ -64,7 +64,7 @@ final class Repository {
}
/** Open with the master key the server holds (scheduled backups, no passphrase needed). */
public static function openWithKey(IBackend $backend, KeyRing $keys): self {
public static function openWithKey(IBackend $backend, KeyRing $keys, ?IIndexCache $cache = null): self {
$config = self::readConfig($backend);
try {
$ok = isset($config['check']) && (new StreamCipher($keys))->decryptString((string)base64_decode($config['check'], true), 'config-check') === $config['id'];
@@ -75,10 +75,18 @@ final class Repository {
throw new RepositoryException('This repository was created with a different key');
}
$repo = new self($backend, $keys, $config['id']);
if ($cache !== null) {
$repo->index->setCache($cache, $config['id']);
}
$repo->index->load();
return $repo;
}
/** Index files downloaded when this repository was opened (0 when the local cache was complete). */
public function indexDownloads(): int {
return $this->index->downloaded;
}
private static function readConfig(IBackend $backend): array {
try {
$fh = $backend->get('config');