perf: make channel-nixpkgs importer only fetch necessary files i.e. don't fetch options.json when Source.Type = "packages"
Alan Pearce alan@alanpearce.eu
Mon, 20 May 2024 23:33:48 +0200
1 files changed, 14 insertions(+), 5 deletions(-)
M internal/fetcher/nixpkgs-channel.go → internal/fetcher/nixpkgs-channel.go
@@ -23,11 +23,11 @@ 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, @@ -42,6 +42,15 @@ if err != nil { err = errors.WithMessagef(err, "error creating directory for data: %s", root) 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