Indexer: Don't optimize merged photos
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
fe9884331f
commit
d82a0ab525
3 changed files with 23 additions and 11 deletions
|
@ -92,9 +92,9 @@ func (m *Photo) EstimatePlace() {
|
|||
}
|
||||
|
||||
// Optimize photo data, improve if possible.
|
||||
func (m *Photo) Optimize(stackMeta, stackUuid bool) (updated bool, err error) {
|
||||
func (m *Photo) Optimize(stackMeta, stackUuid bool) (updated bool, merged Photos, err error) {
|
||||
if !m.HasID() {
|
||||
return false, errors.New("photo: can't maintain, id is empty")
|
||||
return false, merged, errors.New("photo: can't maintain, id is empty")
|
||||
}
|
||||
|
||||
current := *m
|
||||
|
@ -103,10 +103,8 @@ func (m *Photo) Optimize(stackMeta, stackUuid bool) (updated bool, err error) {
|
|||
m.UpdateLocation()
|
||||
}
|
||||
|
||||
if merged, err := m.Stack(stackMeta, stackUuid); err != nil {
|
||||
if merged, err = m.Stack(stackMeta, stackUuid); err != nil {
|
||||
log.Errorf("photo: %s (stack)", err)
|
||||
} else {
|
||||
log.Infof("photo: merged uid %s with %s", m.PhotoUID, merged.UIDs())
|
||||
}
|
||||
|
||||
m.EstimatePlace()
|
||||
|
@ -133,10 +131,10 @@ func (m *Photo) Optimize(stackMeta, stackUuid bool) (updated bool, err error) {
|
|||
checked := Timestamp()
|
||||
|
||||
if reflect.DeepEqual(*m, current) {
|
||||
return false, m.Update("CheckedAt", &checked)
|
||||
return false, merged, m.Update("CheckedAt", &checked)
|
||||
}
|
||||
|
||||
m.CheckedAt = &checked
|
||||
|
||||
return true, m.Save()
|
||||
return true, merged, m.Save()
|
||||
}
|
||||
|
|
|
@ -53,23 +53,30 @@ func TestPhoto_EstimateCountry(t *testing.T) {
|
|||
func TestPhoto_Optimize(t *testing.T) {
|
||||
t.Run("update", func(t *testing.T) {
|
||||
photo := PhotoFixtures.Get("Photo19")
|
||||
if updated, err := photo.Optimize(true, true); err != nil {
|
||||
if updated, merged, err := photo.Optimize(false, false); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if !updated {
|
||||
t.Error("photo should be updated")
|
||||
} else if len(merged) > 0 {
|
||||
t.Error("no photos should be merged")
|
||||
}
|
||||
|
||||
if updated, err := photo.Optimize(false, false); err != nil {
|
||||
if updated, merged, err := photo.Optimize(false, false); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if updated {
|
||||
t.Error("photo should NOT be updated")
|
||||
} else if len(merged) > 0 {
|
||||
t.Error("no photos should be merged")
|
||||
}
|
||||
})
|
||||
t.Run("photo without id", func(t *testing.T) {
|
||||
photo := Photo{}
|
||||
bool, err := photo.Optimize(false, false)
|
||||
bool, merged, err := photo.Optimize(false, false)
|
||||
assert.Error(t, err)
|
||||
assert.False(t, bool)
|
||||
|
||||
if len(merged) > 0 {
|
||||
t.Error("no photos should be merged")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -76,12 +76,19 @@ func (worker *Meta) Start() (err error) {
|
|||
|
||||
done[photo.PhotoUID] = true
|
||||
|
||||
if updated, err := photo.Optimize(worker.conf.Settings().StackMeta(), worker.conf.Settings().StackUUID()); err != nil {
|
||||
updated, merged, err := photo.Optimize(worker.conf.Settings().StackMeta(), worker.conf.Settings().StackUUID())
|
||||
|
||||
if err != nil {
|
||||
log.Errorf("metadata: %s (optimize photo)", err)
|
||||
} else if updated {
|
||||
optimized++
|
||||
log.Debugf("metadata: optimized photo %s", photo.String())
|
||||
}
|
||||
|
||||
for _, m := range merged {
|
||||
log.Infof("metadata: stacked %s", m.PhotoUID)
|
||||
done[m.PhotoUID] = true
|
||||
}
|
||||
}
|
||||
|
||||
if mutex.MetaWorker.Canceled() {
|
||||
|
|
Loading…
Reference in a new issue