gpt4 book ai didi

jquery - Django查询慢,优化

转载 作者:行者123 更新时间:2023-11-29 22:24:25 28 4
gpt4 key购买 nike

def search(request):
found_entries = None
query = Q(feedstock__fs_name__icontains=corn
found_entries = Sample.objects.filter(query).exclude(status_id=3).order_by('id')
queries = request.GET.copy()
sample = paging(request, found_entries)
return render_to_response('search_results.html', {'sample': sample, 'queries': queries},
context_instance=RequestContext(request))

这会返回大约 9000 个条目,查询需要很长时间。而对于分页来说,如果你点击下一页,那么花费的时间就和重新查询数据一样长。关于如何加快查询或优化查询有什么想法吗?

最佳答案

您是否尝试过使用 Django 分页来设置结果大小?如果没有,我会说看看 https://docs.djangoproject.com/en/1.8/topics/pagination/

以下是与您相关的文档的长处和短处:

从 django.core.paginator 导入 Paginator、EmptyPage、PageNotAnInteger

def listing(request):
contact_list = Contacts.objects.all()
paginator = Paginator(contact_list, 25) # Show 25 contacts per page

page = request.GET.get('page')
try:
contacts = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
contacts = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
contacts = paginator.page(paginator.num_pages)

return render_to_response('list.html', {"contacts": contacts})

关于jquery - Django查询慢,优化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30405215/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com