Hello,
I'm making a Django-based chat app, and I'm trying to make a sort of long polling. Do you think it would be a good idea (in terms of efficiency) to use the time.sleep() method when server receives a request? My plan is to do something like this, in order to minimize the number of requests:
for _ in range(5):
messages = Message.objects.new_messages()
if messages.count() > 0:
return JsonResponse({
"messages": messages,
})
else:
time.sleep(5)
return JsonResponse({
"messages": [],
})
I'm worried this could freeze the whole app, especially when several people will be using it.