From 826434a8597122847f643abe835d5c6e5dd74c4c Mon Sep 17 00:00:00 2001 From: RanXom Date: Tue, 14 Jul 2026 10:45:04 +0530 Subject: refactor(service): rename load to reload --- internal/service/reload.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 internal/service/reload.go (limited to 'internal/service/reload.go') diff --git a/internal/service/reload.go b/internal/service/reload.go new file mode 100644 index 0000000..98e4710 --- /dev/null +++ b/internal/service/reload.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) Reload(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 +} -- cgit v1.2.3 From ad97c2f3222dcdb8c124747feb4564ca9069fa1e Mon Sep 17 00:00:00 2001 From: RanXom Date: Tue, 14 Jul 2026 10:57:01 +0530 Subject: refactor(service): synchronize gallery access --- internal/service/reload.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'internal/service/reload.go') diff --git a/internal/service/reload.go b/internal/service/reload.go index 98e4710..9460dbc 100644 --- a/internal/service/reload.go +++ b/internal/service/reload.go @@ -6,7 +6,7 @@ import ( "github.com/RanXom/galleryd/internal/gallery" ) -// Load scans the configured roots and rebuilds the in-memory gallery. +// Reload scans the configured roots and rebuilds the in-memory gallery. func (s *galleryService) Reload(ctx context.Context) error { files, err := s.scanner.Scan(ctx) if err != nil { @@ -27,7 +27,9 @@ func (s *galleryService) Reload(ctx context.Context) error { index.byID[photo.ID] = photo } + s.mu.Lock() s.index = index + s.mu.Unlock() return nil } -- cgit v1.2.3