* Notifications: performance improvements on fetching notifications

This commit is contained in:
Hadi Nategh 2018-06-19 14:58:32 +02:00
parent 17daf70e8a
commit e8cc3d0eb3
2 changed files with 78 additions and 71 deletions

View File

@ -180,7 +180,8 @@ class notifications_ajax {
'account_id' => $this->recipient->account_id,
'notify_type' => self::_type
),
__LINE__,__FILE__,false,'',self::_appname);
__LINE__,__FILE__,false,'ORDER BY notify_id DESC LIMIT 0,100',self::_appname);
$result = array();
if ($rs->NumRows() > 0) {
foreach ($rs as $notification) {
$actions = null;
@ -193,33 +194,17 @@ class notifications_ajax {
), $data['appname'], true);
$actions = $_actions[$data['appname']];
}
$this->response->apply('app.notifications.append',array(
$notification['notify_id'],
$notification['notify_message'],
$browserNotify,
$notification['notify_status'],
Api\DateTime::to($notification['notify_created']),
new DateTime(),
is_array($actions)?$actions:NULL)
$result[] = array(
'id' => $notification['notify_id'],
'message' => $notification['notify_message'],
'status' => $notification['notify_status'],
'created' => Api\DateTime::to($notification['notify_created']),
'current' => new DateTime(),
'action' => is_array($actions)?$actions:NULL
);
}
switch($this->preferences[self::_appname]['egwpopup_verbosity']) {
case 'low':
$this->response->apply('app.notifications.bell', array('active'));
break;
case 'high':
if (empty($notification['notify_status']) || $notification['notify_status'] === "UNSEEN")
{
$this->response->alert(lang('EGroupware has notifications for you'));
}
$this->response->apply('app.notifications.display');
break;
case 'medium':
default:
$this->response->apply('app.notifications.display');
break;
}
$this->response->apply('app.notifications.append', array($result, $browserNotify));
}
return true;
}

View File

@ -474,31 +474,29 @@
/**
* Add message to internal display-queue
*
* @param _id
* @param _message
* @param _rowData
* @param _browser_notify
* @param {string} _status
* @param {string} _created
*
* @return undefined
*/
notifications.prototype.append = function(_id, _message, _browser_notify,
_status, _created, _current, _actions) {
var data = this.getData(_message);
notifications.prototype.append = function(_rawData, _browser_notify) {
var hasUnseen = [];
for (var i=0; i < _rawData.length; i++)
{
var data = this.getData(_rawData[i]['message']);
// Prevent the same thing popping up multiple times
notifymessages[_id] = {
message:_message,
notifymessages[_rawData[i]['id']] = {
message:_rawData[i]['message'],
data: data,
status: _status,
created: _created,
current: _current
status: _rawData[i]['status'],
created: _rawData[i]['created'],
current: _rawData[i]['current']
};
if (_actions && _actions.length > 0) notifymessages[_id]['data']['actions'] = _actions;
if (_rawData[i]['actions'] && _rawData[i]['actions'].length > 0) notifymessages[_rawData[i]['id']]['data']['actions'] = _rawData[i]['actions'];
// Notification API
if(_browser_notify && !_status)
if(_browser_notify && !_rawData[i]['status'])
{
egw.notification(data.title, {
tag: data.app+":"+_id,
tag: data.app+":"+_rawData[i]['id'],
body: data.message,
icon: data.icon,
onclose:function(e){
@ -529,6 +527,30 @@
}
});
}
if (!_rawData[i]['status'])
{
egw.json("notifications.notifications_ajax.update_status", [_rawData[i]['id'], 'DISPLAYED']);
hasUnseen.push(_rawData[i]['id']);
}
}
switch(egw.preference('egwpopup_verbosity', 'notifications'))
{
case 'low':
this.bell('active');
break;
case 'high':
if (hasUnseen.length > 0)
{
alert(egw.lang('EGroupware has notifications for you'));
egw.json("notifications.notifications_ajax.update_status", [hasUnseen, 'DISPLAYED']).sendRequest();
}
this.display();
break;
case 'medium':
this.display();
}
};
/**