Skip to content
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

Fix some bugs #54

Merged
merged 3 commits into from
May 30, 2024
Merged
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
20 changes: 15 additions & 5 deletions profiles/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ def fetch_user(user_id=None, username=None, gamemode=Gamemode.STANDARD):
user_id=user_id, gamemode=gamemode
)
else:
return UserStats.objects.select_related("user").get(
user__username__iexact=username, gamemode=gamemode
# usernames should really be unique, but we don't have an up to date view of the users so there may be clashes
return (
UserStats.objects.select_related("user")
.filter(user__username__iexact=username, gamemode=gamemode)
.first()
)
except UserStats.DoesNotExist:
return None
Expand Down Expand Up @@ -104,6 +107,10 @@ def refresh_user_from_api(
# Doesnt exist
return None

# try to fetch user stats by id in case of namechange
if user_id is None and user_stats is None:
user_stats = fetch_user(user_id=user_data["user_id"], gamemode=gamemode)

if user_stats is not None:
osu_user = user_stats.user
else:
Expand Down Expand Up @@ -259,9 +266,12 @@ def fetch_scores(user_id, beatmap_ids, gamemode):
Fetch and add scores for a user on beatmaps in a gamemode
"""
# Fetch UserStats from database
user_stats = UserStats.objects.select_for_update().get(
user_id=user_id, gamemode=gamemode
)
try:
user_stats = UserStats.objects.select_for_update().get(
user_id=user_id, gamemode=gamemode
)
except UserStats.DoesNotExist:
return []

full_score_data_list = []
for beatmap_id in beatmap_ids:
Expand Down