From c1f8f32790b4b64c33747c21067b9c794fcf7b2b Mon Sep 17 00:00:00 2001 From: Craig Harshbarger Date: Wed, 8 Nov 2023 15:29:12 -0600 Subject: [PATCH] Make the data refresh interval based on the number of nodes --- demo/data/graph-small.json | 2 +- src/consts.ts | 1 - src/factories/data.ts | 10 ++++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/demo/data/graph-small.json b/demo/data/graph-small.json index 1e320412..7733a2ff 100644 --- a/demo/data/graph-small.json +++ b/demo/data/graph-small.json @@ -1,6 +1,6 @@ { "start_time": "2023-09-27T15:50:39.425118+00:00", - "end_time": "2023-09-27T15:51:11.922153+00:00", + "end_time": null, "root_node_ids": [ "ea9d7c12-7418-4ea9-b33d-189f22f737af", "7d93e182-e17f-40a2-a0c3-784d1d0e7ff5", diff --git a/src/consts.ts b/src/consts.ts index a7272848..e3d036d9 100644 --- a/src/consts.ts +++ b/src/consts.ts @@ -1,4 +1,3 @@ -export const DEFAULT_POLL_INTERVAL = 1000 export const DEFAULT_NODES_CONTAINER_NAME = 'nodes-container' export const DEFAULT_NODE_CONTAINER_NAME = 'node-container' export const DEFAULT_EDGE_CONTAINER_NAME = 'edge-container' diff --git a/src/factories/data.ts b/src/factories/data.ts index 7694e4d9..14f061fc 100644 --- a/src/factories/data.ts +++ b/src/factories/data.ts @@ -1,4 +1,4 @@ -import { DEFAULT_POLL_INTERVAL } from '@/consts' +import { millisecondsInSecond } from 'date-fns' import { RunGraphData } from '@/models/RunGraph' import { waitForConfig } from '@/objects/config' @@ -22,7 +22,7 @@ export async function dataFactory(runId: string, callback: DataCallback) { if (data && !data.end_time) { - interval = setTimeout(() => start(), DEFAULT_POLL_INTERVAL) + interval = setTimeout(() => start(), getIntervalForDataSize(data)) } } @@ -36,4 +36,10 @@ export async function dataFactory(runId: string, callback: DataCallback) { stop, } +} + +function getIntervalForDataSize(data: RunGraphData): number { + const intervalBasedOnNodeCount = Math.floor(data.nodes.size / millisecondsInSecond) * millisecondsInSecond + + return Math.max(millisecondsInSecond, intervalBasedOnNodeCount) } \ No newline at end of file