From 93ffee538cc9c30ce6990a86dc32d0bd09c1cbe8 Mon Sep 17 00:00:00 2001 From: Catherine Date: Fri, 19 Sep 2025 18:38:47 +0000 Subject: [PATCH] Precompute total site size in manifest. --- src/manifest.go | 3 +++ src/schema.pb.go | 14 ++++++++++++-- src/schema.proto | 15 ++++++++------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/manifest.go b/src/manifest.go index 0a3e294..2edc612 100644 --- a/src/manifest.go +++ b/src/manifest.go @@ -111,6 +111,7 @@ func ExternalizeFiles(manifest *Manifest) *Manifest { Commit: manifest.Commit, Contents: make(map[string]*Entry), } + var totalSize uint32 for name, entry := range manifest.Contents { if entry.GetType() == Type_InlineFile && entry.GetSize() > ExternalSizeMin { newManifest.Contents[name] = &Entry{ @@ -121,7 +122,9 @@ func ExternalizeFiles(manifest *Manifest) *Manifest { } else { newManifest.Contents[name] = entry } + totalSize += entry.GetSize() } + newManifest.TotalSize = proto.Uint32(totalSize) return &newManifest } diff --git a/src/schema.pb.go b/src/schema.pb.go index 1e67e92..4705a13 100644 --- a/src/schema.pb.go +++ b/src/schema.pb.go @@ -147,6 +147,7 @@ type Manifest struct { Branch *string `protobuf:"bytes,2,opt,name=branch" json:"branch,omitempty"` Commit *string `protobuf:"bytes,3,opt,name=commit" json:"commit,omitempty"` Contents map[string]*Entry `protobuf:"bytes,4,rep,name=contents" json:"contents,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + TotalSize *uint32 `protobuf:"varint,5,opt,name=total_size,json=totalSize" json:"total_size,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -209,6 +210,13 @@ func (x *Manifest) GetContents() map[string]*Entry { return nil } +func (x *Manifest) GetTotalSize() uint32 { + if x != nil && x.TotalSize != nil { + return *x.TotalSize + } + return 0 +} + var File_schema_proto protoreflect.FileDescriptor const file_schema_proto_rawDesc = "" + @@ -217,12 +225,14 @@ const file_schema_proto_rawDesc = "" + "\x05Entry\x12\x19\n" + "\x04type\x18\x01 \x01(\x0e2\x05.TypeR\x04type\x12\x12\n" + "\x04size\x18\x02 \x01(\rR\x04size\x12\x12\n" + - "\x04data\x18\x03 \x01(\fR\x04data\"\xcf\x01\n" + + "\x04data\x18\x03 \x01(\fR\x04data\"\xee\x01\n" + "\bManifest\x12\x19\n" + "\brepo_url\x18\x01 \x01(\tR\arepoUrl\x12\x16\n" + "\x06branch\x18\x02 \x01(\tR\x06branch\x12\x16\n" + "\x06commit\x18\x03 \x01(\tR\x06commit\x123\n" + - "\bcontents\x18\x04 \x03(\v2\x17.Manifest.ContentsEntryR\bcontents\x1aC\n" + + "\bcontents\x18\x04 \x03(\v2\x17.Manifest.ContentsEntryR\bcontents\x12\x1d\n" + + "\n" + + "total_size\x18\x05 \x01(\rR\ttotalSize\x1aC\n" + "\rContentsEntry\x12\x10\n" + "\x03key\x18\x01 \x01(\tR\x03key\x12\x1c\n" + "\x05value\x18\x02 \x01(\v2\x06.EntryR\x05value:\x028\x01*Q\n" + diff --git a/src/schema.proto b/src/schema.proto index 8ad4ba6..088d0ba 100644 --- a/src/schema.proto +++ b/src/schema.proto @@ -16,14 +16,15 @@ enum Type { } message Entry { - Type type = 1; - uint32 size = 2; - bytes data = 3; + Type type = 1; + uint32 size = 2; + bytes data = 3; } message Manifest { - string repo_url = 1; - string branch = 2; - string commit = 3; - map contents = 4; + string repo_url = 1; + string branch = 2; + string commit = 3; + map contents = 4; + uint32 total_size = 5; }