My view has a search bar, which searches extremely slowly with MYSQL BD - $12 account. The weirdest thing is that it was really fast on SQLite. I'm thinking it could be the connection to the MYSQL DB. There are four tables that I'm trying to pull information from Restaurant, Food, Menu, Quality.
When I run it in the shell, it's actually normal speed. No one line takes super long, not sure why it's so slow on the server. I've tried to comment out individual lines and run on the server and it does not really change the speed.
Here is the code that runs very slowly:
in_radius = [# list short] list_ids = ['# list short] # Restaurants table is small find_objects = Restaurants.objects.filter(Q(zipcode__in=in_radius) | Q(id__in=list_ids)).distinct() # Menu table 1 million observations objects_selected = Food.objects.filter(menu__menuid=pk) table = objects_selected.filter(restaurants__in=find_objects).order_by('price').prefetch_related('restaurants') #Food table is small food_info = Food.objects.filter(foodid=pk) # quality has about 600K objects quality_info = Quality.objects.filter(food__foodid=pk,locality = str(5))[:1]