kalkun-sms / Kalkun

Open Source Web based SMS Manager
https://kalkun.sourceforge.io/
GNU General Public License v2.0
209 stars 129 forks source link

remove async option on ajax calls #376

Closed tenzap closed 2 years ago

tenzap commented 2 years ago

Any idea why these were here? To avoid multiple DB calls at the same time?

kingster commented 2 years ago

Async false means that those would be blocking sync calls. And UI won't allow any other activity. If these are moved to async, then the code execution should be moved to the oncomplete handler.

tenzap commented 2 years ago

Async false means that those would be blocking sync calls. And UI won't allow any other activity. If these are moved to async, then the code execution should be moved to the oncomplete handler.

Can you elaborate please? I don't understand.

kingster commented 2 years ago

https://stackoverflow.com/questions/1478295/what-does-async-false-do-in-jquery-ajax

Essentially it means that the ajax call is a sync call and the execution is blocked until the response comes. So this is more of sequence call (this is very bad).

var notif = ....
$.post(delete_url + source, {
    type: 'conversation',
    number: $(this).val(),
    current_folder: current_folder
    ...
}, function(data) {
    if (!data) {
        $(message_row).slideUp("slow");
        $(message_row).remove();
    } else {
        notif = data;
    }
});

//now you can use the updated notif here. 
show_alert(notif); //example usage

The way to solve this would be


$.post(....,  function(data) {
    //use the data now and continue execution here.
    show_alert(data);
}).
tenzap commented 2 years ago

Thanks, but I still don't understand this and the oncomplete handler:

This change needs to be updated so that the following statements are moved inside the oncomplete handler

BTW, here we are in a loop in which POST calls are made. Does that change something to your answer?

tenzap commented 2 years ago

@kingster , I close this. Maybe you want to give a try.