Search: Remove unused countries from dropdown #982
This commit is contained in:
parent
2a96c019f4
commit
8177f36f43
6 changed files with 38 additions and 14 deletions
|
@ -35,8 +35,8 @@ func (m *Files) Init() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
if err := query.CleanDuplicates(); err != nil {
|
||||
return fmt.Errorf("%s (clean duplicates)", err.Error())
|
||||
if err := query.PurgeDuplicates(); err != nil {
|
||||
return fmt.Errorf("%s (purge duplicates)", err.Error())
|
||||
}
|
||||
|
||||
files, err := query.IndexedFiles()
|
||||
|
|
|
@ -242,7 +242,7 @@ func (w *Purge) Start(opt PurgeOptions) (purgedFiles map[string]bool, purgedPhot
|
|||
log.Info("purge: searching index for unassigned primary files")
|
||||
|
||||
if err := query.FixPrimaries(); err != nil {
|
||||
log.Errorf("purge: %s (find unassigned primaries)", err.Error())
|
||||
log.Errorf("purge: %s (fix primary files)", err.Error())
|
||||
}
|
||||
|
||||
log.Info("purge: searching index for hidden media files")
|
||||
|
@ -251,16 +251,20 @@ func (w *Purge) Start(opt PurgeOptions) (purgedFiles map[string]bool, purgedPhot
|
|||
return purgedFiles, purgedPhotos, err
|
||||
}
|
||||
|
||||
if err := query.PurgeDuplicates(); err != nil {
|
||||
log.Errorf("purge: %s (duplicates)", err)
|
||||
}
|
||||
|
||||
if err := query.PurgeUnusedCountries(); err != nil {
|
||||
log.Errorf("purge: %s (countries)", err)
|
||||
}
|
||||
|
||||
if err := query.UpdateMissingAlbumEntries(); err != nil {
|
||||
log.Errorf("purge: %s (update albums)", err.Error())
|
||||
log.Errorf("purge: %s (album entries)", err)
|
||||
}
|
||||
|
||||
if err := entity.UpdatePhotoCounts(); err != nil {
|
||||
log.Errorf("purge: %s (update photo counts)", err)
|
||||
}
|
||||
|
||||
if err := query.CleanDuplicates(); err != nil {
|
||||
log.Errorf("purge: %s (clean duplicates)", err)
|
||||
log.Errorf("purge: %s (photo counts)", err)
|
||||
}
|
||||
|
||||
return purgedFiles, purgedPhotos, nil
|
||||
|
|
9
internal/query/countries.go
Normal file
9
internal/query/countries.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package query
|
||||
|
||||
// PurgeUnusedCountries removes countries without any photos.
|
||||
func PurgeUnusedCountries() error {
|
||||
switch DbDialect() {
|
||||
default:
|
||||
return UnscopedDb().Exec(`DELETE FROM countries WHERE id NOT IN (SELECT photo_country FROM photos)`).Error
|
||||
}
|
||||
}
|
11
internal/query/countries_test.go
Normal file
11
internal/query/countries_test.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package query
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPurgeUnusedCountries(t *testing.T) {
|
||||
if err := PurgeUnusedCountries(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
|
@ -6,8 +6,8 @@ import (
|
|||
"github.com/photoprism/photoprism/internal/entity"
|
||||
)
|
||||
|
||||
// CleanDuplicates removes all files from the duplicates table that don't exist in the files table.
|
||||
func CleanDuplicates() error {
|
||||
// PurgeDuplicates deletes all files from the duplicates table that don't exist in the files table.
|
||||
func PurgeDuplicates() error {
|
||||
if err := UnscopedDb().Delete(entity.Duplicate{}, "file_hash IN (SELECT d.file_hash FROM duplicates d LEFT JOIN files f ON d.file_hash = f.file_hash AND f.file_missing = 0 AND f.deleted_at IS NULL WHERE f.file_hash IS NULL)").Error; err == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ func CleanDuplicates() error {
|
|||
return UnscopedDb().Delete(entity.Duplicate{}, "file_hash IN (SELECT file_hash FROM (SELECT d.file_hash FROM duplicates d LEFT JOIN files f ON d.file_hash = f.file_hash AND f.file_missing = 0 AND f.deleted_at IS NULL WHERE f.file_hash IS NULL) AS tmp)").Error
|
||||
}
|
||||
|
||||
// Duplicates returns duplicate files in the range of limit and offset sorted by file name.
|
||||
// Duplicates finds duplicate files in the range of limit and offset sorted by file name.
|
||||
func Duplicates(limit, offset int, pathName string) (files entity.Duplicates, err error) {
|
||||
if strings.HasPrefix(pathName, "/") {
|
||||
pathName = pathName[1:]
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCleanDuplicates(t *testing.T) {
|
||||
func TestPurgeDuplicates(t *testing.T) {
|
||||
fileName := "hd89e5yhb8p9h.jpg"
|
||||
|
||||
if err := entity.AddDuplicate(
|
||||
|
@ -27,7 +27,7 @@ func TestCleanDuplicates(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err := CleanDuplicates()
|
||||
err := PurgeDuplicates()
|
||||
|
||||
assert.NoError(t, err)
|
||||
|
||||
|
|
Loading…
Reference in a new issue