Skip to content

Commit b100fb9

Browse files
committed
Skip loading reflists when listing published repos
The output doesn't actually depend on the reflists, and loading them for every published repo starts to take substantial time and memory. Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
1 parent 75b858b commit b100fb9

3 files changed

Lines changed: 32 additions & 12 deletions

File tree

api/publish.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func apiPublishList(c *gin.Context) {
6161
result := make([]*deb.PublishedRepo, 0, collection.Len())
6262

6363
err := collection.ForEach(func(repo *deb.PublishedRepo) error {
64-
err := collection.LoadComplete(repo, collectionFactory)
64+
err := collection.LoadShallow(repo, collectionFactory)
6565
if err != nil {
6666
return err
6767
}

cmd/publish_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func aptlyPublishListTxt(cmd *commander.Command, _ []string) error {
3434
published := make([]string, 0, collectionFactory.PublishedRepoCollection().Len())
3535

3636
err = collectionFactory.PublishedRepoCollection().ForEach(func(repo *deb.PublishedRepo) error {
37-
e := collectionFactory.PublishedRepoCollection().LoadComplete(repo, collectionFactory)
37+
e := collectionFactory.PublishedRepoCollection().LoadShallow(repo, collectionFactory)
3838
if e != nil {
3939
fmt.Fprintf(os.Stderr, "Error found on one publish (prefix:%s / distribution:%s / component:%s\n)",
4040
repo.StoragePrefix(), repo.Distribution, repo.Components())

deb/publish.go

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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"
288288
func (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

Comments
 (0)