Skip to content

Commit

Permalink
perf: Optomise random quote fetch speed
Browse files Browse the repository at this point in the history
  • Loading branch information
idabblewith committed Dec 14, 2023
1 parent bb9a92d commit 634fb78
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions quotes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ def go(self, pk):
raise NotFound

def get(self, req):
count = Quote.objects.count()
quote = self.go(pk=random.randint(0, count))
# count = Quote.objects.count()
# quote = self.go(pk=random.randint(0, count))

# Faster means of getting a random quote
quote = Quote.objects.order_by('?').first()
ser = QuoteDetailSerializer(quote, context={"request": req})
return Response(
ser.data,
Expand Down

0 comments on commit 634fb78

Please sign in to comment.