Skip to content

Commit

Permalink
perf: optimized user level api
Browse files Browse the repository at this point in the history
  • Loading branch information
aswanthabam committed Sep 26, 2024
1 parent 9214481 commit 2cc6207
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions api/dashboard/profile/profile_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ class Meta:
model = Level
fields = ("name", "tasks", "karma")

def _get_completed_tasks(self, user_id):
if getattr(self, "completed_tasks", None):
return self.completed_tasks
self.completed_tasks = list(
KarmaActivityLog.objects.filter(user=user_id, appraiser_approved=True)
.select_related("task__id")
.values_list("task__id", flat=True)
)
return self.completed_tasks

def get_tasks(self, obj):
user_id = self.context.get("user_id")
user_igs = UserIgLink.objects.filter(user__id=user_id).values_list(
Expand All @@ -215,9 +225,7 @@ def get_tasks(self, obj):
if obj.level_order > 4:
tasks = tasks.filter(ig__name__in=user_igs)

completed_tasks = KarmaActivityLog.objects.filter(
user=user_id, appraiser_approved=True
).values_list("task__id", flat=True)
completed_tasks = self._get_completed_tasks(user_id)
return [
{
"task_name": task.title,
Expand Down

0 comments on commit 2cc6207

Please sign in to comment.