photoprism/internal/entity/subject_names.go
Michael Mayer c74fcbf282 People: Show real name instead of uid in logs #1438 #2182
Since caching all subject data proved too complex in the time available,
this implementation uses a simple key/value lookup table to cache
subject names and perform backward searches by uid.
2022-04-04 14:21:43 +02:00

22 lines
544 B
Go

package entity
// SubjNames is a uid/name (reverse) lookup map
var SubjNames = NewStringMap(nil)
func init() {
onReady = append(onReady, initSubjNames)
}
// initSubjNames initializes the subject uid/name (reverse) lookup table.
func initSubjNames() {
var results KeyValues
// Fetch subjects from the database.
if err := UnscopedDb().Model(Subject{}).Select("subj_uid AS k, subj_name AS v").
Scan(&results).Error; err != nil {
log.Warnf("subjects: %s (init lookup)", err)
} else {
SubjNames = NewStringMap(results.Strings())
}
}