Backend: Add mutex for location updates

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-01-02 06:10:28 +01:00
parent 4263061a89
commit 29db7abfd1
2 changed files with 16 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package entity
import (
"strings"
"sync"
"time"
"github.com/jinzhu/gorm"
@ -10,6 +11,8 @@ import (
"github.com/photoprism/photoprism/internal/util"
)
var locationMutex = sync.Mutex{}
// Photo location
type Location struct {
ID string `gorm:"type:varbinary(16);primary_key;auto_increment:false;"`
@ -23,6 +26,16 @@ type Location struct {
UpdatedAt time.Time
}
// Locks locations for updates
func (Location) Lock() {
locationMutex.Lock()
}
// Unlock locations for updates
func (Location) Unlock() {
locationMutex.Unlock()
}
func NewLocation(lat, lng float64) *Location {
result := &Location{}

View file

@ -365,6 +365,9 @@ func (ind *Index) indexLocation(mediaFile *MediaFile, photo *entity.Photo, label
var keywords []string
if location, err := mediaFile.Location(); err == nil {
location.Lock()
defer location.Unlock()
err := location.Find(ind.db)
if err != nil {