Skip to content

Commit 8907536

Browse files
committed
fix: resolved duplicate recommendation generation issue
1 parent 7178af5 commit 8907536

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

app/controllers/pages_controller.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,11 @@ def initialize_guest_data
3636
def load_recommendations
3737
# Check if recommendations exist and are fresh
3838
if Recommendation.fresh_for_user?(current_user)
39-
# Load cached recommendations
40-
@recommended_animes = current_user.recommended_animes
41-
.joins(:recommendations)
42-
.where(recommendations: { user_id: current_user.id })
43-
.merge(Recommendation.top(12)) # Show top 12
44-
.to_a
39+
# Load top 12 recommendations with anime preloaded
40+
recommendations = current_user.recommendations
41+
.includes(:anime)
42+
.top(12)
43+
@recommended_animes = recommendations.map(&:anime)
4544
else
4645
# Recommendations stale or don't exist - show cold start
4746
@recommended_animes = load_cold_start_recommendations

app/services/recommendation_engine.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ def fetch_candidate_anime
4848
collab_candidates = fetch_collaborative_candidates
4949
popular_candidates = fetch_popular_candidates
5050

51-
# combine and deduplicate
51+
# combine and deduplicate by anime ID
5252
(genre_candidates + collab_candidates + popular_candidates)
53-
.uniq
53+
.uniq(&:id)
5454
# filter out anime alr in the user's anime list
5555
.reject { |anime| @user_anime_ids.include?(anime.id) }
5656
# grab first CANDIDATE_LIMIT items

0 commit comments

Comments
 (0)