about summary refs log tree commit diff stats
path: root/internal/importer
diff options
context:
space:
mode:
authorAlan Pearce2024-05-17 15:51:27 +0200
committerAlan Pearce2024-05-17 15:51:27 +0200
commit9f241bff227608dd53a250d012116077dce6dab6 (patch)
treec8f1f19788f866548dd42baaf7fedfd0560a47b7 /internal/importer
parent43fe431c3aff36d52a630ca670f9fc4ee161962f (diff)
downloadsearchix-9f241bff227608dd53a250d012116077dce6dab6.tar.lz
searchix-9f241bff227608dd53a250d012116077dce6dab6.tar.zst
searchix-9f241bff227608dd53a250d012116077dce6dab6.zip
feat: automatically add/remove sources to/from index
Diffstat (limited to 'internal/importer')
-rw-r--r--internal/importer/main.go18
1 files changed, 16 insertions, 2 deletions
diff --git a/internal/importer/main.go b/internal/importer/main.go
index 7776482..747d813 100644
--- a/internal/importer/main.go
+++ b/internal/importer/main.go
@@ -9,12 +9,18 @@ import (
 	"searchix/internal/config"
 	"searchix/internal/fetcher"
 	"searchix/internal/index"
+	"slices"
 	"strings"
 
 	"github.com/pkg/errors"
 )
 
-func Start(cfg *config.Config, indexer *index.WriteIndex, replace bool) error {
+func Start(
+	cfg *config.Config,
+	indexer *index.WriteIndex,
+	forceUpdate bool,
+	onlyUpdateSources *[]string,
+) error {
 	if len(cfg.Importer.Sources) == 0 {
 		slog.Info("No sources enabled")
 
@@ -24,7 +30,15 @@ func Start(cfg *config.Config, indexer *index.WriteIndex, replace bool) error {
 	ctx, cancel := context.WithTimeout(context.Background(), cfg.Importer.Timeout.Duration)
 	defer cancel()
 
+	forceUpdate = forceUpdate || (onlyUpdateSources != nil && len(*onlyUpdateSources) > 0)
+
 	for name, source := range cfg.Importer.Sources {
+		if len(*onlyUpdateSources) > 0 {
+			if !slices.Contains(*onlyUpdateSources, name) {
+				continue
+			}
+		}
+
 		logger := slog.With("name", name, "fetcher", source.Fetcher.String())
 		logger.Debug("starting fetcher")
 
@@ -54,7 +68,7 @@ func Start(cfg *config.Config, indexer *index.WriteIndex, replace bool) error {
 		}
 		logger.Info("importer fetch succeeded", "updated", updated)
 
-		if updated || replace {
+		if updated || forceUpdate {
 			err = setRepoRevision(files.Revision, source)
 			if err != nil {
 				logger.Warn("could not set source repo revision", "error", err)