Skip to content

Commit

Permalink
fix: Fixing aggregate wrong condition
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed May 17, 2022
1 parent 1ecee1d commit edbe749
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
image: vibioh/exas
environment:
EXAS_STORAGE_FILE_SYSTEM_DIRECTORY: '/data'
EXAS_GEOCODE_URL: 'https://nominatim.openstreetmap.org'
volumes:
- ${DATA_DIR}:/data
user: '${DATA_USER_ID}'
Expand Down
2 changes: 1 addition & 1 deletion pkg/exif/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (a App) computeAndSaveAggregate(ctx context.Context, dir absto.Item) error
minDate, maxDate = aggregateDate(minDate, maxDate, exifData.Date)
}

if !exifData.Geocode.HasAddress() {
if exifData.Geocode.HasAddress() {
directoryAggregate.ingest(exifData.Geocode)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/exif/amqp.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ func (a App) AmqpHandler(message amqp.Delivery) error {
return fmt.Errorf("unable to save: %s", err)
}

return a.processExif(ctx, resp.Item, resp.Exif)
return a.processExif(ctx, resp.Item, resp.Exif, true)
}
14 changes: 9 additions & 5 deletions pkg/exif/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (a App) EventConsumer(ctx context.Context, e provider.Event) {
getEventLogger(e.Item).Error("unable to start: %s", err)
}
case provider.UploadEvent:
if err = a.handleUploadEvent(ctx, e.Item); err != nil {
if err = a.handleUploadEvent(ctx, e.Item, true); err != nil {
getEventLogger(e.Item).Error("unable to upload: %s", err)
}
case provider.RenameEvent:
Expand Down Expand Up @@ -74,10 +74,10 @@ func (a App) handleStartEvent(ctx context.Context, event provider.Event) error {
return nil
}

return a.handleUploadEvent(ctx, item)
return a.handleUploadEvent(ctx, item, !forced)
}

func (a App) handleUploadEvent(ctx context.Context, item absto.Item) error {
func (a App) handleUploadEvent(ctx context.Context, item absto.Item, aggregate bool) error {
if !a.CanHaveExif(item) {
return nil
}
Expand All @@ -95,14 +95,18 @@ func (a App) handleUploadEvent(ctx context.Context, item absto.Item) error {
return nil
}

return a.processExif(ctx, item, exif)
return a.processExif(ctx, item, exif, aggregate)
}

func (a App) processExif(ctx context.Context, item absto.Item, exif exas.Exif) error {
func (a App) processExif(ctx context.Context, item absto.Item, exif exas.Exif, aggregate bool) error {
if err := a.updateDate(ctx, item, exif); err != nil {
return fmt.Errorf("unable to update date: %s", err)
}

if !aggregate {
return nil
}

if err := a.aggregate(ctx, item); err != nil {
return fmt.Errorf("unable to aggregate folder: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/exif/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func newAggregate() locationAggregate {
return make(map[string]map[string]int64)
}

func (a *locationAggregate) ingest(geocoding model.Geocode) {
func (a locationAggregate) ingest(geocoding model.Geocode) {
for _, level := range levels {
a.inc(level, geocoding.Address[level])
}
Expand Down

0 comments on commit edbe749

Please sign in to comment.