DeletePreference 删除偏好
( ctx context.Context, userID string, category PreferenceCategory, key string, )
| 250 | |
| 251 | // DeletePreference 删除偏好 |
| 252 | func (pm *PreferenceManager) DeletePreference( |
| 253 | ctx context.Context, |
| 254 | userID string, |
| 255 | category PreferenceCategory, |
| 256 | key string, |
| 257 | ) error { |
| 258 | pm.mu.Lock() |
| 259 | defer pm.mu.Unlock() |
| 260 | |
| 261 | // 从主存储中删除 |
| 262 | prefs := pm.preferences[userID] |
| 263 | newPrefs := []*Preference{} |
| 264 | for _, p := range prefs { |
| 265 | if p.Category != category || p.Key != key { |
| 266 | newPrefs = append(newPrefs, p) |
| 267 | } |
| 268 | } |
| 269 | pm.preferences[userID] = newPrefs |
| 270 | |
| 271 | // 从索引中删除 |
| 272 | indexKey := fmt.Sprintf("%s:%s", userID, category) |
| 273 | indexPrefs := pm.categoryIndex[indexKey] |
| 274 | newIndexPrefs := []*Preference{} |
| 275 | for _, p := range indexPrefs { |
| 276 | if p.Key != key { |
| 277 | newIndexPrefs = append(newIndexPrefs, p) |
| 278 | } |
| 279 | } |
| 280 | pm.categoryIndex[indexKey] = newIndexPrefs |
| 281 | |
| 282 | return nil |
| 283 | } |
| 284 | |
| 285 | // GetTopPreferences 获取强度最高的 N 个偏好 |
| 286 | func (pm *PreferenceManager) GetTopPreferences( |
no outgoing calls