Thanks a lot! That solved my issue.

On Wednesday, June 22, 2016 at 7:48:18 PM UTC+2, Anthony wrote:
>
> First, note that without specifying an orderby, the order of the records 
> is not guaranteed to follow any particular rule, so you can't be sure which 
> record .last() will return.
>
> Second, your current query is returning *all *records from the database, 
> which involves parsing each record into a Row object. Depending on the data 
> in each record and the number of records, this can get slow. However, you 
> only want a single record (it appears you want the one with the most recent 
> created_on date), so you should instead use orderby and limitby:
>
> curr_record = db(db.pushes).select(orderby=~db.pushes.created_on, limitby
> =(0, 1)).first()
> if current_record.created_on.date() < datetime.datetime.now().date():
>     etc.
>
> To speed things up further, you can define an index on the created_on 
> field.
> Anthony
>
> On Wednesday, June 22, 2016 at 1:23:54 PM UTC-4, Grzegorz Dzień wrote:
>>
>> I have an app with following code:
>>
>>     curr_val = db(db.pushes).select().last().kolik
>>     if db(db.pushes.created_on).select().last().created_on.date() < 
>> datetime.datetime.now().date():
>>         db.pushes.insert(kolik=1)
>>     else:
>>         db.pushes.insert(kolik=curr_val+1)
>>
>> When DB gets to 6428 (last time I've checked) this took 9 seconds on 
>> mysql, after I deleted all records it ends up within 1 second. As the DB 
>> grows this code gets slower and slower.
>> Can someone point me as to what I am doing wrong?
>>
>

-- 
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.

Reply via email to