aboutsummaryrefslogtreecommitdiff
path: root/internal/service/load.go
diff options
context:
space:
mode:
authorRanXom <saiyedshizain@gmail.com>2026-07-13 18:37:01 +0530
committerRanXom <saiyedshizain@gmail.com>2026-07-13 18:37:01 +0530
commitd754ce4c11af51e06515275b58a3f337a440ed9d (patch)
tree07845d209b67c7445803443e2ba158e91b672888 /internal/service/load.go
parenta06e00d332aff7ddc667331c8f83b7317f5ca933 (diff)
downloadgalleryd-d754ce4c11af51e06515275b58a3f337a440ed9d.tar.xz
galleryd-d754ce4c11af51e06515275b58a3f337a440ed9d.zip
feat(service): introduce service lifecycle & load gallery during initialization
Diffstat (limited to 'internal/service/load.go')
-rw-r--r--internal/service/load.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/internal/service/load.go b/internal/service/load.go
new file mode 100644
index 0000000..09bbc20
--- /dev/null
+++ b/internal/service/load.go
@@ -0,0 +1,33 @@
+package service
+
+import (
+ "context"
+
+ "github.com/RanXom/galleryd/internal/gallery"
+)
+
+// Load scans the configured roots and rebuilds the in-memory gallery.
+func (s *galleryService) Load(ctx context.Context) error {
+ files, err := s.scanner.Scan(ctx)
+ if err != nil {
+ return err
+ }
+
+ photos, err := s.builder.Build(ctx, files)
+ if err != nil {
+ return err
+ }
+
+ index := galleryIndex{
+ photos: photos,
+ byID: make(map[string]gallery.Photo, len(photos)),
+ }
+
+ for _, photo := range photos {
+ index.byID[photo.ID] = photo
+ }
+
+ s.index = index
+
+ return nil
+}