Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip loading reflists when listing published repos #1274

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func apiPublishList(c *gin.Context) {
result := make([]*deb.PublishedRepo, 0, collection.Len())

err := collection.ForEach(func(repo *deb.PublishedRepo) error {
err := collection.LoadComplete(repo, collectionFactory)
err := collection.LoadShallow(repo, collectionFactory)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/publish_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func aptlyPublishListTxt(cmd *commander.Command, _ []string) error {
published := make([]string, 0, collectionFactory.PublishedRepoCollection().Len())

err = collectionFactory.PublishedRepoCollection().ForEach(func(repo *deb.PublishedRepo) error {
e := collectionFactory.PublishedRepoCollection().LoadComplete(repo, collectionFactory)
e := collectionFactory.PublishedRepoCollection().LoadShallow(repo, collectionFactory)
if e != nil {
fmt.Fprintf(os.Stderr, "Error found on one publish (prefix:%s / distribution:%s / component:%s\n)",
repo.StoragePrefix(), repo.Distribution, repo.Components())
Expand Down
40 changes: 30 additions & 10 deletions deb/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@
return result, nil
}

// MarshalJSON requires object to be "loaded completely"
// MarshalJSON requires object to filled by "LoadShallow" or "LoadComplete"
func (p *PublishedRepo) MarshalJSON() ([]byte, error) {
type sourceInfo struct {
Component, Name string
Expand Down Expand Up @@ -987,8 +987,11 @@
return batch.Write()
}

// LoadComplete loads additional information for remote repo
func (collection *PublishedRepoCollection) LoadComplete(repo *PublishedRepo, collectionFactory *CollectionFactory) (err error) {
// LoadShallow loads basic information on the repo's sources
//
// This does not *fully* load in the sources themselves and their packages.
// It's useful if you just want to use JSON serialization without loading in unnecessary things.
func (collection *PublishedRepoCollection) LoadShallow(repo *PublishedRepo, collectionFactory *CollectionFactory) (err error) {
repo.sourceItems = make(map[string]repoSourceItem)

if repo.SourceKind == SourceSnapshot {
Expand All @@ -999,10 +1002,6 @@
if err != nil {
return
}
err = collectionFactory.SnapshotCollection().LoadComplete(item.snapshot)
if err != nil {
return
}

repo.sourceItems[component] = item
}
Expand All @@ -1014,6 +1013,30 @@
if err != nil {
return
}

item.packageRefs = &PackageRefList{}
repo.sourceItems[component] = item
}
} else {
panic("unknown SourceKind")

Check warning on line 1021 in deb/publish.go

View check run for this annotation

Codecov / codecov/patch

deb/publish.go#L1020-L1021

Added lines #L1020 - L1021 were not covered by tests
}

return
}

// LoadComplete loads complete information on the sources of the repo *and* their packages
func (collection *PublishedRepoCollection) LoadComplete(repo *PublishedRepo, collectionFactory *CollectionFactory) (err error) {
collection.LoadShallow(repo, collectionFactory)

if repo.SourceKind == SourceSnapshot {
for _, item := range repo.sourceItems {
err = collectionFactory.SnapshotCollection().LoadComplete(item.snapshot)
if err != nil {
return
}

Check warning on line 1036 in deb/publish.go

View check run for this annotation

Codecov / codecov/patch

deb/publish.go#L1035-L1036

Added lines #L1035 - L1036 were not covered by tests
}
} else if repo.SourceKind == SourceLocalRepo {
for component, item := range repo.sourceItems {
err = collectionFactory.LocalRepoCollection().LoadComplete(item.localRepo)
if err != nil {
return
Expand All @@ -1032,13 +1055,10 @@
}
}

item.packageRefs = &PackageRefList{}
err = item.packageRefs.Decode(encoded)
if err != nil {
return
}

repo.sourceItems[component] = item
}
} else {
panic("unknown SourceKind")
Expand Down
Loading