From: Hypolite Petovan Date: Wed, 27 May 2020 12:30:26 +0000 (-0400) Subject: Improve performance of asynchronous like/update X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2d217129b9fb2e4379b728b01ec73fc0be8c58ff;p=friendica.git Improve performance of asynchronous like/update - Make the like module return earlier instead of outputting a full empty HTML page - Update the force_update variable earlier to prevent spilling on multiple unrelated nav update calls --- diff --git a/src/Module/Like.php b/src/Module/Like.php index c926012f18..ca38247508 100644 --- a/src/Module/Like.php +++ b/src/Module/Like.php @@ -22,6 +22,7 @@ namespace Friendica\Module; use Friendica\BaseModule; +use Friendica\Core\System; use Friendica\DI; use Friendica\Model\Item; use Friendica\Core\Session; @@ -68,5 +69,7 @@ class Like extends BaseModule DI::baseUrl()->redirect($returnPath . $rand); } + + System::jsonExit(['status' => 'OK']); } } diff --git a/view/js/main.js b/view/js/main.js index 8613153987..af2f8522c8 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -594,15 +594,17 @@ function liveUpdate(src) { in_progress = true; - if ($(document).scrollTop() == 0) { - force_update = true; - } + let force = force_update || $(document).scrollTop() === 0; var orgHeight = $("section").height(); var udargs = ((netargs.length) ? '/' + netargs : ''); - var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&force=' + ((force_update) ? 1 : 0) + '&item=' + update_item; + var update_url = 'update_' + src + udargs + '&p=' + profile_uid + '&force=' + (force ? 1 : 0) + '&item=' + update_item; + + if (force_update) { + force_update = false; + } if (getUrlParameter('page')) { update_url += '&page=' + getUrlParameter('page'); @@ -614,9 +616,8 @@ function liveUpdate(src) { update_url += '&max_id=' + getUrlParameter('max_id'); } - $.get(update_url,function(data) { + $.get(update_url, function(data) { in_progress = false; - force_update = false; update_item = 0; $('.wall-item-body', data).imagesLoaded(function() {