I have around 6 million objects in my database. For these objects, I need to have a structure page, where the users would browse through the aforementioned 6 million objects as paginated content.
My code for the pagination is a total duplicate of what is given in the documentation of Django:
def listing(request):
movie_list = Movie.objects.all()
paginator = Paginator(movie_list , 100) # Show 100 movies per page.
page_number = request.GET.get('page')
page_obj = paginator.get_page(page_number)
return render(request, 'movies.html', {'page_obj': page_obj})
Howevre, most of the resulting 60,000 pages with the movies are too long to open, and give 504 timeout errors, which also results in the content being unreadable for GoogleBot (which is actually the main aim of the structure page).
What can be the workaround to prevent these timeouts and ensure the normal load speed for the large paginated content in Django? The database I am using is PostgreSQL.