简体   繁体   English

用表格改善django性能

[英]improving django perfomace with forms

I have a big database from which a get a list of dictionaries (dictfetchall) that represents some table. 我有一个很大的数据库,从中可以获得代表某些表的词典列表(dictfetchall)。 Then i should make a couple of forms depending on the table i get from db. 然后,我应该根据从db获得的表来制作几种形式。 The table is pretty big - it's about 25k rows and therefore my forms are being built very slowly - about 12 seconds on the whole page, which is unacceptable to me. 该表非常大-大约有25,000行,因此我的表单的构建速度非常慢-整个页面大约需要12秒,这对我来说是不可接受的。 Are there any tricks to improve perfomance? 有什么技巧可以提高性能吗? In General, my code looks like that: 通常,我的代码如下所示:

    all_filters_table = get_all_subord_struct() 
    for row in all_filters_table:
        filters[row[struct_type_id] - 1].append(row['id_struct'], row['struct_name'])
    SomeForm.OPTIONS = filters[i][:1000]
    context['form'] = SomeForm()

update I'm oly working with a stored procedure that gives me about 25k rows and it will be difficult for me to change it. 更新我正在使用一个存储过程,该存储过程给了我约25k行,这对我来说很难更改。 Are there any quick variants to deal with big data that i have? 是否有任何快速变体来处理我拥有的大数据?

Not sure from the code, but it looks like you are fetching all the lines from the DB, then doing filters on the result list. 从代码中不确定,但是看起来您正在从数据库中获取所有行,然后对结果列表进行过滤。

You really need to filter the query request, to only get what you need. 您确实需要过滤查询请求,以仅获取所需的内容。 If you need the last 1000 record for example, you could use something like: 例如,如果您需要最后的1000条记录,则可以使用以下方法:

Data.objects.filter(<some filter>)[:1000]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM