MCPcopy Create free account
hub / github.com/astercloud/aster / DeletePreference

Method DeletePreference

pkg/memory/preference.go:252–283  ·  view source on GitHub ↗

DeletePreference 删除偏好

(
	ctx context.Context,
	userID string,
	category PreferenceCategory,
	key string,
)

Source from the content-addressed store, hash-verified

250
251// DeletePreference 删除偏好
252func (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 个偏好
286func (pm *PreferenceManager) GetTopPreferences(

Calls

no outgoing calls

Tested by 1