photoprism/internal/entity/photo_keyword.go
Michael Mayer b37d4472e4 Backend: Use original file if thumb size exceeds limit #172
Plus some mutex and config refactoring along the way...

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-01-08 19:51:21 +01:00

35 lines
757 B
Go

package entity
import (
"github.com/jinzhu/gorm"
"github.com/photoprism/photoprism/internal/mutex"
)
type PhotoKeyword struct {
PhotoID uint `gorm:"primary_key;auto_increment:false"`
KeywordID uint `gorm:"primary_key;auto_increment:false;index"`
}
func (PhotoKeyword) TableName() string {
return "photos_keywords"
}
func NewPhotoKeyword(photoID, keywordID uint) *PhotoKeyword {
result := &PhotoKeyword{
PhotoID: photoID,
KeywordID: keywordID,
}
return result
}
func (m *PhotoKeyword) FirstOrCreate(db *gorm.DB) *PhotoKeyword {
mutex.Db.Lock()
defer mutex.Db.Unlock()
if err := db.FirstOrCreate(m, "photo_id = ? AND keyword_id = ?", m.PhotoID, m.KeywordID).Error; err != nil {
log.Errorf("photo keyword: %s", err)
}
return m
}