简体   繁体   中英

improving django perfomace with forms

I have a big database from which a get a list of dictionaries (dictfetchall) that represents some table. Then i should make a couple of forms depending on the table i get from 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. 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. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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