about summary refs log tree commit diff stats
path: root/internal/fetcher
diff options
context:
space:
mode:
authorAlan Pearce2024-05-20 23:33:48 +0200
committerAlan Pearce2024-05-20 23:33:48 +0200
commite72d9caabfd825db660733abe3082426dc2c3838 (patch)
tree449e3f4fdcfae4e1149b984451457e6aeb2e4d92 /internal/fetcher
parent8e8c5c9cc35ef9b3de9b8d43919f27a39a1d75d3 (diff)
downloadsearchix-e72d9caabfd825db660733abe3082426dc2c3838.tar.lz
searchix-e72d9caabfd825db660733abe3082426dc2c3838.tar.zst
searchix-e72d9caabfd825db660733abe3082426dc2c3838.zip
perf: make channel-nixpkgs importer only fetch necessary files
i.e. don't fetch options.json when Source.Type = "packages"
Diffstat (limited to 'internal/fetcher')
-rw-r--r--internal/fetcher/nixpkgs-channel.go19
1 files changed, 14 insertions, 5 deletions
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)