Skip to content

Commit

Permalink
Limit resource count for header display to avoid unnecessary large co…
Browse files Browse the repository at this point in the history
…unt queries (#2404)

- Updated the cloud resources count query to accept a maxSize parameter, allowing for more flexible data retrieval.
    - Modified the Inventory component to display cloud resource counts, showing a '+' sign if the count exceeds the defined
maximum limit of 9999.
  • Loading branch information
manV authored Jan 8, 2025
1 parent 9796e9f commit a339584
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import { TopologyHeader } from '@/features/topology/components/TopologyHeader';
import { queries } from '@/queries';
import { usePageNavigation } from '@/utils/usePageNavigation';

const MAX_CLOUD_RESOURCE_COUNT = 9999;

function useCloudResourcesCount() {
return useSuspenseQuery({ ...queries.search.cloudResourcesCount() });
return useSuspenseQuery({
...queries.search.cloudResourcesCount({ maxSize: MAX_CLOUD_RESOURCE_COUNT + 1 }),
});
}

const CloudResourceCount = () => {
const { data: cloudResourceCount } = useCloudResourcesCount();
return <b>{cloudResourceCount}</b>;
return (
<b>
{cloudResourceCount > MAX_CLOUD_RESOURCE_COUNT
? `${MAX_CLOUD_RESOURCE_COUNT}+`
: cloudResourceCount}
</b>
);
};

const inventoryTabs = [
Expand Down
4 changes: 2 additions & 2 deletions deepfence_frontend/apps/dashboard/src/queries/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1563,7 +1563,7 @@ export const searchQueries = createQueryKeys('search', {
},
};
},
cloudResourcesCount: () => {
cloudResourcesCount: ({ maxSize }: { maxSize: number }) => {
return {
queryKey: ['cloudResourcesCount'],
queryFn: async () => {
Expand All @@ -1587,7 +1587,7 @@ export const searchQueries = createQueryKeys('search', {
},
window: {
offset: 0,
size: Number.MAX_SAFE_INTEGER,
size: maxSize,
},
},
});
Expand Down

0 comments on commit a339584

Please sign in to comment.