Form submit takes too long

70 views
Skip to first unread message

Maurice Waka

unread,
Aug 29, 2018, 7:35:56 AM8/29/18
to web2py-users
I noticed that my form submit takes too long, almost 45 seconds sometimes. The more data I add to the database and I need to fetch it, the more longer it takes to submit.
This is my code
           
<div class="bottom_wrapper clearfix">
               
<div class="message_input_wrapper">
                    {{=form.custom.begin}}
                   
<textarea id="message_input" type="text"name="message"  placeholder="Type your message here..."></textarea>
                   
<button>send</button>
                    {{=form.custom.end}}
               
</div>
               
<div class="message_template">
                   
<li class="message">
                       
<div class="message-data-time" ></div>
                       
<div class="text_wrapper">
                           
<div class="text"></div>
                       
</div>
                   
</li>
               
</div>
           
</div>

Controller function

def c_function():
    form
= SQLFORM(db.post).process()
    row
= db(db.post.author== auth.user.id).select(db.post.id, db.post.message, orderby=~db.post.id, limitby=(0,1)).first()
    names
= row.message if row else None
    db
.answers.insert(quest=names, message=report())
    replies
= db(db.answers.author == auth.user.id).select(db.answers.ALL)[-10:-1]
   
return dict(form=form,names=names,replies=replies)

Anthony

unread,
Aug 29, 2018, 11:30:52 AM8/29/18
to web2py-users
    db.answers.insert(quest=names, message=report())

What does report() do? Is that an expensive function?
 
    replies = db(db.answers.author == auth.user.id).select(db.answers.ALL)[-10:-1]

Above you are selecting every record in the db.answers table and converting them to Python objects -- is that a big table? You should instead use limitby to select only the records you want.

Anthony

Maurice Waka

unread,
Aug 29, 2018, 12:36:45 PM8/29/18
to web...@googlegroups.com
Answers is a small table, can have up to 100 rows. I'll introduce the limitby(). There are several functions that an item loops through, almost 100, but with a filter to limit the number of functions, with the final result returned by report() 


--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/OJRaYk57ZPQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leonel Câmara

unread,
Aug 30, 2018, 7:28:15 AM8/30/18
to web2py-users
Apart from the obvious problem Anthony pointed. Are you using sqlite in a highly concurrent environment? 

justice Nanhou

unread,
Sep 2, 2018, 2:03:30 PM9/2/18
to web2py-users
Hallo Maurice,

it is know issue for all application and all framworks.
which database are you using ? 
- my first attempt will be to try to add indexes in the post and answers Table on the field author.
- secondly i will try to change this row
row = db(db.post.author== auth.user.id).select(db.post.id, db.post.message, orderby=~db.post.id, limitby=(0,1)).first()
to this
row = db(db.post.author== auth.user.id).select(db.post.id, db.post.message, orderby=~db.post.id).first()

limitby ist not needed in that case. it is just my opinion.

Lovedie JC

unread,
Sep 2, 2018, 2:12:59 PM9/2/18
to web...@googlegroups.com
Yes. Been away. But I am looking into this. I'll let you know the results.
Regards 

--
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 web2py+un...@googlegroups.com.

Lovedie JC

unread,
Sep 2, 2018, 2:13:51 PM9/2/18
to web...@googlegroups.com
Am using sqlite.storage

On Sun, 2 Sep 2018, 21:03 justice Nanhou <justice...@gmail.com> wrote:

Maurice Waka

unread,
Sep 2, 2018, 3:24:03 PM9/2/18
to web...@googlegroups.com
Hey @Lovdie. Can we have a look at this later? 

You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/OJRaYk57ZPQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.

Anthony

unread,
Sep 2, 2018, 9:52:35 PM9/2/18
to web2py-users
- my first attempt will be to try to add indexes in the post and answers Table on the field author.
- secondly i will try to change this row
row = db(db.post.author== auth.user.id).select(db.post.id, db.post.message, orderby=~db.post.id, limitby=(0,1)).first()
to this
row = db(db.post.author== auth.user.id).select(db.post.id, db.post.message, orderby=~db.post.id).first()

limitby ist not needed in that case. it is just my opinion.

Why would you not use limitby? Without limitby, the database will return every record in the table, and the the DAL will have to parse every record and convert it to a Row object -- and then all of those Row objects will simply be ignored, as only the first will be used in the code.

Anthony

Massimo Di Pierro

unread,
Sep 18, 2018, 12:02:24 AM9/18/18
to web2py-users
I understand the confusion. In SQLAlchemy for example people use .first() for fetch one record. In web2py the feching is by the select. .first() just gives you the fist of the records that were retrieved.

Maurice Waka

unread,
Sep 18, 2018, 2:06:34 AM9/18/18
to web...@googlegroups.com
Noted. I removed some while loops with tremendous results. It now works well.
Regards.

--
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 a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/OJRaYk57ZPQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages