Import: Refactor indexing of related original filenames #2623

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2022-09-15 03:03:49 +02:00
parent 90567072cd
commit 0cb9cbc56a
2 changed files with 7 additions and 4 deletions

View file

@ -23,7 +23,6 @@ type ImportJob struct {
func ImportWorker(jobs <-chan ImportJob) { func ImportWorker(jobs <-chan ImportJob) {
for job := range jobs { for job := range jobs {
var destMainFileName string var destMainFileName string
relatedOriginalNames := make(map[string]string)
o := job.IndexOpt o := job.IndexOpt
imp := job.Imp imp := job.Imp
@ -31,6 +30,9 @@ func ImportWorker(jobs <-chan ImportJob) {
impPath := job.ImportOpt.Path impPath := job.ImportOpt.Path
related := job.Related related := job.Related
// relatedOriginalNames contains the original filenames of related files.
relatedOriginalNames := make(map[string]string, len(related.Files))
if related.Main == nil { if related.Main == nil {
log.Warnf("import: %s belongs to no supported media file", clean.Log(fs.RelName(job.FileName, impPath))) log.Warnf("import: %s belongs to no supported media file", clean.Log(fs.RelName(job.FileName, impPath)))
continue continue
@ -61,7 +63,7 @@ func ImportWorker(jobs <-chan ImportJob) {
if destFileName, err := imp.DestinationFilename(related.Main, f); err == nil { if destFileName, err := imp.DestinationFilename(related.Main, f); err == nil {
destDir := filepath.Dir(destFileName) destDir := filepath.Dir(destFileName)
// Keep original name of related files after they are renamed, so they are indexed with the original name. // Remember the original filenames of related files, so they can later be indexed and searched.
relatedOriginalNames[destFileName] = relFileName relatedOriginalNames[destFileName] = relFileName
if fs.PathExists(destDir) { if fs.PathExists(destDir) {
@ -235,7 +237,7 @@ func ImportWorker(jobs <-chan ImportJob) {
} }
} }
// Index related MediaFile. // Index related media file including its original filename.
res := ind.MediaFile(f, o, relatedOriginalNames[f.FileName()], photoUID) res := ind.MediaFile(f, o, relatedOriginalNames[f.FileName()], photoUID)
// Save file error. // Save file error.

View file

@ -1,13 +1,14 @@
package photoprism package photoprism
import ( import (
"testing"
"github.com/photoprism/photoprism/internal/classify" "github.com/photoprism/photoprism/internal/classify"
"github.com/photoprism/photoprism/internal/config" "github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/entity" "github.com/photoprism/photoprism/internal/entity"
"github.com/photoprism/photoprism/internal/face" "github.com/photoprism/photoprism/internal/face"
"github.com/photoprism/photoprism/internal/nsfw" "github.com/photoprism/photoprism/internal/nsfw"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
"testing"
) )
func TestImportWorker_OriginalFileNames(t *testing.T) { func TestImportWorker_OriginalFileNames(t *testing.T) {