From ddd8ce2202392d3fb6066df68a7451c7c4e58fe2 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Wed, 19 Aug 2020 15:08:59 +0200 Subject: [PATCH] * Notifications: Some performance optimizations --- notifications/js/notificationajaxpopup.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/notifications/js/notificationajaxpopup.js b/notifications/js/notificationajaxpopup.js index 1a16052f24..920d6c5658 100644 --- a/notifications/js/notificationajaxpopup.js +++ b/notifications/js/notificationajaxpopup.js @@ -16,6 +16,7 @@ { var notifymessages = {}; + var _currentRawData = []; /** * time range label today * @type Number @@ -262,6 +263,7 @@ { for (var c in notifymessages[id]['children']) { + if (Object.keys(notifymessages[id]['children']).indexOf(c) < Object.keys(notifymessages[id]['children']).length-2) continue; $inner_container[0].innerHTML += notifymessages[id]['children'][c]['message']; } } @@ -661,6 +663,11 @@ notifications.prototype.append = function(_rawData, _browser_notify) { var hasUnseen = []; + // Dont process the data if they're the same as it could get very expensive to + // proccess html their content. + if (_currentRawData.length>0 && _currentRawData.length == _rawData.length) return; + _currentRawData = _rawData; + let old_notifymessages = notifymessages; notifymessages = {}; var browser_notify = _browser_notify || this.check_browser_notify(); for (var i=0; i < _rawData.length; i++) @@ -737,6 +744,7 @@ } } + let egwpopup = document.getElementById('egwpopup'); switch(egw.preference('egwpopup_verbosity', 'notifications')) { case 'low': @@ -748,10 +756,17 @@ alert(egw.lang('EGroupware has notifications for you')); egw.json("notifications.notifications_ajax.update_status", [hasUnseen, 'DISPLAYED']).sendRequest(); } - this.display(); + if (egwpopup.style.display != 'none') this.display(); break; case 'medium': - this.display(); + if (egwpopup.style.display != 'none' && Object.keys(old_notifymessages).length != Object.keys(notifymessages).length) + { + this.display(); + } + else + { + this.counterUpdate(); + } } }; @@ -763,7 +778,9 @@ * @returns {notificationajaxpopup_L15.notifications.prototype.getData.data} */ notifications.prototype.getData = function (_message, _extra_data) { - var dom = jQuery(document.createElement('div')).html(_message); + var parser = new DOMParser(); + var dom = jQuery(parser.parseFromString(_message, 'text/html')); + var extra_data = _extra_data || {}; var link = dom.find('div[data-id],div[data-url]'); var data = {