Skip to content

Commit

Permalink
refactor: enhance LocalAssetBrowser to read metadata only when requir…
Browse files Browse the repository at this point in the history
…ed by options
  • Loading branch information
simulot committed Dec 11, 2024
1 parent 2a2809e commit 5310b9c
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions adapters/folder/readFolder.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ import (
)

type LocalAssetBrowser struct {
fsyss []fs.FS
log *fileevent.Recorder
flags *ImportFolderOptions
pool *worker.Pool
wg sync.WaitGroup
groupers []groups.Grouper
fsyss []fs.FS
log *fileevent.Recorder
flags *ImportFolderOptions
pool *worker.Pool
wg sync.WaitGroup
groupers []groups.Grouper
requiresDateInformation bool // true if we need to read the date from the file for the options
}

func NewLocalFiles(ctx context.Context, l *fileevent.Recorder, flags *ImportFolderOptions, fsyss ...fs.FS) (*LocalAssetBrowser, error) {
Expand All @@ -44,10 +45,11 @@ func NewLocalFiles(ctx context.Context, l *fileevent.Recorder, flags *ImportFold
}

la := LocalAssetBrowser{
fsyss: fsyss,
flags: flags,
log: l,
pool: worker.NewPool(3), // TODO: Make this configurable
fsyss: fsyss,
flags: flags,
log: l,
pool: worker.NewPool(3), // TODO: Make this configurable
requiresDateInformation: flags.InclusionFlags.DateRange.IsSet() || flags.TakeDateFromFilename || flags.StackBurstPhotos,
}
if flags.InfoCollector == nil {
flags.InfoCollector = filenames.NewInfoCollector(flags.TZ, flags.SupportedMedia)
Expand Down Expand Up @@ -254,7 +256,7 @@ func (la *LocalAssetBrowser) parseDir(ctx context.Context, fsys fs.FS, dir strin
}

// Read metadata from the file only id needed (date range or take date from filename)
if la.flags.InclusionFlags.DateRange.IsSet() || la.flags.TakeDateFromFilename {
if la.requiresDateInformation {
if a.CaptureDate.IsZero() {
// no date in XMp, JSON, try reading the metadata
f, name, err := a.PartialSourceReader()
Expand All @@ -265,7 +267,7 @@ func (la *LocalAssetBrowser) parseDir(ctx context.Context, fsys fs.FS, dir strin
} else {
a.FromSourceFile = a.UseMetadata(md)
}
if md == nil && la.flags.TakeDateFromFilename && !a.NameInfo.Taken.IsZero() {
if md == nil && !a.NameInfo.Taken.IsZero() {
// no exif, but we have a date in the filename and the TakeDateFromFilename is set
a.FromApplication = &assets.Metadata{
DateTaken: a.NameInfo.Taken,
Expand Down

0 comments on commit 5310b9c

Please sign in to comment.