@@ -284,7 +284,7 @@ func NewPublishedRepo(storage, prefix, distribution string, architectures []stri
284284 return result , nil
285285}
286286
287- // MarshalJSON requires object to be "loaded completely "
287+ // MarshalJSON requires object to filled by "LoadShallow" or "LoadComplete "
288288func (p * PublishedRepo ) MarshalJSON () ([]byte , error ) {
289289 type sourceInfo struct {
290290 Component , Name string
@@ -990,8 +990,11 @@ func (collection *PublishedRepoCollection) Update(repo *PublishedRepo) error {
990990 return batch .Write ()
991991}
992992
993- // LoadComplete loads additional information for remote repo
994- func (collection * PublishedRepoCollection ) LoadComplete (repo * PublishedRepo , collectionFactory * CollectionFactory ) (err error ) {
993+ // LoadShallow loads basic information on the repo's sources
994+ //
995+ // This does not *fully* load in the sources themselves and their packages.
996+ // It's useful if you just want to use JSON serialization without loading in unnecessary things.
997+ func (collection * PublishedRepoCollection ) LoadShallow (repo * PublishedRepo , collectionFactory * CollectionFactory ) (err error ) {
995998 repo .sourceItems = make (map [string ]repoSourceItem )
996999
9971000 if repo .SourceKind == SourceSnapshot {
@@ -1002,10 +1005,6 @@ func (collection *PublishedRepoCollection) LoadComplete(repo *PublishedRepo, col
10021005 if err != nil {
10031006 return
10041007 }
1005- err = collectionFactory .SnapshotCollection ().LoadComplete (item .snapshot )
1006- if err != nil {
1007- return
1008- }
10091008
10101009 repo .sourceItems [component ] = item
10111010 }
@@ -1017,6 +1016,30 @@ func (collection *PublishedRepoCollection) LoadComplete(repo *PublishedRepo, col
10171016 if err != nil {
10181017 return
10191018 }
1019+
1020+ item .packageRefs = & PackageRefList {}
1021+ repo .sourceItems [component ] = item
1022+ }
1023+ } else {
1024+ panic ("unknown SourceKind" )
1025+ }
1026+
1027+ return
1028+ }
1029+
1030+ // LoadComplete loads complete information on the sources of the repo *and* their packages
1031+ func (collection * PublishedRepoCollection ) LoadComplete (repo * PublishedRepo , collectionFactory * CollectionFactory ) (err error ) {
1032+ collection .LoadShallow (repo , collectionFactory )
1033+
1034+ if repo .SourceKind == SourceSnapshot {
1035+ for _ , item := range repo .sourceItems {
1036+ err = collectionFactory .SnapshotCollection ().LoadComplete (item .snapshot )
1037+ if err != nil {
1038+ return
1039+ }
1040+ }
1041+ } else if repo .SourceKind == SourceLocalRepo {
1042+ for component , item := range repo .sourceItems {
10201043 err = collectionFactory .LocalRepoCollection ().LoadComplete (item .localRepo )
10211044 if err != nil {
10221045 return
@@ -1035,13 +1058,10 @@ func (collection *PublishedRepoCollection) LoadComplete(repo *PublishedRepo, col
10351058 }
10361059 }
10371060
1038- item .packageRefs = & PackageRefList {}
10391061 err = item .packageRefs .Decode (encoded )
10401062 if err != nil {
10411063 return
10421064 }
1043-
1044- repo .sourceItems [component ] = item
10451065 }
10461066 } else {
10471067 panic ("unknown SourceKind" )
0 commit comments