mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 04:56:45 +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
|
// Display any cached alert messages
|
||||||
showCachedAlerts();
|
showCachedAlerts();
|
||||||
|
|
||||||
// Start notification background worker to check every 5 seconds if notifications are available
|
// Start notification background worker to check every 1 seconds if notifications are available
|
||||||
setInterval(notificationCheck, 5000);
|
setInterval(notificationCheck, 1000);
|
||||||
|
|
||||||
// also run when the focus returns
|
// also run when the focus returns
|
||||||
$(document).on('focus', function(e){
|
$(document).on('focus', function(e){
|
||||||
notificationCheck();
|
notificationCheck(force = true);
|
||||||
});
|
});
|
||||||
|
|
||||||
$('#offcanvasRight').on('show.bs.offcanvas', openNotificationPanel) // listener for opening the notification panel
|
$('#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
|
* 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
|
* if unread messages exist the alert flag is raised by making it visible
|
||||||
**/
|
**/
|
||||||
function notificationCheck() {
|
function notificationCheck(force = false) {
|
||||||
// only refresh state if in focus
|
notificationUpdateTic = notificationUpdateTic + 1;
|
||||||
if (document.hasFocus()) {
|
|
||||||
|
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(
|
inventreeGet(
|
||||||
'/api/notifications/',
|
'/api/notifications/',
|
||||||
{
|
{
|
||||||
@ -262,6 +268,9 @@ function closeNotificationPanel() {
|
|||||||
* updates the notification counter
|
* updates the notification counter
|
||||||
**/
|
**/
|
||||||
function updateNotificationIndicator(count) {
|
function updateNotificationIndicator(count) {
|
||||||
|
// reset update Ticker -> safe some API bandwidth
|
||||||
|
notificationUpdateTic = 0;
|
||||||
|
|
||||||
if (count == 0) {
|
if (count == 0) {
|
||||||
$("#notification-alert").addClass("d-none");
|
$("#notification-alert").addClass("d-none");
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user