ListPreferences 列出用户的所有偏好
( ctx context.Context, userID string, category PreferenceCategory, )
| 209 | |
| 210 | // ListPreferences 列出用户的所有偏好 |
| 211 | func (pm *PreferenceManager) ListPreferences( |
| 212 | ctx context.Context, |
| 213 | userID string, |
| 214 | category PreferenceCategory, |
| 215 | ) ([]*Preference, error) { |
| 216 | pm.mu.RLock() |
| 217 | defer pm.mu.RUnlock() |
| 218 | |
| 219 | if category == "" { |
| 220 | // 返回所有偏好 |
| 221 | return pm.preferences[userID], nil |
| 222 | } |
| 223 | |
| 224 | // 返回特定类别的偏好 |
| 225 | indexKey := fmt.Sprintf("%s:%s", userID, category) |
| 226 | return pm.categoryIndex[indexKey], nil |
| 227 | } |
| 228 | |
| 229 | // UpdatePreference 更新偏好 |
| 230 | func (pm *PreferenceManager) UpdatePreference( |
no outgoing calls