nandi/gleanpublic Fork 0
116dd3b
Commits
Clone
git clone https://git.rickub.com/nandi/glean.git
git clone ssh://git@rickub.com/nandi/glean.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Add cache invalidation for feed, article, and peopleUnverified

Julien Robert committed 2026-05-15T13:20:48+02:00 Browse files
116dd3b parent: c1916a6
modified internal/cluster/scoring.go +12 -0
@@ -47,6 +47,18 @@ type ArticleRecommendation struct {
4747 Score float64
4848 }
4949
50+func (e *Engine) InvalidateFeedCache(userDID string) {
51+ e.feedCache.Remove(userDID)
52+}
53+
54+func (e *Engine) InvalidateArticleCache(userDID string) {
55+ e.articleCache.Remove(userDID)
56+}
57+
58+func (e *Engine) InvalidatePeopleCache(userDID string) {
59+ e.peopleCache.Remove(userDID)
60+}
61+
5062 // GetFeedRecommendations returns feed recommendations for a user. Users with
5163 // fewer than 5 subscriptions get cold-start recommendations (embedding-based
5264 // KNN or graph+popular fallback). Results are min-max normalized and
@@ -47,6 +47,18 @@ type ArticleRecommendation struct {
47 Score float6447 Score float64
48 }48 }
49 49
50+func (e *Engine) InvalidateFeedCache(userDID string) {
51+ e.feedCache.Remove(userDID)
52+}
53+
54+func (e *Engine) InvalidateArticleCache(userDID string) {
55+ e.articleCache.Remove(userDID)
56+}
57+
58+func (e *Engine) InvalidatePeopleCache(userDID string) {
59+ e.peopleCache.Remove(userDID)
60+}
61+
50 // GetFeedRecommendations returns feed recommendations for a user. Users with62 // GetFeedRecommendations returns feed recommendations for a user. Users with
51 // fewer than 5 subscriptions get cold-start recommendations (embedding-based63 // fewer than 5 subscriptions get cold-start recommendations (embedding-based
52 // KNN or graph+popular fallback). Results are min-max normalized and64 // KNN or graph+popular fallback). Results are min-max normalized and
modified internal/server/recs_handler.go +6 -4
@@ -5,18 +5,18 @@ import (
55 )
66
77 func (s *Server) handleDismissFeedRecommendation(w http.ResponseWriter, r *http.Request) {
8- s.handleDismiss(w, r, "feed_url", "feed")
8+ s.handleDismiss(w, r, "feed_url", "feed", func(did string) { s.engine.InvalidateFeedCache(did) })
99 }
1010
1111 func (s *Server) handleDismissArticleRecommendation(w http.ResponseWriter, r *http.Request) {
12- s.handleDismiss(w, r, "article_url", "article")
12+ s.handleDismiss(w, r, "article_url", "article", func(did string) { s.engine.InvalidateArticleCache(did) })
1313 }
1414
1515 func (s *Server) handleDismissPersonRecommendation(w http.ResponseWriter, r *http.Request) {
16- s.handleDismiss(w, r, "target_did", "person")
16+ s.handleDismiss(w, r, "target_did", "person", func(did string) { s.engine.InvalidatePeopleCache(did) })
1717 }
1818
19-func (s *Server) handleDismiss(w http.ResponseWriter, r *http.Request, field, targetType string) {
19+func (s *Server) handleDismiss(w http.ResponseWriter, r *http.Request, field, targetType string, invalidateCache func(string)) {
2020 user := currentUser(r)
2121 targetID := r.FormValue(field)
2222 if targetID == "" {
@@ -35,5 +35,7 @@ func (s *Server) handleDismiss(w http.ResponseWriter, r *http.Request, field, ta
3535 return
3636 }
3737
38+ invalidateCache(user.DID)
39+
3840 w.WriteHeader(http.StatusOK)
3941 }
@@ -5,18 +5,18 @@ import (
5 )5 )
6 6
7 func (s *Server) handleDismissFeedRecommendation(w http.ResponseWriter, r *http.Request) {7 func (s *Server) handleDismissFeedRecommendation(w http.ResponseWriter, r *http.Request) {
8- s.handleDismiss(w, r, "feed_url", "feed")8+ s.handleDismiss(w, r, "feed_url", "feed", func(did string) { s.engine.InvalidateFeedCache(did) })
9 }9 }
10 10
11 func (s *Server) handleDismissArticleRecommendation(w http.ResponseWriter, r *http.Request) {11 func (s *Server) handleDismissArticleRecommendation(w http.ResponseWriter, r *http.Request) {
12- s.handleDismiss(w, r, "article_url", "article")12+ s.handleDismiss(w, r, "article_url", "article", func(did string) { s.engine.InvalidateArticleCache(did) })
13 }13 }
14 14
15 func (s *Server) handleDismissPersonRecommendation(w http.ResponseWriter, r *http.Request) {15 func (s *Server) handleDismissPersonRecommendation(w http.ResponseWriter, r *http.Request) {
16- s.handleDismiss(w, r, "target_did", "person")16+ s.handleDismiss(w, r, "target_did", "person", func(did string) { s.engine.InvalidatePeopleCache(did) })
17 }17 }
18 18
19-func (s *Server) handleDismiss(w http.ResponseWriter, r *http.Request, field, targetType string) {19+func (s *Server) handleDismiss(w http.ResponseWriter, r *http.Request, field, targetType string, invalidateCache func(string)) {
20 user := currentUser(r)20 user := currentUser(r)
21 targetID := r.FormValue(field)21 targetID := r.FormValue(field)
22 if targetID == "" {22 if targetID == "" {
@@ -35,5 +35,7 @@ func (s *Server) handleDismiss(w http.ResponseWriter, r *http.Request, field, ta
35 return35 return
36 }36 }
37 37
38+ invalidateCache(user.DID)
39+
38 w.WriteHeader(http.StatusOK)40 w.WriteHeader(http.StatusOK)
39 }41 }