mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
reduce api calls to really just check every 5 seconds
This commit is contained in:
parent
1d123827bc
commit
92c3eaef8f
@ -218,11 +218,12 @@ function inventreeDocReady() {
|
||||
// Display any cached alert messages
|
||||
showCachedAlerts();
|
||||
|
||||
// Start notification background worker to check every 5 seconds if notifications are available
|
||||
setInterval(notificationCheck, 5000);
|
||||
// Start notification background worker to check every 1 seconds if notifications are available
|
||||
setInterval(notificationCheck, 1000);
|
||||
|
||||
// also run when the focus returns
|
||||
$(document).on('focus', function(e){
|
||||
notificationCheck();
|
||||
notificationCheck(force = true);
|
||||
});
|
||||
|
||||
$('#offcanvasRight').on('show.bs.offcanvas', openNotificationPanel) // listener for opening the notification panel
|
||||
|
@ -119,14 +119,20 @@ function showMessage(message, options={}) {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
var notificationUpdateTic = 0;
|
||||
/**
|
||||
* The notification checker is initiated when the document is loaded. It checks if there are unread notifications
|
||||
* if unread messages exist the alert flag is raised by making it visible
|
||||
**/
|
||||
function notificationCheck() {
|
||||
// only refresh state if in focus
|
||||
if (document.hasFocus()) {
|
||||
function notificationCheck(force = false) {
|
||||
notificationUpdateTic = notificationUpdateTic + 1;
|
||||
|
||||
console.log(notificationUpdateTic);
|
||||
|
||||
// refresh if forced or
|
||||
// if in focus and was not refreshed in the last 5 seconds
|
||||
if (force || (document.hasFocus() && notificationUpdateTic >= 5)) {
|
||||
notificationUpdateTic = 0;
|
||||
inventreeGet(
|
||||
'/api/notifications/',
|
||||
{
|
||||
@ -262,6 +268,9 @@ function closeNotificationPanel() {
|
||||
* updates the notification counter
|
||||
**/
|
||||
function updateNotificationIndicator(count) {
|
||||
// reset update Ticker -> safe some API bandwidth
|
||||
notificationUpdateTic = 0;
|
||||
|
||||
if (count == 0) {
|
||||
$("#notification-alert").addClass("d-none");
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user