Forums

Performance issues in Django application

Hello!

I have just migrated my SQLite database to MySQL following the steps detailed in several posts in this forum (so thanks for that!) and everything seemed to work out well without any errors. However, I don't see any performance improvement as one of my main pages still takes a while to load (it's a database with 2K rows) - so my next thoughts are that it could be caused by two things: pythonanywhere free account or DataTables.net. Any ideas?

Thank you in advance!

2k rows is pretty tiny by MySQL's standards, so the problem is probably not the database specifically. What are you doing in the view for the page in question? Are you rendering all two thousand rows, or a subset? If it's a subset, how are you filtering them? Could you post the code you're using, perhaps?

Hello!

Thanks for your reply - I kinda do both: I get the 2K rows from the database but only show a subset in each page (20 rows per page). This is part of the code to do that:

In views.py

 def index(request):
   users = Users.objects.all()
   context = {
     'users': users,
   }
   return render(request, 'webapp/index.html', context)

In the html page:

Javascript code for rendering the table (https://datatables.net/):

$(document).ready(function(){
      var myTable = $('#myTable').DataTable( {
      "lengthMenu": [15, 20],
      "pageLength": 20,
} );

And then I iterate through the users to draw the table:

{% for user in users %}

are you sending all 2k rows to the html page?

I'm afraid I am. I'm new to web development so I'm trying to learn my lessons here -> I need to handle the data retrieving on the backend side rather than the frontend.

That's a really good lesson to learn early. Dumping large amounts of data across the network and then not using it takes time. There's a bit of a trade-off there - sometimes you want to speed subsequent accesses and you're prepared to pay the cost up front, and other times you want the first access to be faster.