func (this *genericDataModelImpl) GetItemPreferences(itemId uint64) (PreferenceArray, error) { if prefs, ok := this.itemPreferenceMap[itemId]; ok { if !this.itemSorted.Contains(itemId) { sort.Sort(prefs) prefs.buildCache() this.itemPreferenceMap[itemId] = prefs this.itemSorted.Add(itemId) } return prefs, nil } return nil, cf.NoSuchItemError(itemId) }
func (this *genericDataModelImpl) PreferenceValue(userId, itemId uint64) (float64, error) { prefs, err := this.GetUserPreferences(userId) if err != nil { return 0, err } values := prefs.Values() for i, id := range prefs.Ids() { if id == itemId { return values[i], nil } } return 0.0, cf.NoSuchItemError(itemId) }