Forum Discussion

JohnBarulich1's avatar
JohnBarulich1
Qrew Cadet
6 years ago

Async concept question with API_DeleteRecord

I have a concept question pertaining to API_DeleteRecord, although could be said for any API call.

Let's say I have a really basic script

for (var i = 0; i < 5; i++){       $.get(url,           act: "API_DeleteRecord",           rid: i       );
}

Would it even be necessary to use async/await for this to execute successfully? Does the server allow several ajax requests at once?

3 Replies

  • Tip of the hat! This is the best question asked all year.

    First, you have to realize that most of the applications of using JavaScript with QuickBase are workarounds and they may well embrace tricks, shortcuts, assumptions or goals that you would not use if you were developing a solution from scratch where you could control all technical aspects of the solution.

    So the simplest solution to using your code as you wrote it would be to just make all jQuery AJAX calls synchronous by adding this line of code:
    $.ajaxSetup({async: false});
    And maybe add a spinner to indicate there are AJAX calls in flight:
    $.ajaxSetup({async: false}); 
    $("<img>", {
      src: "https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/0.16.1/images/loader-large.gif",
      id: "QBU_Spinner"
    }).css({
      position: "fixed",
      top: "50%",
      left: "50%",
      transform: "translate(-50%, -50%)"
    }).appendTo("body");
    for (var i = 0; i < 5; i++) {
      $.get(url,
        act: "API_DeleteRecord",
        rid: i
      );
    }
    $("#QBU_Spinner").hide();

    My professional colleagues would be aghast that I just suggested that you could use synchronous AJAX calls because asynchronous calls are all but the norm for most greenfield development.

    Use it if you want, but there is good reason to master asynchronous programming as it will greatly expand your understanding of the process and propel you to even greater capabilities of what can be achieved using script with QuickBase.
  • I am refactoring my code to accomodate async. I was using async/await to handle each API_DeleteRecord call, but I'm still not completely clear. You're saying turning async off will make this code snippet work, but does this imply quickbase doesn't handle several ajax requests made at *basically* the same time/ does quickbase handle all the requests as a queue? I know that ajax calls are event based, does one event get completely interrupted by another?

    Obviously my goal is to write optimized code because our list gets quite large and there are specifications for what gets deleted, I would preferably like to delete these records with async
    • _anomDiebolt_'s avatar
      _anomDiebolt_
      Qrew Elite
      Browsers will limit the number of simultaneous requests to the same domain (QuickBase uses at least two domains: quickbase.com and assets-cflare.quickbasecdn.net) to a number historically between four to six:

      Max Parallel HTTP Connections
      https://stackoverflow.com/questions/985431/max-parallel-http-connections-in-a-browser#answer-985704

      If you make too many requests simultaneously your browser could run out of sockets and hang. Where that limit is reached probably depends on a number of technical factors but you are probably safe up to say 100  simultaneous requests.

      Servers tend to rate limit the number of requests they accept and don't often publicize the rate limit or other details. The issue is pretty much treated as a security issue (Denail of Service). Other than the limits QuickBase publishes for {webhooks, actions, automations} I am not sure what QuickBase uses but I have never had a problem.

      If you are moving towards using async/await (which is a good idea) you will not have any problem. I answered the questions assuming you had more limited knowledge of async/await. You are on the right track and will have no problems.