0

I want to know some information about this particular query:

  case_insensitive_username = User.objects.filter(email__iexact=username).first()
  1. is there a way to know how many queries it executes on the background?
  2. How can I test the performance of this query? I mean, execution time, memory.

Thanks in advance.

Nick Cuevas
  • 1,474
  • 15
  • 10
  • Possible duplicate of https://stackoverflow.com/a/3748307/12581324. And one more thing, the query is never executed if it is not evaluated, so the code above can have the query attr, but it is not executed to db yet. It will be executed if you then put it with something like print(). – Paaksing May 14 '20 at 14:29
  • https://docs.djangoproject.com/en/3.0/topics/db/optimization/ – iklinac May 14 '20 at 14:47

1 Answers1

0
  • For the first point.
case_insensitive_username = User.objects.filter(email__iexact=username).first()
print(case_insensitive_username.query)
  • For the second point.
import datetime
start_time = datetime.datetime.now()
#execute the query
end_time = datetime.datetime.now()

diff_time = end_time - start_time
print(diff_time.seconds) 
chatrapathi
  • 107
  • 8