diff --git a/internal/entity/photo_fixtures.go b/internal/entity/photo_fixtures.go index 61b0a4633..964b1fd61 100644 --- a/internal/entity/photo_fixtures.go +++ b/internal/entity/photo_fixtures.go @@ -68,14 +68,14 @@ var PhotoFixtures = PhotoMap{ Keywords: []Keyword{}, Albums: []Album{}, Files: []File{}, - Labels: []PhotoLabel{ + Labels: []PhotoLabel{ LabelFixtures.PhotoLabel(1000000, "flower", 38, "image"), LabelFixtures.PhotoLabel(1000000, "cake", 38, "manual"), }, - CreatedAt: time.Date(2009, 1, 1, 0, 0, 0, 0, time.UTC), - UpdatedAt: time.Date(2008, 1, 1, 0, 0, 0, 0, time.UTC), - EditedAt: nil, - DeletedAt: nil, + CreatedAt: time.Date(2009, 1, 1, 0, 0, 0, 0, time.UTC), + UpdatedAt: time.Date(2008, 1, 1, 0, 0, 0, 0, time.UTC), + EditedAt: nil, + DeletedAt: nil, }, "Photo01": { ID: 1000001, @@ -218,14 +218,14 @@ var PhotoFixtures = PhotoMap{ Keywords: []Keyword{}, Albums: []Album{}, Files: []File{}, - Labels: []PhotoLabel{ + Labels: []PhotoLabel{ LabelFixtures.PhotoLabel(1000003, "cow", 20, "image"), LabelFixtures.PhotoLabel(1000003, "updatePhotoLabel", 20, "manual"), }, - CreatedAt: time.Date(2009, 1, 1, 0, 0, 0, 0, time.UTC), - UpdatedAt: time.Date(2008, 1, 1, 0, 0, 0, 0, time.UTC), - EditedAt: nil, - DeletedAt: nil, + CreatedAt: time.Date(2009, 1, 1, 0, 0, 0, 0, time.UTC), + UpdatedAt: time.Date(2008, 1, 1, 0, 0, 0, 0, time.UTC), + EditedAt: nil, + DeletedAt: nil, }, "Photo04": { ID: 1000004, diff --git a/internal/entity/views.go b/internal/entity/views.go index 458008d19..9a2593485 100644 --- a/internal/entity/views.go +++ b/internal/entity/views.go @@ -1,6 +1,6 @@ package entity -func CreateViews () { +func CreateViews() { labelCounts := `CREATE OR REPLACE VIEW label_counts AS SELECT label_id, SUM(photo_count) AS photo_count FROM ( (SELECT l.id AS label_id, COUNT(*) AS photo_count FROM labels l diff --git a/internal/photoprism/index_mediafile.go b/internal/photoprism/index_mediafile.go index 51aa73e1f..79bb8f483 100644 --- a/internal/photoprism/index_mediafile.go +++ b/internal/photoprism/index_mediafile.go @@ -24,6 +24,7 @@ const ( IndexAdded IndexStatus = "added" IndexSkipped IndexStatus = "skipped" IndexDuplicate IndexStatus = "skipped duplicate" + IndexArchived IndexStatus = "skipped archived" IndexFailed IndexStatus = "failed" ) @@ -144,6 +145,16 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) ( } } + if photo.PhotoQuality == -1 && file.FilePrimary { + // restore photos that have been purged automatically + photo.DeletedAt = nil + } else if photo.DeletedAt != nil { + result.Status = IndexArchived + return result + } + + file.DeletedAt = nil + if file.FilePrimary { primaryFile = file @@ -296,9 +307,6 @@ func (ind *Index) MediaFile(m *MediaFile, o IndexOptions, originalName string) ( } } - photo.DeletedAt = nil - file.DeletedAt = nil - if photoExists { // Estimate location if o.Rescan && photo.NoLocation() { diff --git a/internal/query/photo_counts.go b/internal/query/photo_counts.go index bb810e200..9684bfbab 100644 --- a/internal/query/photo_counts.go +++ b/internal/query/photo_counts.go @@ -15,24 +15,24 @@ func UpdatePhotoCounts() error { /* See internal/entity/views.go - CREATE OR REPLACE VIEW label_counts AS - SELECT label_id, SUM(photo_count) AS photo_count FROM ( - (SELECT l.id AS label_id, COUNT(*) AS photo_count FROM labels l - JOIN photos_labels pl ON pl.label_id = l.id - JOIN photos ph ON pl.photo_id = ph.id - WHERE pl.uncertainty < 100 - AND ph.photo_quality >= 0 - AND ph.photo_private = 0 - AND ph.deleted_at IS NULL GROUP BY l.id) - UNION ALL - (SELECT l.id AS label_id, COUNT(*) AS photo_count FROM labels l - JOIN categories c ON c.category_id = l.id - JOIN photos_labels pl ON pl.label_id = c.label_id - JOIN photos ph ON pl.photo_id = ph.id - WHERE pl.uncertainty < 100 - AND ph.photo_quality >= 0 - AND ph.photo_private = 0 - AND ph.deleted_at IS NULL GROUP BY l.id)) counts GROUP BY label_id + CREATE OR REPLACE VIEW label_counts AS + SELECT label_id, SUM(photo_count) AS photo_count FROM ( + (SELECT l.id AS label_id, COUNT(*) AS photo_count FROM labels l + JOIN photos_labels pl ON pl.label_id = l.id + JOIN photos ph ON pl.photo_id = ph.id + WHERE pl.uncertainty < 100 + AND ph.photo_quality >= 0 + AND ph.photo_private = 0 + AND ph.deleted_at IS NULL GROUP BY l.id) + UNION ALL + (SELECT l.id AS label_id, COUNT(*) AS photo_count FROM labels l + JOIN categories c ON c.category_id = l.id + JOIN photos_labels pl ON pl.label_id = c.label_id + JOIN photos ph ON pl.photo_id = ph.id + WHERE pl.uncertainty < 100 + AND ph.photo_quality >= 0 + AND ph.photo_private = 0 + AND ph.deleted_at IS NULL GROUP BY l.id)) counts GROUP BY label_id */ /* TODO: Requires proper view support in TiDB