photoprism/internal/entity/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

36 lines
661 B
Go

package entity
import (
"strings"
"github.com/jinzhu/gorm"
"github.com/photoprism/photoprism/internal/mutex"
)
// Keyword for full text search
type Keyword struct {
ID uint `gorm:"primary_key"`
Keyword string `gorm:"type:varchar(64);index;"`
Skip bool
}
func NewKeyword(keyword string) *Keyword {
keyword = strings.ToLower(strings.TrimSpace(keyword))
result := &Keyword{
Keyword: keyword,
}
return result
}
func (m *Keyword) FirstOrCreate(db *gorm.DB) *Keyword {
mutex.Db.Lock()
defer mutex.Db.Unlock()
if err := db.FirstOrCreate(m, "keyword = ?", m.Keyword).Error; err != nil {
log.Errorf("keyword: %s", err)
}
return m
}