How many DB query's do you have in an action file?

Hi All,

Just wanted to get people’s thoughts on how many DB query’s or steps you might have in a single server connect ‘action file’ before you start adding new files?

Naturally i try to create a logical grouping, and i’m aware that the steps run in order one after the other and if one fails they all fail. So just thought if ask if anyone wanted to share their thoughts on how they structure their action files and steps involved.

For instance, is there a performance difference on loading 2 x server connect queryies in app connect each with 1 x DB connection and 1 X DB query VS loading 1 x server connect file in app connect with 2 x queries in it?

Thoughts?

Cheers,
Phil

Great question Phil!

I just put everything in the same file that logically happens in the same action my app is performing… but that is no more than 3-5 database access steps at a time at the moment.

When a user signs up I have a massive amount of data that gets created and I have that happen in a stored procedure (just don’t tell @JonL!)… it seemed more sensible for all of that to go on directly in the database than all the communication to be going on between the database and the server. However as I have just set up my full test and production environments, I can see where @JonL is coming from in terms of maintenance… so I’m restricting stored procedures to tasks that are well defined and unlikely to change very much.

Best wishes,
Antony.

2 Likes

My worst one to date has about 10 db actions, 3 api actions, 5 image reseze, 5 image saves, 2 image loads, and the worst part i would imagine is that all those steps are duplicated twice in 2 different conditions, and the last condition has 3 nested conditions in that.
Its like 4 pages of scrolling.
Seems to run perfectly though. Normally my server actions only have 3 or 4 steps though, this one was an anomaly.

1 Like

I think the most I’ve had is about 8.

One thing I did realise, though, which can be a problem. If you ‘load’ an action file again (to refresh the page after something has updated) then it reloads all the queries. I wanted to only reload one particular query so needed to separate them into action files with one in each.

Maybe a feature request to be able to use the load feature and then specify what to load from within the action file?

2 Likes

Crikey, I have some SAs with literally dozens of database calls but I like to do things at server level when possible. Still never used a app connect .where()

I would suggest SA with multiple queries will be faster than separate SAs as there is no need to keep remaking the connection, returning data or even any DNS lag calling files repeatedly

2 Likes

I never even thought of using multiple queries in a server action. Interesting concept.

1 Like

Thanks for all your replies everyone, always good to get others perspective.

@brad. The fact you never have more than one query would explain that screenshot of yours I saw the other day. I like your use of Sections to keep everything organised, but noticed the huge among of server connect components in your app :grin:

1 Like

There is no limit in how many you can use. If you need multiple data sets loading the data on page load and don’t need to reload them separately - then you can put all of the queries in the same server action.

1 Like

My main use of multiple queries is processing multi table data for example i may make a database query then as a result of the data returned call further queries to add/remove/ associated date (triggers are often much to simplistic for my needs). I use conditions inside repeats in SAs heavily to manage inserts/updates via queries
Also i often use cron jobs to manage data where multiple, sometimes unrelated processes are contained within a singe SA called on a schedule

1 Like