What I’m trying to do:
query 1 row from database.
I’m just starting using Anvil and noticed that it takes 13 seconds to get just onw row from the database. Is this normal? My user cant wait too long. It need to be between 2-4 seconds max.
thank you
What I’ve tried and what’s not working:
Fetch a row from server database takes 13 seconds.
Code Sample:
<CLIENT CODE>
def form_show(self, **event_args):
"""This method is called when the form is shown on the page"""
# question = app_tables.questions.search()[0]
question = anvil.server.call('get_question')
<SERVER CODE>
@anvil.server.callable
def get_question():
question = app_tables.questions.search()[0]
return question
Clone link:
share a copy of your app
Welcome to the forum.
OK - I click “start”, I get a page with an empty drop down. I click start session, and after a few seconds it complains there are no secrets.
Can’t test any further.
Please explain the sequence of events to reproduce what you’re seeing.
Replace your search() with a get(), or narrow down the search.
Based on what I’ve seen on the forum, search() will load up to 100 rows at a time.
Do you have a bunch of top level imports in your server modules? That could be an issue too.
Use accelerated tables and limit the columns you get using fetch_only()
1 Like
As a general rule, with all program-optimization problems, it’s important to measure where the time is actually being spent. That is, to break down the actions into their component steps, and measure the time spent in each step. (Python offers well-documented standard-library tools for that, I won’t go into them here.)
Otherwise, it’s all just guessing. And human intuition is easily caught off-guard in cases like these, where so much of the infrastructure is hidden.
Guys I’m extremely grateful for all the quick answers.
Sorry for the delay in my answer
I create a new toy project to test this.
This is my first project using Anvil, so I’m getting used to it.
In this toy project it took 9 seconds to show the content on the main page.
The table has only 2 columns and only 1 row.
I think I can see the time using devtools console:
RPC Request (9688 ms, 9028 ms lost)
1 Like
In your simple test - put a button on the page and move the db lookup to the click event for the button.
At the moment you cannot separate the boot up time from the server call when the server call is in the form show event.
For me, when I do this, the return is almost instant, certainly less than a second.
3 Likes
It worked better with this change. thank you. now I understand better the lifecycle.
thanks
2 Likes