Your code can sometimes take a long time to execute. Depending on who notices, this may or may not be an issue. If some code takes 30 seconds to do its thing “behind the scenes,” the wait may not be an issue. However, if your user is waiting for your application to respond, and it takes 30 seconds, everyone notices. What you should do to fix this problem depends on what you’re trying to do (and who’s doing the waiting). In this short chapter, we’ll briefly discuss some options, then look at one solution to the issue at hand: what happens if something takes too long?
When you write code that has the potential to make your users wait, you need to think carefully about what it is you are trying to do. Let’s consider some points of view.
Maybe it is the case that waiting for a write is different from waiting for a read, especially as it relates to how your webapp works?
Let’s take another look at the SQL queries in
view_the_log to see how you’re using them.
log_request function, we are using an SQL
INSERT to add details of the request to our backend database. When
log_request is called, it waits while the
INSERT is executed by