Faster way to access data from table?

What I’m trying to do:
I’m trying to get all the data out of a table more quickly so I can build a graph in plotly without the delay.
I currently have a table called ‘co2mlweekly’ that has 2 columns: ‘date’ & ‘average’. There are approximately 2,600 rows in the table.
I want to use all of the data from the table to build the graph. It does not need to be filtered in any way.
Under my current approach, it takes up to 5 seconds to build the graph.
Is there a way to pull all the data from the table at once, in one call? Or some other way of doing this?
Alternatively, is there a way for Anvil to cache the data or the graph?
Thanks.
What I’ve tried and what’s not working:
Currently my code builds two lists with:

 datelist = [r['date'] for r in app_tables.co2mlweekly.search()]
 co2list = [r['average'] for r in app_tables.co2mlweekly.search()]

then uses these lists to build the trace for the graph with

trace_co2 = go.Scatter(x=datelist,
                            y=co2list,
                            mode='lines',
                            )

Clone link:

Welcome to the Forum!

You may be looking for this: Accelerated Tables Beta.

You should also do the search only once, otherwise you’re doing twice the work you need on the database. e.g.:

 results = app_tables.co2mlweekly.search()
 datelist = [r['date'] for r in results ]
 co2list = [r['average'] for r in results ]

You could further optimize that by only iterating over the results once, and pulling both columns out at the same time.

2 Likes