First, if you are using cache=..., you do not also need to set cacheable=True. Using the former, the DAL automatically handles caching for you. Setting cacheable=True is only for cases where you want to manually cache the Rows object, so you wouldn't be using cache=... in that case.
Second, the .find() method is a method of the Rows object and has nothing to do with caching. It loops through the records in the Rows object and extracts just the Rows that satisfy the search criteria. In this case, your filter function includes row.contato.site, which is a recursive select, so it is doing an additional db select for every Row in reports. Furthermore, you are not caching the testdrives object, so this happens on every request, even if the reports object has been cached. Instead of using the .find() method to filter the reports objects, it would probably be much more efficient to simply do an additional database query to get the testdrives records, using either a join or a nested select. Anthony On Wednesday, December 4, 2013 10:13:10 AM UTC-5, Tito Garrido wrote: > > Hi Folks, > > I have report function that is caching my query, example: > def report(): > sites=db(db.site.ativo==True).select(db.site.id > ,db.site.nome,cache=(cache.ram,6000),cacheable=True) > lojas=db(db.estoque.ativo==True).select(db.estoque.id > ,db.estoque.nome,cache=(cache.ram,6000),cacheable=True) > reports=db(db.report.id > >0).select(groupby=db.report.carro,cache=(cache.ram,6000),cacheable=True) > if request.vars.filtro_site: # WHEN I USE THIS VARIABLE IT GETS SLOW > site=int(request.vars.filtro_site) > testdrives=reports.find(lambda row: site in row.contato.site if > row.contato.site else None) > if request.vars.filtro_loja: # WHEN I USE THIS VARIABLE IT GETS SLOW > loja=int(request.vars.filtro_loja) > testdrives=reports.find(lambda row: loja in row.contato.loja if > row.contato.loja else None) > return > dict(section='relatorio',testdrives=testdrives,lojas=lojas,sites=sites) > > So, when I use "request.vars" and the find function it gets pretty slow, > is it using the cache to execute the find function? Most of the time I am > getting timeout from the webserver. > > Regards, > > Tito > > -- > > Linux User #387870 > .........____ > .... _/_õ|__| > ..º[ .-.___.-._| . . . . > .__( o)__( o).:_______ > -- 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/groups/opt_out.

