Files
git.stella-ops.org/src/__Libraries/StellaOps.Provcache.Postgres/PostgresEvidenceChunkRepository.Manifest.cs

57 lines
1.5 KiB
C#

using Microsoft.EntityFrameworkCore;
namespace StellaOps.Provcache.Postgres;
public sealed partial class PostgresEvidenceChunkRepository
{
/// <inheritdoc />
public async Task<ChunkManifest?> GetManifestAsync(
string proofRoot,
CancellationToken cancellationToken = default)
{
ArgumentException.ThrowIfNullOrWhiteSpace(proofRoot);
// Get metadata without loading blobs
var chunks = await _context.EvidenceChunks
.Where(e => e.ProofRoot == proofRoot)
.OrderBy(e => e.ChunkIndex)
.Select(e => new
{
e.ChunkId,
e.ChunkIndex,
e.ChunkHash,
e.BlobSize,
e.ContentType,
e.CreatedAt
})
.AsNoTracking()
.ToListAsync(cancellationToken)
.ConfigureAwait(false);
if (chunks.Count == 0)
{
return null;
}
var metadata = chunks
.Select(c => new ChunkMetadata
{
ChunkId = c.ChunkId,
Index = c.ChunkIndex,
Hash = c.ChunkHash,
Size = c.BlobSize,
ContentType = c.ContentType
})
.ToList();
return new ChunkManifest
{
ProofRoot = proofRoot,
TotalChunks = chunks.Count,
TotalSize = chunks.Sum(c => (long)c.BlobSize),
Chunks = metadata,
GeneratedAt = _timeProvider.GetUtcNow()
};
}
}