all repos — searchix @ e72d9caabfd825db660733abe3082426dc2c3838

Search engine for NixOS, nix-darwin, home-manager and NUR users

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
commit

e72d9caabfd825db660733abe3082426dc2c3838

parent

8e8c5c9cc35ef9b3de9b8d43919f27a39a1d75d3

1 files changed, 14 insertions(+), 5 deletions(-)

jump to
M internal/fetcher/nixpkgs-channel.gointernal/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