Skip to content

Popularity and recommendations fixes #2813

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions listenbrainz/db/popularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_inserts(self, message):
values = [(r[self.entity_mbid], r["total_listen_count"], r["total_user_count"]) for r in message["data"]]
return query, None, values

def get_indexes(self):
def get_indices(self):
if self.mlhd:
prefix = "mlhd_popularity"
else:
Expand All @@ -58,10 +58,10 @@ class PopularityTopDataset(DatabaseDataset):
def __init__(self, entity, mlhd):
if mlhd:
name = "mlhd_popularity_top_" + entity
table_name = "top_" + entity
table_name = "mlhd_top_" + entity
else:
name = "popularity_top_" + entity
table_name = "mlhd_top_" + entity
table_name = "top_" + entity
super().__init__(name, table_name, "popularity")
self.entity = entity
self.entity_mbid = f"{entity}_mbid"
Expand All @@ -82,7 +82,7 @@ def get_inserts(self, message):
values = [(r["artist_mbid"], r[self.entity_mbid], r["total_listen_count"], r["total_user_count"]) for r in message["data"]]
return query, None, values

def get_indexes(self):
def get_indices(self):
if self.mlhd:
prefix = "mlhd_popularity_top"
else:
Expand Down
7 changes: 5 additions & 2 deletions listenbrainz/spark/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from listenbrainz.troi.daily_jams import run_post_recommendation_troi_bot
from listenbrainz.troi.weekly_playlists import process_weekly_playlists, process_weekly_playlists_end
from listenbrainz.troi.year_in_music import process_yim_playlists, process_yim_playlists_end
from listenbrainz.webserver import db_conn

TIME_TO_CONSIDER_STATS_AS_OLD = 20 # minutes
TIME_TO_CONSIDER_RECOMMENDATIONS_AS_OLD = 7 # days
Expand Down Expand Up @@ -147,7 +148,7 @@ def handle_missing_musicbrainz_data(data):
""" Insert user missing musicbrainz data i.e data submitted to ListenBrainz but not MusicBrainz.
"""
user_id = data['user_id']
user = db_user.get(user_id)
user = db_user.get(db_conn, user_id)

if not user:
return
Expand All @@ -159,6 +160,7 @@ def handle_missing_musicbrainz_data(data):

try:
db_missing_musicbrainz_data.insert_user_missing_musicbrainz_data(
db_conn,
user['id'],
UserMissingMusicBrainzDataJson(missing_musicbrainz_data=missing_musicbrainz_data),
source
Expand Down Expand Up @@ -213,7 +215,7 @@ def handle_recommendations(data):
""" Take recommended recordings for a user and save it in the db.
"""
user_id = data['user_id']
user = db_user.get(user_id)
user = db_user.get(db_conn, user_id)
if not user:
current_app.logger.info(f"Generated recommendations for a user that doesn't exist in the Postgres database: {user_id}")
return
Expand All @@ -223,6 +225,7 @@ def handle_recommendations(data):

try:
db_recommendations_cf_recording.insert_user_recommendation(
db_conn,
user_id,
UserRecommendationsJson(**recommendations)
)
Expand Down
Loading