aboutsummaryrefslogtreecommitdiff
path: root/internal/service/reload.go
blob: 98e47101d3405ca25a19ed8e29f9ab26347fd5e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
}