Skip to content

Commit

Permalink
Using batching library and bulk endpoint to batch pipeline count retr…
Browse files Browse the repository at this point in the history
…ieval.
  • Loading branch information
dennisoelkers committed Nov 26, 2024
1 parent a6a78a7 commit e040b2e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
13 changes: 8 additions & 5 deletions graylog2-web-interface/src/hooks/usePipelinesConnectedStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import { useQuery } from '@tanstack/react-query';
import { create, windowScheduler } from '@yornaath/batshit';

import { qualifyUrl } from 'util/URLUtils';
import fetch from 'logic/rest/FetchProvider';
import ApiRoutes from 'routing/ApiRoutes';
import { Streams } from '@graylog/server-api';
import type FetchError from 'logic/errors/FetchError';
import type { PipelineType } from 'stores/pipelines/PipelinesStore';

export type StreamConnectedPipelines = Array<Pick<PipelineType, 'id' | 'title'>>

const fetchPipelinesConnectedStream = (streamId: string) => fetch('GET', qualifyUrl(ApiRoutes.StreamsApiController.stream_connected_pipelines(streamId).url));
const pipelines = create({
fetcher: async (streamIds: Array<string>) => Streams.getConnectedPipelinesForStreams({ stream_ids: streamIds }),
resolver: (items, query) => items[query],
scheduler: windowScheduler(10),
});

const usePipelinesConnectedStream = (streamId: string): {
data: StreamConnectedPipelines,
Expand All @@ -35,7 +38,7 @@ const usePipelinesConnectedStream = (streamId: string): {
} => {
const { data, refetch, isInitialLoading, error, isError } = useQuery<StreamConnectedPipelines, FetchError>(
['stream', 'pipelines', streamId],
() => fetchPipelinesConnectedStream(streamId),
() => pipelines.fetch(streamId),
{
notifyOnChangeProps: ['data', 'error'],
},
Expand Down
1 change: 0 additions & 1 deletion graylog2-web-interface/src/routing/ApiRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ const ApiRoutes = {
delete: (streamId: string) => ({ url: `/streams/${streamId}` }),
pause: (streamId: string) => ({ url: `/streams/${streamId}/pause` }),
resume: (streamId: string) => ({ url: `/streams/${streamId}/resume` }),
stream_connected_pipelines: (streamId: string) => ({ url: `/streams/${streamId}/pipelines` }),
testMatch: (streamId: string) => ({ url: `/streams/${streamId}/testMatch` }),
},
StreamOutputsApiController: {
Expand Down

0 comments on commit e040b2e

Please sign in to comment.