Yes! Thanks Anthony, indeed by simply putting
requires=[IS_IN_DB(db, 't_codespostaux.id')])
in the Field definition the problem is solved.
Thus, the indexing of the field is not a necessary condition, however I
will do it also to be sure to have all the performance gains possible.
Cheers,
Jota Pin
Le lundi 17 décembre 2018 13:18:12 UTC+1, Jota Pin a écrit :
>
> Thanks for answering,
>
> - The process crashes indeed when addresses_manage is loaded (in fact the
> browser itself freezes waiting a bit, then after +-30 sec the web2py
> process crashes).
>
> - About "f_representationfield", db.t_codespostaux is a table with four
> columns: f_postcode|f_city|f_country|f_representationfield, where
> f_representationfield contains (concatenated) postcode+city+country. Reason
> for that column: the table was imported with the 3 first columns, then
> since there might be identical postcodes for two countries, people should
> directly see and select postcode+city+country when encoding an addresses,
> and I thought that avoiding having the concatenation made by web2py could
> improve the performance.
>
> - Indeed I did not indexed that field, good point it cannot hurt, I will
> try it and come back here with the result, but I had not tried that before
> since performing the SQL directly on the sqlite db was rather quick.
>
> - Your hypothesis that the problem might come from the widget seems likely
> to be true to me, I will try it now and report here the result.
>
> All the best,
> Jota Pin
>
>
>
>
> Le samedi 15 décembre 2018 02:19:48 UTC+1, Anthony a écrit :
>>
>> What is db.t_codespostaux.f_representationfield (it's not in your model),
>> and most importantly, have you created a database index on that field (will
>> help with the autocomplete search)?
>>
>> Exactly at what point does the process crash -- as soon as you load the
>> addresses_manage page? If so, I suspect the problem might be the grid
>> search widget, which by default will attempt to generate all the options
>> for reference fields. To avoid that, I think it will work to manually
>> create the reference field validator and put it in a list:
>>
>> Field('f_codepostal', 'reference t_codespostaux',
>> requires=[IS_IN_DB(db, 't_codespostaux.id')])
>>
>> That will also suppress the default select widget in forms, even if you
>> don't explicitly specify the autocomplete widget as you have.
>>
>> Anthony
>>
>> On Friday, December 14, 2018 at 6:58:42 PM UTC-5, Jota Pin wrote:
>>>
>>> Dear all,
>>>
>>>
>>> [I posted my first message some days ago and did not saw it appearing on
>>> the list, so I re-post, sorry]
>>>
>>>
>>> I am developing a small-scale app, basically for +-15 users with tables
>>> around 1000-10000 lines, except for one: post-codes (500000). The app works
>>> fine with up to ~5000 postcodes, but with the real table, it simply crashes
>>> the web2py process. Being small-scale, I suppose that using the "defaults"
>>> is enough (the embedded rocket server, ubuntu 16.04, sqlite). Is there a
>>> simple solution by modifying the model/controller, or is this about
>>> switching to nginx?
>>>
>>>
>>> A) The model: (for the two concerned tables, simplified to not flooding
>>> you with details, "codespostaux" are the post-codes):
>>>
>>> db.define_table('t_adresses',
>>> Field('f_codepostal', type='reference t_codespostaux', notnull=True,
>>> label=T('Codepostal')),
>>> migrate=settings.migrate)
>>> db.t_adresses.f_codepostal.widget =
>>> SQLFORM.widgets.autocomplete(request,
>>> db.t_codespostaux.f_representationfield,
>>> id_field=db.t_codespostaux.id,limitby=(0,10),
>>> min_length=2)
>>>
>>> db.define_table('t_adresses_archive',db.t_adresses,Field('current_record','reference
>>>
>>> t_adresses',readable=False,writable=False))
>>>
>>> db.define_table('t_codespostaux',
>>> Field('f_codepostal', type='string',
>>> label=T('Codepostal'),
>>> format='%(f_codepostal)s',
>>> migrate=settings.migrate)
>>>
>>> db.define_table('t_codespostaux_archive',db.t_codespostaux,Field('current_record','reference
>>>
>>> t_codespostaux',readable=False,writable=False))
>>>
>>> B) The Controller:
>>> def adresses_manage():
>>> form =
>>> SQLFORM.smartgrid(db.t_adresses,onupdate=auth.archive,csv=False)
>>> return locals()
>>>
>>>
>>>
>>> Best regards,
>>>
>>> Jota
>>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.