Skip to content

Commit

Permalink
Merge pull request #54 from Syriiin/bug-bashing
Browse files Browse the repository at this point in the history
Fix some bugs
  • Loading branch information
Syriiin authored May 30, 2024
2 parents f9386e9 + 80b9cef commit 7ec6626
Showing 1 changed file with 15 additions and 5 deletions.
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

0 comments on commit 7ec6626

Please sign in to comment.