Resouce Query in Automatic Mode will executed twice on page load

Encountered a similar issue here:
https://community.retool.com/t/every-database-query-is-executed-twice/

Issue:
The query in automatic mode will be executed twice on page load.
One is actually triggered by the 'on load', the other is triggered by input change while the input parameter from the debug shows no difference.

Background:

  • The query is referencing the {{ urlparams.href }} as part of the input
  • The app is configured with custom URL
  • If access the app directly thru the custom URL, it won't have this dup execution issue

Retool Version:
Self-hosted Retool 3.75.0

The redirection of app from the default url to the custom url may accidentally trigger the query. My temp workaround is to add a short cache so the second execution won't waste up the resource, but I hope there can be a more elegant native solution from Retool.

Hello @zelterNN,

Interesting issue. Thank you for linking that other post for greater context.

I believe you are correct, the app has a brief re-direct from the default url to the custom url, which will trigger the query via variable change. With the first run being triggered by the initial on page load.

This is a tricky issue to fix, as I am guessing you want to have the query run when the {{ urlparams.href }} change, but I am not sure it is possible to programmatically tell the app that it should ignore the first time this happens :thinking:

You could have it not run automatically on page load, given that it will run anyway when the page loads and the var changes from a "nullish" value to the custom url value.

If you switch off the run on page load I would imagine that the query will run how you expect it to, on initial load and on var change.

1 Like

if so i need to switch the run mode to Manual and configure the parameter watch, which can be a bit annoying if the query will be updated in the future.

Btw, thanks for confirming this issue :slight_smile:

Ahh yes I totally understand, configuring the param to watch for manual mode is less than idea, especially if the query will need to be updated.

This would be the surefire way to stop the double initial run. It sounded like you had set this up to run the query on input change, which I was guessing could be kept the same :face_with_monocle:

The runtime state of an app on page load is a bit complex so it can be challenging to set things up perfectly :sweat_smile: glad I could help provide some insight on a possible solution.

1 Like