Backend: Add mutex for location updates
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
4263061a89
commit
29db7abfd1
|
@ -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{}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue