If you don't need this page to be update more then once a day or once a
hour what you can do is this :

You make sub-function that you gonna cache

def __sub_func_NAME():
    complex query
    return var

def display_func():
    var = cache.ram('var',
                      lambda: __sub_func_samples_list(),
                      time_expire=3600)
    from = RESULT OF YOUR FORM GENERATION
    return dict(form=form)

That way you can cache the long query, so it will be slow only once in a
wild...

Sorry, I don't have time to analyse in details if what you are doing could
be optimize. I think that if you just want to make it faster you can follow
the path a suggest as long as your code give you the result you expect.

Richard


On Wed, May 16, 2012 at 4:06 PM, Fabiano Faver <far...@gmail.com> wrote:

> For this purpose they are not...I may include a field on printers table
> that inform the date I searching for.
>
> If what I want to do in this page is still not clear I can try to explain
> more.
> basically its a grid that each TD have a bg-color dependant on it last date
>
>
>
> EmpresaTb = db.define_table("empresa",
>             Field('nome_fantasia','string'**),
>             format='%(nome_fantasia)s'
>             #migrate=False
>             )
>
> FilialTb = db.define_table("filial_**empresa",
>             Field('descricao_filial','**string'),
>             Field('endereco','string'),
>             Field('telefone','string'),
>             Field('Contato',default=''),
>             Field('email','string'),
>             Field('id_empresa','reference empresa'),
>             format='%(descricao_filial)s',
>             migrate=False
>             )
>
> FabricanteTb = db.define_table("fabricante",
>             Field('nome_fabricante','**string'),
>             format='%(nome_fabricante)s'
>             #migrate=False
>             )
>
> ModeloTb = db.define_table("modelo",
>             Field('nome_modelo','string'),
>             Field('id_fabricante','**reference fabricante'),
>             format='%(nome_modelo)s'
>             #migrate=False
>             )
>
>
> ImpressoraTb = db.define_table("impressora",
>             Field('serial','string'),
>             Field('macaddress','string'),
>             Field('id_modelo','reference modelo'),
>             Field('id_filial_empresa','**reference filial_empresa'),
>             format=lambda r: r.serial or r.macaddress
>             #migrate=False
>             )
>
>
> ContadoresTb = db.define_table("contadores",
>             Field('printpb','integer'),
>             Field('copypb','integer'),
>             Field('printcolor','integer'),
>             Field('copycolor','integer'),
>             Field('singlecolor','integer')**,
>             Field('twocolor','integer'),
>             Field('copysinglecolor','**integer'),
>             Field('copytwocolor','integer'**),
>             Field('scanner','integer'),
>             Field('fax','integer'),
>             Field('total','integer'),
>             Field('data','date'),
>             Field('hora','time'),
>             Field('id_impressora','**reference impressora')
>             #Field('fkempresa','reference empresa'),
>             #migrate=False
>             )
>
> Em quarta-feira, 16 de maio de 2012 16h50min35s UTC-3, Richard escreveu:
>
>> Would you show your models...
>>
>> You make complexe queries, maybe your models are not pretty well design
>> for the purpose.
>>
>> Richard
>>
>> On Wed, May 16, 2012 at 3:22 PM, Fabiano Faver <far...@gmail.com> wrote:
>>
>>> But because of the group by clause it are too slow and I curious to know
>>> if I can query each company separately  do what i must with the data and
>>> show the result on page as soon as they are ready
>>>
>>>
>>> 2012/5/16 Fabiano Faver <far...@gmail.com>
>>>
>>>> I'm trying to display a table with the name of some companies with the
>>>> background color of each TD or DIV  dependent of the last day the printers
>>>> company were checked
>>>>
>>>> this it what I have now:
>>>>
>>>> def exibicao_empresas():
>>>>     #get companies
>>>>     empr = db(auth.accessible_query('**read**', db.empresa,
>>>> auth.user_id)).select()
>>>>     tabela_empresa = TABLE( _class='grid_color')
>>>>     tr = TR()
>>>>     columns = 6
>>>>     count_cl = 0
>>>>     #for each company get all their printers and the last date it were
>>>> checked
>>>>     for td in empr:
>>>>         lista_1 = []
>>>>         count_menos = count_mais = 0
>>>>         #getting printers
>>>>         impress = db((db.impressora.id_filial_**em**presa==
>>>> db.filial_empresa.id)**&(**db.filial_empresa.id_**empresa==**td.id<http://td.id/>
>>>> ))._select(db.**impressora.**id <http://db.impressora.id/>)
>>>>
>>>>         quant_impressoras = len(impress)
>>>>         maxdata = db.contadores.data.max()
>>>>         #getting dates
>>>>         dias = 
>>>> db(db.contadores.id_**impressora**.belongs(impress)).**select(
>>>> maxdata,db.contadores.id_**impre**ssora, groupby=db.contadores.id_**
>>>> impre**ssora)
>>>>
>>>>         # checking to show the indicative background-color
>>>>         for dia in dias:
>>>>             if (((dia_hoje-dia[maxdata]).days >= 1) and
>>>> ((dia_hoje-dia[maxdata]).days < 5)): count_menos = count_menos+1
>>>>             if ((dia_hoje-dia[maxdata]).days > 5): count_mais =
>>>> count_mais+1
>>>>         bg_td = 'background-color: #99FFCC'
>>>>         if count_menos: bg_td = 'background-color: #EAEA9F'
>>>>         if count_mais == len(dias): bg_td = 'background-color: #FF9999'
>>>>
>>>>         tr.append(TD(td.nome_fantasia, _style = bg_td))
>>>>         count_cl = count_cl + 1
>>>>         if count_cl==columns:
>>>>             tabela_empresa.append(tr)
>>>>             tr=TR()
>>>>     else:
>>>>         if len(tr): tabela_empresa.append(tr)
>>>>
>>>>     return dict(tabela_empresa =tabela_empresa )
>>>>
>>>>>
>>>>>
>>>
>>

Reply via email to