AshoniA
AshoniA
RRailway
Created by AshoniA on 4/2/2024 in #✋|help
Server Response too slow
I have Django, React application live on railway. I'm using Hobby plan. whenever I click through pagination buttons server is taking up to a minute to respond. I can see in the network panel that request has been sent and it takes 10 - 60 second for the response to come in. on the localhost everything is instant. I don't know what's causing it. Full project code : https://github.com/AlexShonia/e-commerce pagination code on django:
@api_view(["GET"])
def getProducts(request):
query = request.query_params.get("keyword")
if query == "null" or query == None:
query = ""

products = Product.objects.filter(name__icontains=query)

page = request.query_params.get("page")
paginator = Paginator(products, 4)

try:
products = paginator.page(page)
except PageNotAnInteger:
products = paginator.page(1)
except EmptyPage:
products = paginator.page(paginator.num_pages)

serializer = ProductSerializer(products, many=True)
return Response(
{"products": serializer.data, "page": page, "pages": paginator.num_pages}
)
@api_view(["GET"])
def getProducts(request):
query = request.query_params.get("keyword")
if query == "null" or query == None:
query = ""

products = Product.objects.filter(name__icontains=query)

page = request.query_params.get("page")
paginator = Paginator(products, 4)

try:
products = paginator.page(page)
except PageNotAnInteger:
products = paginator.page(1)
except EmptyPage:
products = paginator.page(paginator.num_pages)

serializer = ProductSerializer(products, many=True)
return Response(
{"products": serializer.data, "page": page, "pages": paginator.num_pages}
)
164 replies