Skip to content

Commit

Permalink
Merge pull request #2230 from aswanthabam/perf-register
Browse files Browse the repository at this point in the history
fix: optimized user level api
  • Loading branch information
shaheenhyderk authored Sep 25, 2024
2 parents 7fbfd2f + cb029ff commit 26821c4
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions api/dashboard/profile/profile_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,20 @@ def get_tasks(self, obj):
if obj.level_order > 4:
tasks = tasks.filter(ig__name__in=user_igs)

data = []
for task in tasks:
completed = KarmaActivityLog.objects.filter(
user=user_id, task=task, appraiser_approved=True
).exists()
if task.active or completed:
data.append(
{
"task_name": task.title,
"discord_link": task.discord_link,
"hashtag": task.hashtag,
"completed": completed,
"karma": task.karma,
}
)
return data
completed_tasks = KarmaActivityLog.objects.filter(
user=user_id, appraiser_approved=True
).values_list("task__id")
return [
{
"task_name": task.title,
"discord_link": task.discord_link,
"hashtag": task.hashtag,
"completed": is_completed,
"karma": task.karma,
}
for task in tasks
if (is_completed := task.id in completed_tasks) or task.active
]


class UserRankSerializer(ModelSerializer):
Expand Down

0 comments on commit 26821c4

Please sign in to comment.