Skip to content

Commit

Permalink
refactor: Aggregate directory at the end
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <[email protected]>
  • Loading branch information
ViBiOh committed Oct 23, 2022
1 parent 9833c98 commit fc2713e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
15 changes: 13 additions & 2 deletions pkg/crud/crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ func (a App) start(ctx context.Context) {

done := ctx.Done()

var directories []absto.Item

err := a.storageApp.Walk(ctx, "", func(item absto.Item) error {
select {
case <-done:
Expand All @@ -167,12 +169,21 @@ func (a App) start(ctx context.Context) {
}

item = a.sanitizeName(ctx, item)
a.notify(ctx, provider.NewStartEvent(item))

if item.IsDir {
directories = append(directories, item)
} else {
a.notify(ctx, provider.NewStartEvent(item))
}

return nil
})
if err != nil {
logger.Error("%s", err)
logger.Error("start: %s", err)
}

for _, directory := range directories {
a.notify(ctx, provider.NewStartEvent(directory))
}
}

Expand Down
15 changes: 13 additions & 2 deletions pkg/crud/regenerate.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,23 @@ func (a App) regenerate(w http.ResponseWriter, r *http.Request, request provider
}

go func(ctx context.Context) {
var directories []absto.Item

err := a.storageApp.Walk(ctx, pathname, func(item absto.Item) error {
a.notify(ctx, provider.NewRestartEvent(item, subset))
if item.IsDir {
directories = append(directories, item)
} else {
a.notify(ctx, provider.NewRestartEvent(item, subset))
}

return nil
})
if err != nil {
logger.Error("error during regenerate of `%s`: %s", pathname, err)
logger.Error("regenerate of `%s`: %s", pathname, err)
}

for _, directory := range directories {
a.notify(ctx, provider.NewStartEvent(directory))
}
}(tracer.CopyToBackground(ctx))

Expand Down
2 changes: 1 addition & 1 deletion pkg/exif/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (a App) handleStartEvent(ctx context.Context, event provider.Event) error {
return nil
}

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

func (a App) handleUploadEvent(ctx context.Context, item absto.Item, aggregate bool) error {
Expand Down

0 comments on commit fc2713e

Please sign in to comment.