From b3f4f3b4b755a05415588420bd6b199c37da1458 Mon Sep 17 00:00:00 2001 From: Dustin Oprea Date: Sun, 22 Nov 2020 01:46:30 -0500 Subject: [PATCH] tags.go: Serialized adds/gets on index https://github.com/photoprism/photoprism/issues/600 --- v3/tags.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/v3/tags.go b/v3/tags.go index cd08416..9e3992d 100644 --- a/v3/tags.go +++ b/v3/tags.go @@ -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]