Stacks: Repair merge query #681 #667 #593

This commit is contained in:
Michael Mayer 2020-12-07 17:51:35 +01:00
parent 63a8dbf4ce
commit a43f8be231
3 changed files with 15 additions and 19 deletions

View file

@ -1023,13 +1023,13 @@ func (m *Photo) Stack(meta, uuid bool) (identical Photos, err error) {
switch {
case meta && uuid:
stmt.Where("(taken_at = ? AND taken_src = 'meta' AND cell_id = ? AND camera_serial = ? AND camera_id = ?) OR (uuid <> '' AND uuid = ?)",
stmt = stmt.Where("(taken_at = ? AND taken_src = 'meta' AND cell_id = ? AND camera_serial = ? AND camera_id = ?) OR (uuid <> '' AND uuid = ?)",
m.TakenAt, m.CellID, m.CameraSerial, m.CameraID, m.UUID)
case meta:
stmt.Where("taken_at = ? AND taken_src = 'meta' AND cell_id = ? AND camera_serial = ? AND camera_id = ?",
stmt = stmt.Where("taken_at = ? AND taken_src = 'meta' AND cell_id = ? AND camera_serial = ? AND camera_id = ?",
m.TakenAt, m.CellID, m.CameraSerial, m.CameraID)
case uuid:
stmt.Where("uuid <> '' AND uuid = ?", m.UUID)
stmt = stmt.Where("uuid <> '' AND uuid = ?", m.UUID)
}
if err := stmt.Find(&identical).Error; err != nil {

View file

@ -161,25 +161,21 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) (
photoQuery = entity.UnscopedDb().First(&photo, "photo_path = ? AND photo_name = ?", filePath, fileBase)
// Stack file based on matching location and time metadata?
if Config().Settings().StackMeta() {
if photoQuery.Error != nil && m.MetaData().HasTimeAndPlace() {
metaData = m.MetaData()
photoQuery = entity.UnscopedDb().First(&photo, "photo_lat = ? AND photo_lng = ? AND taken_at = ? AND taken_src = 'meta' AND camera_serial = ?", metaData.Lat, metaData.Lng, metaData.TakenAt, metaData.CameraSerial)
if photoQuery.Error != nil && Config().Settings().StackMeta() && m.MetaData().HasTimeAndPlace() {
metaData = m.MetaData()
photoQuery = entity.UnscopedDb().First(&photo, "photo_lat = ? AND photo_lng = ? AND taken_at = ? AND taken_src = 'meta' AND camera_serial = ?", metaData.Lat, metaData.Lng, metaData.TakenAt, metaData.CameraSerial)
if photoQuery.Error == nil {
fileStacked = true
}
if photoQuery.Error == nil {
fileStacked = true
}
}
// Stack file based on the same unique ID?
if Config().Settings().StackUUID() {
if photoQuery.Error != nil && m.MetaData().HasDocumentID() {
photoQuery = entity.UnscopedDb().First(&photo, "uuid <> '' AND uuid = ?", m.MetaData().DocumentID)
if photoQuery.Error != nil && Config().Settings().StackUUID() && m.MetaData().HasDocumentID() {
photoQuery = entity.UnscopedDb().First(&photo, "uuid <> '' AND uuid = ?", m.MetaData().DocumentID)
if photoQuery.Error == nil {
fileStacked = true
}
if photoQuery.Error == nil {
fileStacked = true
}
}
} else {

View file

@ -121,7 +121,7 @@ func MatchingPhotos(meta, uuid bool) (entities entity.Photos, err error) {
switch {
case meta && uuid:
stmt.Joins(`JOIN photos dup ON photos.id < dup.id
stmt = stmt.Joins(`JOIN photos dup ON photos.id < dup.id
AND photos.photo_single = 0 AND dup.photo_single = 0
AND photos.deleted_at IS NULL AND dup.deleted_at IS NULL
AND ((photos.taken_src = 'meta' AND dup.taken_src = 'meta'
@ -132,7 +132,7 @@ func MatchingPhotos(meta, uuid bool) (entities entity.Photos, err error) {
AND photos.camera_serial = dup.camera_serial) OR
(photos.uuid <> '' AND photos.uuid = dup.uuid))`)
case meta:
stmt.Joins(`JOIN photos dup ON photos.id < dup.id
stmt = stmt.Joins(`JOIN photos dup ON photos.id < dup.id
AND photos.photo_single = 0
AND dup.photo_single = 0
AND photos.deleted_at IS NULL AND dup.deleted_at IS NULL
@ -143,7 +143,7 @@ func MatchingPhotos(meta, uuid bool) (entities entity.Photos, err error) {
AND photos.camera_id = dup.camera_id
AND photos.camera_serial = dup.camera_serial))`)
case uuid:
stmt.Joins(`JOIN photos dup ON photos.id < dup.id
stmt = stmt.Joins(`JOIN photos dup ON photos.id < dup.id
AND photos.photo_single = 0 AND dup.photo_single = 0
AND photos.deleted_at IS NULL AND dup.deleted_at IS NULL
AND (photos.uuid <> '' AND photos.uuid = dup.uuid)`)