Fetch and cache missing profile details on demandUnverified
0438036 parent: c898429 modified
internal/server/profile_handler.go +9 -0 | @@ -35,6 +35,15 @@ func (s *Server) handleProfile(w http.ResponseWriter, r *http.Request) { | ||
| 35 | 35 | return |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | + if !profileUser.AvatarURL.Valid || profileUser.AvatarURL.String == "" { | |
| 39 | + _, displayName, avatarURL, err := atproto.FetchProfile(r.Context(), did) | |
| 40 | + if err == nil && avatarURL != "" { | |
| 41 | + _ = s.db.UpdateUserProfile(r.Context(), did, displayName, avatarURL) | |
| 42 | + profileUser.DisplayName = nullString(displayName) | |
| 43 | + profileUser.AvatarURL = nullString(avatarURL) | |
| 44 | + } | |
| 45 | + } | |
| 46 | + | |
| 38 | 47 | subs, _ := s.db.ListSubscriptions(r.Context(), did, "", 50, 0) |
| 39 | 48 | annotations, _ := s.db.ListAnnotations(r.Context(), "", "", did, 50, 0) |
| 40 | 49 | subCount, _ := s.db.GetSubscriptionCount(r.Context(), did) |
| @@ -35,6 +35,15 @@ func (s *Server) handleProfile(w http.ResponseWriter, r *http.Request) { | |||
| 35 | return | 35 | return |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | + if !profileUser.AvatarURL.Valid || profileUser.AvatarURL.String == "" { | ||
| 39 | + _, displayName, avatarURL, err := atproto.FetchProfile(r.Context(), did) | ||
| 40 | + if err == nil && avatarURL != "" { | ||
| 41 | + _ = s.db.UpdateUserProfile(r.Context(), did, displayName, avatarURL) | ||
| 42 | + profileUser.DisplayName = nullString(displayName) | ||
| 43 | + profileUser.AvatarURL = nullString(avatarURL) | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + | ||
| 38 | subs, _ := s.db.ListSubscriptions(r.Context(), did, "", 50, 0) | 47 | subs, _ := s.db.ListSubscriptions(r.Context(), did, "", 50, 0) |
| 39 | annotations, _ := s.db.ListAnnotations(r.Context(), "", "", did, 50, 0) | 48 | annotations, _ := s.db.ListAnnotations(r.Context(), "", "", did, 50, 0) |
| 40 | subCount, _ := s.db.GetSubscriptionCount(r.Context(), did) | 49 | subCount, _ := s.db.GetSubscriptionCount(r.Context(), did) |