Metadata: Add --force flag to optimize command #1736
This commit is contained in:
parent
9da2e92fb6
commit
04cde0f392
6 changed files with 21 additions and 14 deletions
|
@ -13,12 +13,18 @@ import (
|
|||
|
||||
// OptimizeCommand registers the index cli command.
|
||||
var OptimizeCommand = cli.Command{
|
||||
Name: "optimize",
|
||||
Usage: "Updates estimates, titles, and descriptions",
|
||||
Name: "optimize",
|
||||
Usage: "Updates estimates, titles, and other metadata",
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "force, f",
|
||||
Usage: "update all, including recently estimated",
|
||||
},
|
||||
},
|
||||
Action: optimizeAction,
|
||||
}
|
||||
|
||||
// optimizeAction updates metadata such as titles and estimate.
|
||||
// optimizeAction updates estimates, titles, and other metadata.
|
||||
func optimizeAction(ctx *cli.Context) error {
|
||||
start := time.Now()
|
||||
|
||||
|
@ -38,9 +44,10 @@ func optimizeAction(ctx *cli.Context) error {
|
|||
log.Infof("config: read-only mode enabled")
|
||||
}
|
||||
|
||||
force := ctx.Bool("force")
|
||||
worker := workers.NewMeta(conf)
|
||||
|
||||
if err := worker.Start(time.Second * 15); err != nil {
|
||||
if err := worker.Start(time.Second*15, force); err != nil {
|
||||
return err
|
||||
} else {
|
||||
elapsed := time.Since(start)
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
// Optimize photo data, improve if possible.
|
||||
func (m *Photo) Optimize(mergeMeta, mergeUuid, estimatePlace bool) (updated bool, merged Photos, err error) {
|
||||
func (m *Photo) Optimize(mergeMeta, mergeUuid, estimatePlace, force bool) (updated bool, merged Photos, err error) {
|
||||
if !m.HasID() {
|
||||
return false, merged, errors.New("photo: can't maintain, id is empty")
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func (m *Photo) Optimize(mergeMeta, mergeUuid, estimatePlace bool) (updated bool
|
|||
}
|
||||
|
||||
if estimatePlace {
|
||||
m.EstimatePlace(false)
|
||||
m.EstimatePlace(force)
|
||||
}
|
||||
|
||||
labels := m.ClassifyLabels()
|
||||
|
|
|
@ -10,7 +10,7 @@ func TestPhoto_Optimize(t *testing.T) {
|
|||
t.Run("update", func(t *testing.T) {
|
||||
photo := PhotoFixtures.Get("Photo19")
|
||||
|
||||
if updated, merged, err := photo.Optimize(false, false, true); err != nil {
|
||||
if updated, merged, err := photo.Optimize(false, false, true, false); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !updated {
|
||||
t.Error("photo should be updated")
|
||||
|
@ -18,7 +18,7 @@ func TestPhoto_Optimize(t *testing.T) {
|
|||
t.Error("no photos should be merged")
|
||||
}
|
||||
|
||||
if updated, merged, err := photo.Optimize(false, false, true); err != nil {
|
||||
if updated, merged, err := photo.Optimize(false, false, true, false); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if updated {
|
||||
t.Errorf("photo should NOT be updated, merged: %+v", merged)
|
||||
|
@ -28,7 +28,7 @@ func TestPhoto_Optimize(t *testing.T) {
|
|||
})
|
||||
t.Run("photo without id", func(t *testing.T) {
|
||||
photo := Photo{}
|
||||
result, merged, err := photo.Optimize(false, false, true)
|
||||
result, merged, err := photo.Optimize(false, false, true, false)
|
||||
assert.Error(t, err)
|
||||
assert.False(t, result)
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ func (m *Meta) originalsPath() string {
|
|||
}
|
||||
|
||||
// Start metadata optimization routine.
|
||||
func (m *Meta) Start(delay time.Duration) (err error) {
|
||||
func (m *Meta) Start(delay time.Duration, force bool) (err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
err = fmt.Errorf("metadata: %s (panic)\nstack: %s", r, debug.Stack())
|
||||
|
@ -87,7 +87,7 @@ func (m *Meta) Start(delay time.Duration) (err error) {
|
|||
|
||||
done[photo.PhotoUID] = true
|
||||
|
||||
updated, merged, err := photo.Optimize(settings.StackMeta(), settings.StackUUID(), settings.Features.Estimates)
|
||||
updated, merged, err := photo.Optimize(settings.StackMeta(), settings.StackUUID(), settings.Features.Estimates, force)
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("metadata: %s (optimize photo)", err)
|
||||
|
|
|
@ -23,13 +23,13 @@ func TestPrism_Start(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if err := worker.Start(time.Second); err == nil {
|
||||
if err := worker.Start(time.Second, true); err == nil {
|
||||
t.Fatal("error expected")
|
||||
}
|
||||
|
||||
mutex.MetaWorker.Stop()
|
||||
|
||||
if err := worker.Start(time.Second); err != nil {
|
||||
if err := worker.Start(time.Second, true); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ func StartMeta(conf *config.Config) {
|
|||
if !mutex.WorkersBusy() {
|
||||
go func() {
|
||||
worker := NewMeta(conf)
|
||||
if err := worker.Start(time.Minute); err != nil {
|
||||
if err := worker.Start(time.Minute, false); err != nil {
|
||||
log.Warnf("metadata: %s", err)
|
||||
}
|
||||
}()
|
||||
|
|
Loading…
Reference in a new issue