tags.go: Serialized adds/gets on index

https://github.com/photoprism/photoprism/issues/600
pull/49/head
Dustin Oprea 2020-11-22 01:46:30 -05:00 committed by WendelHime
parent 9d79f79757
commit 6568ab261b
1 changed files with 9 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package exif
import (
"fmt"
"sync"
"github.com/dsoprea/go-logging"
"gopkg.in/yaml.v2"
@ -177,6 +178,8 @@ func (it *IndexedTag) DoesSupportType(tagType exifcommon.TagTypePrimitive) bool
type TagIndex struct {
tagsByIfd map[string]map[uint16]*IndexedTag
tagsByIfdR map[string]map[string]*IndexedTag
mutex sync.Mutex
}
// NewTagIndex returns a new TagIndex struct.
@ -197,6 +200,9 @@ func (ti *TagIndex) Add(it *IndexedTag) (err error) {
}
}()
ti.mutex.Lock()
defer ti.mutex.Unlock()
// Store by ID.
family, found := ti.tagsByIfd[it.IfdPath]
@ -242,6 +248,9 @@ func (ti *TagIndex) Get(ii *exifcommon.IfdIdentity, id uint16) (it *IndexedTag,
log.PanicIf(err)
}
ti.mutex.Lock()
defer ti.mutex.Unlock()
ifdPath := ii.UnindexedString()
family, found := ti.tagsByIfd[ifdPath]