2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-27 19:16:44 +00:00

Update notification fetching (#9557)

- Reduce interval to 1 minute
- Only fetch for visible tab
This commit is contained in:
Oliver 2025-04-22 09:52:50 +10:00 committed by GitHub
parent 40ded29b35
commit 89b3f91ded
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 4 deletions

View File

@ -11,7 +11,7 @@ import {
Text,
Tooltip
} from '@mantine/core';
import { useDisclosure } from '@mantine/hooks';
import { useDisclosure, useDocumentVisibility } from '@mantine/hooks';
import { IconBell, IconSearch } from '@tabler/icons-react';
import { useQuery } from '@tanstack/react-query';
import { type ReactNode, useEffect, useMemo, useState } from 'react';
@ -63,10 +63,12 @@ export function Header() {
return server.customize?.navbar_message;
}, [server.customize]);
const visibility = useDocumentVisibility();
// Fetch number of notifications for the current user
const notifications = useQuery({
queryKey: ['notification-count'],
enabled: isLoggedIn(),
enabled: isLoggedIn() && visibility === 'visible',
queryFn: async () => {
if (!isLoggedIn()) {
return null;
@ -90,7 +92,8 @@ export function Header() {
return null;
}
},
refetchInterval: 5 * 60 * 1000,
// Refetch every minute, *if* the tab is visible
refetchInterval: 60 * 1000,
refetchOnMount: true
});

View File

@ -1,6 +1,7 @@
import { ApiEndpoints } from '@lib/enums/ApiEndpoints';
import { apiUrl } from '@lib/functions/Api';
import { t } from '@lingui/core/macro';
import { useDocumentVisibility } from '@mantine/hooks';
import { notifications, showNotification } from '@mantine/notifications';
import { IconCircleCheck } from '@tabler/icons-react';
import { useQuery } from '@tanstack/react-query';
@ -21,6 +22,8 @@ export default function useDataOutput({
}) {
const api = useApi();
const visibility = useDocumentVisibility();
const [loading, setLoading] = useState<boolean>(false);
useEffect(() => {
@ -38,7 +41,7 @@ export default function useDataOutput({
}, [id, title]);
const progress = useQuery({
enabled: !!id && loading,
enabled: !!id && loading && visibility === 'visible',
refetchInterval: 500,
queryKey: ['data-output', id, title],
queryFn: () =>