Yes, a brand new problem today -- Best way to Delay a Query

I want to try slowing down a lookup query that runs after an insert form has posted a record to the database.

I’m suspecting that maybe my localhost M1 Mac runs the lookup just a smidge too fast to pick up the Conditional Where value that was just posted.

I have the lookup running after the insert query in the same API – and maybe I have to delay it a second. The forum is filled with questions on delaying scheduling but some answers say use the scheduler ON the page to delay the lookup table query — and others say best place is to delay it in the API I’m using – one stop shopping… running synchronously.

But I’m sure the last steps are not correct. I want to delay running the query for 1 second.

You know you can use the Wait step, right?

And then come back with your conclusion, because I’m very much interested to hear if this is really a case of a race condition

Yes, the famous WAIT condition !

But how do I access this in Wappler ?

That’s pretty funny actually, looks like PHP is missing that famous Wait (yet it’s something so simple)

Well, you have to resort to a custom extension:

1 Like

All we have is ```
sleep(1);


I have this now.
I was looking at @sid 's project just last week...

I load my api query using a page flow with the wait option in php. Works great!

Isn’t this a server action?
Don’t server actions run sequentially? So, the "Condition {{$_SESSION.story_ID}} shouldn’t run until your database insert is done.

That’s what I was thinking, too.

But now I discover that the slippery little devil of a unique number generator is playing by its own rules.
i think I’m “freezing” it in a given split second of time but … Time waits for no plodding developer.

The unique number I think I’m capturing when I see it in the form input before inserting the form simply updates itself while the form is flying its little packets to the mysql server.

Which is why I can never retrieve the last record by the number I “captured” to use as the query table WHERE $_givenkey = '1650991819"

The record has already been saved with a new sequential unique number.

Programmically there is a way around this but in the meantime I may have to go back to old tried and true last record’s key id fetch.

THANKS to all who have been helping through the stalwart hours!

I have most security issues solved except for why I have a page that refuses to allow any more server connections via the Wappler UI.

There is some jquery related code in Wappler that is putting its little vars down and stamping on my tries.

Please show me that “little wait action” written into your flow, please! :face_with_raised_eyebrow:

This waits one second before it runs three queries. I do this because these queries are filtered by variable/form values. So I wait a second for those values to be populated. I probably don’t need a full second but for my use case it works like a charm.

PHP/MySQL

The steps in your server actions are running sequentially, no wait is needed to get the inserted record Identity immediately after the insert step. The steps after the insert will only be executed after the insert is done, which means the id is already available.

Also I see no logical reason to set session then a condition then a query inside a condition.
You just need to place the query step after the insert and directly use the insert identity in your query.

1 Like

I agree with Teodor - something else is wrong if your condition is not grabbing the ID.

What EXACTLY is the problem?

Is it that your Databse query (query_check_saved_story) isn’t pulling anything up, or what?

Maybe you could turn on the outputs for a minute and then look: what do your Dev tools in the browser say is happening. Show us.