b37d4472e4
Plus some mutex and config refactoring along the way... Signed-off-by: Michael Mayer <michael@liquidbytes.net>
42 lines
1,012 B
Go
42 lines
1,012 B
Go
package entity
|
|
|
|
import (
|
|
"github.com/jinzhu/gorm"
|
|
"github.com/photoprism/photoprism/internal/mutex"
|
|
)
|
|
|
|
// Photo labels are weighted by uncertainty (100 - confidence)
|
|
type PhotoLabel struct {
|
|
PhotoID uint `gorm:"primary_key;auto_increment:false"`
|
|
LabelID uint `gorm:"primary_key;auto_increment:false;index"`
|
|
LabelUncertainty int
|
|
LabelSource string
|
|
Photo *Photo
|
|
Label *Label
|
|
}
|
|
|
|
func (PhotoLabel) TableName() string {
|
|
return "photos_labels"
|
|
}
|
|
|
|
func NewPhotoLabel(photoId, labelId uint, uncertainty int, source string) *PhotoLabel {
|
|
result := &PhotoLabel{
|
|
PhotoID: photoId,
|
|
LabelID: labelId,
|
|
LabelUncertainty: uncertainty,
|
|
LabelSource: source,
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
func (m *PhotoLabel) FirstOrCreate(db *gorm.DB) *PhotoLabel {
|
|
mutex.Db.Lock()
|
|
defer mutex.Db.Unlock()
|
|
|
|
if err := db.FirstOrCreate(m, "photo_id = ? AND label_id = ?", m.PhotoID, m.LabelID).Error; err != nil {
|
|
log.Errorf("photo label: %s", err)
|
|
}
|
|
|
|
return m
|
|
}
|