From e72d9caabfd825db660733abe3082426dc2c3838 Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 20 May 2024 23:33:48 +0200 Subject: perf: make channel-nixpkgs importer only fetch necessary files i.e. don't fetch options.json when Source.Type = "packages" --- internal/fetcher/nixpkgs-channel.go | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'internal') diff --git a/internal/fetcher/nixpkgs-channel.go b/internal/fetcher/nixpkgs-channel.go index e36728c..32aaac3 100644 --- a/internal/fetcher/nixpkgs-channel.go +++ b/internal/fetcher/nixpkgs-channel.go @@ -23,11 +23,11 @@ func makeChannelURL(channel string, subPath string) (string, error) { return url, errors.WithMessagef(err, "error creating URL") } -var filesToFetch = map[string]string{ - "revision": "git-revision", - "options": "options.json.br", - "packages": "packages.json.br", -} +const ( + revisionFilename = "git-revision" + optionsFilename = "options.json.br" + packagesFileName = "packages.json.br" +) func (i *NixpkgsChannelFetcher) FetchIfNeeded( parent context.Context, @@ -44,6 +44,15 @@ func (i *NixpkgsChannelFetcher) FetchIfNeeded( return } + filesToFetch := make([]string, 2) + filesToFetch[0] = revisionFilename + switch i.Source.Importer { + case config.Packages: + filesToFetch[1] = packagesFileName + case config.Options: + filesToFetch[1] = optionsFilename + } + var fetchURL string for _, filename := range filesToFetch { fetchURL, err = makeChannelURL(i.Source.Channel, filename) -- cgit 1.4.1