Skip to content

Commit

Permalink
Faster large collections (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
SmilyOrg authored Sep 8, 2024
2 parents 48e2be6 + 0be2444 commit 637fe90
Show file tree
Hide file tree
Showing 14 changed files with 364 additions and 212 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ version zero.
### Added

- Enable search even if AI is not enabled
- Add `skip_collection_counts` config option for faster startup in some cases

### Changed

- None
- Optimized loading very large collections (100K .. 10M+ files)
- Fixed unit in loading spinner

### Removed

Expand Down
7 changes: 1 addition & 6 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"photofield/internal/layout"
"photofield/internal/render"
"photofield/tag"
"strings"

"github.com/goccy/go-yaml"
"github.com/imdario/mergo"
Expand Down Expand Up @@ -144,11 +143,7 @@ func loadConfig(dataDir string) (*AppConfig, error) {

for i := range collections {
collection := &collections[i]
collection.GenerateId()
collection.Layout = strings.ToUpper(collection.Layout)
if collection.Limit > 0 && collection.IndexLimit == 0 {
collection.IndexLimit = collection.Limit
}
collection.MakeValid()
}

// Override earlier collection with the same ID
Expand Down
4 changes: 4 additions & 0 deletions defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ media:

# Set to true to not extract any metadata or colors from photos
skip_load_info: false

# Skip printing the file count of collections at startup
# This can speed up startup time for large collections
skip_collection_counts: false

caches:
image:
Expand Down
16 changes: 15 additions & 1 deletion internal/collection/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"photofield/internal/clip"
"photofield/internal/image"
"sort"
"strings"
"time"

"github.com/gosimple/slug"
Expand All @@ -26,8 +27,20 @@ type Collection struct {
InvalidatedAt *time.Time `json:"-"`
}

func (collection *Collection) GenerateId() {
func (collection *Collection) MakeValid() {
collection.Id = slug.Make(collection.Name)
collection.Layout = strings.ToUpper(collection.Layout)
if collection.Limit > 0 && collection.IndexLimit == 0 {
collection.IndexLimit = collection.Limit
}
for i := range collection.Dirs {
dir := collection.Dirs[i]
dir = filepath.FromSlash(dir)
if !strings.HasSuffix(dir, string(filepath.Separator)) {
dir += string(filepath.Separator)
}
collection.Dirs[i] = dir
}
}

func (collection *Collection) UpdatedAt() time.Time {
Expand Down Expand Up @@ -65,6 +78,7 @@ func (collection *Collection) Expand() []Collection {
Limit: collection.Limit,
IndexLimit: collection.IndexLimit,
}
child.MakeValid()
collections = append(collections, child)
}
}
Expand Down
Loading

0 comments on commit 637fe90

Please sign in to comment.