NPM Resource Changed ? ? Pending

User tests: Successful: Unsuccessful:

avatar PhilETaylor
PhilETaylor
9 May 2021

Summary of Changes

@dgrammatiko 3 years ago in #21421 you continued added a 2000ms delay in checking for Joomla updates when you refactored. Can you remember why waiting that long?

It now "feels" that its slow checking for updates now, when sat along side the other boxes in Joomla 4 admin that are also running an ajax call checking for udpates - its not slow, because its not actually checking until 2000ms after page load, and then returns very fast once the ajax call is finally made.

This PR is me pretending to be a javascript developer so if its wrong I'll happily let you do it, I compared it to the other boxes checking for updates and they dont have a setTimeout

Testing Instructions

Load home dashboard - watch the four green boxes for updates.

Actual result BEFORE applying this Pull Request

Screen.Recording.2021-05-09.at.01.24.21.pm.mp4

Expected result AFTER applying this Pull Request

same as before, just much (2000ms) faster.

Screen.Recording.2021-05-09.at.01.37.08.pm.mp4

Documentation Changes Required

avatar PhilETaylor PhilETaylor - open - 9 May 2021
avatar PhilETaylor PhilETaylor - change - 9 May 2021
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 9 May 2021
Category JavaScript Repository NPM Change
avatar dgrammatiko
dgrammatiko - comment - 9 May 2021

@PhilETaylor I have no clue, that PR was just converting the notation from ES5 to ES6, so I probably respected what was there

May I propose this version of the script, since you're refactoring it here:

/**
 * @copyright  (C) 2018 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

if (Joomla && Joomla.getOptions('js-extensions-update')) {
  const options = Joomla.getOptions('js-joomla-update');

  const update = (type, text) => {
    const link = document.getElementById('plg_quickicon_joomlaupdate');
    const linkSpans = [].slice.call(link.querySelectorAll('span.j-links-link'));
    if (link) {
      link.classList.add(type);
    }

    if (linkSpans.length) {
      linkSpans.forEach((span) => {
        span.innerHTML = text;
      });
    }
  };

  fetch(options.ajaxUrl, { method: 'GET' })
    .then((response) => {
      response.json().then((updateInfoList) => {
        if (Array.isArray(updateInfoList)) {
          if (updateInfoList.length === 0) {
            // No updates
            update('success', Joomla.Text._('PLG_QUICKICON_JOOMLAUPDATE_UPTODATE'));
          } else {
            const updateInfo = updateInfoList.shift();

            if (updateInfo.version !== options.version) {
              update('danger', Joomla.Text._('PLG_QUICKICON_JOOMLAUPDATE_UPDATEFOUND').replace('%s', `<span class="badge text-dark bg-light"> \u200E ${updateInfo.version}</span>`));
            } else {
              update('success', Joomla.Text._('PLG_QUICKICON_JOOMLAUPDATE_UPTODATE'));
            }
          }
        } else {
          // An error occurred
          update('danger', Joomla.Text._('PLG_QUICKICON_JOOMLAUPDATE_ERROR'));
        }
      })
        .catch(() => {
          // An error occurred
          update('danger', Joomla.Text._('PLG_QUICKICON_JOOMLAUPDATE_ERROR'));
        });
    })
    .catch(() => {
      // An error occurred
      update('danger', Joomla.Text._('PLG_QUICKICON_JOOMLAUPDATE_ERROR'));
    });
}
avatar PhilETaylor PhilETaylor - change - 9 May 2021
Labels Added: NPM Resource Changed ?
avatar PhilETaylor
PhilETaylor - comment - 9 May 2021

Done. Thanks.

avatar dgrammatiko dgrammatiko - test_item - 9 May 2021 - Tested successfully
avatar dgrammatiko
dgrammatiko - comment - 9 May 2021

I have tested this item successfully on e54f7ee


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33693.

avatar dgrammatiko
dgrammatiko - comment - 9 May 2021

I have tested this item successfully on e54f7ee


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33693.

avatar rjharishabh rjharishabh - test_item - 9 May 2021 - Tested successfully
avatar rjharishabh
rjharishabh - comment - 9 May 2021

I have tested this item successfully on e54f7ee


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33693.

avatar brianteeman
brianteeman - comment - 9 May 2021

It would be good to find the reason that the delay was placed there in the first place before removing it

avatar hans2103
hans2103 - comment - 9 May 2021

It would be good to find the reason that the delay was placed there in the first place before removing it

da59378#diff-d9892566784491318da9dfec14b617f12198d73377796009002b2931f5842b34

no reason found

avatar PhilETaylor
PhilETaylor - comment - 9 May 2021

no reason found

Correct. Just one guys way of writing code.

avatar richard67 richard67 - change - 9 May 2021
The description was changed
Status Pending Ready to Commit
avatar richard67
richard67 - comment - 9 May 2021

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/33693.

avatar richard67 richard67 - edited - 9 May 2021
avatar dgrammatiko
dgrammatiko - comment - 9 May 2021

It would be good to find the reason that the delay was placed there in the first place before removing it

FWIW the code is asynchronous, which means it will not block anything happening in the page rendering phase so if the fetch of the json happens immediately or after 2 seconds it's irrelevant as it will most probably take also around .5~1sec to get the response.

avatar PhilETaylor
PhilETaylor - comment - 9 May 2021

it will most probably take also around .5~1sec to get the response.

That is, if it doesn't actually check for updates, as it is cached out of the time. If it actually has to ask joomla.org for the latest information it will take considerably longer. This is what I thought it was doing when it was taking so long today.

avatar dgrammatiko
dgrammatiko - comment - 9 May 2021

If it actually has to ask joomla.org for the latest information it will take considerably longer

It always do that. I had proposed to have some sort of state store in session storage but people were against it for some reasons that I can't recall rn

avatar richard67 richard67 - change - 9 May 2021
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2021-05-09 17:50:05
Closed_By richard67
Labels Added: ?
avatar richard67 richard67 - close - 9 May 2021
avatar richard67 richard67 - merge - 9 May 2021
avatar richard67
richard67 - comment - 9 May 2021

Thanks!

Add a Comment

Login with GitHub to post a comment