@@ -5,6 +5,7 @@ import { scopedLogger } from "@hpcc-js/util";
5
5
import { singletonHook } from "react-singleton-hook" ;
6
6
import { userKeyValStore } from "src/KeyValStore" ;
7
7
import { DockPanelLayout } from "../layouts/DockPanel" ;
8
+ import { singletonDebounce } from "../util/throttle" ;
8
9
import { useWorkunit } from "./workunit" ;
9
10
import { useQuery } from "./query" ;
10
11
import { useCounter } from "./util" ;
@@ -214,14 +215,19 @@ function useMetricsViewsImpl(): useMetricsViewsResult {
214
215
215
216
export const useMetricsViews = singletonHook ( defaultState , useMetricsViewsImpl ) ;
216
217
218
+ let wuDetailsMetaResponse : Promise < WsWorkunits . WUDetailsMetaResponse > ;
219
+
217
220
export function useMetricMeta ( ) : [ string [ ] , string [ ] ] {
218
221
219
222
const service = useConst ( ( ) => new WorkunitsService ( { baseUrl : "" } ) ) ;
220
223
const [ scopeTypes , setScopeTypes ] = React . useState < string [ ] > ( [ ] ) ;
221
224
const [ properties , setProperties ] = React . useState < string [ ] > ( [ ] ) ;
222
225
223
226
React . useEffect ( ( ) => {
224
- service ?. WUDetailsMeta ( { } ) . then ( response => {
227
+ if ( ! wuDetailsMetaResponse && service ) {
228
+ wuDetailsMetaResponse = service . WUDetailsMeta ( { } ) ;
229
+ }
230
+ wuDetailsMetaResponse ?. then ( response => {
225
231
setScopeTypes ( response ?. ScopeTypes ?. ScopeType || [ ] ) ;
226
232
setProperties ( ( response ?. Properties ?. Property . map ( p => p . Name ) || [ ] ) . sort ( ) ) ;
227
233
} ) ;
@@ -274,45 +280,48 @@ export function useWorkunitMetrics(
274
280
const [ count , increment ] = useCounter ( ) ;
275
281
276
282
React . useEffect ( ( ) => {
277
- setStatus ( FetchStatus . STARTED ) ;
278
- workunit ?. fetchDetailsNormalized ( {
279
- ScopeFilter : scopeFilter ,
280
- NestedFilter : nestedFilter ,
281
- PropertiesToReturn : {
282
- AllScopes : true ,
283
- AllAttributes : true ,
284
- AllProperties : true ,
285
- AllNotes : true ,
286
- AllStatistics : true ,
287
- AllHints : true
288
- } ,
289
- ScopeOptions : {
290
- IncludeId : true ,
291
- IncludeScope : true ,
292
- IncludeScopeType : true ,
293
- IncludeMatchedScopesInResults : true
294
- } ,
295
- PropertyOptions : {
296
- IncludeName : true ,
297
- IncludeRawValue : true ,
298
- IncludeFormatted : true ,
299
- IncludeMeasure : true ,
300
- IncludeCreator : false ,
301
- IncludeCreatorType : false
302
- }
303
- } ) . then ( response => {
304
- setData ( response ?. data ) ;
305
- setColumns ( response ?. columns ) ;
306
- setActivities ( response ?. meta ?. Activities ?. Activity || [ ] ) ;
307
- setProperties ( response ?. meta ?. Properties ?. Property || [ ] ) ;
308
- setMeasures ( response ?. meta ?. Measures ?. Measure || [ ] ) ;
309
- setScopeTypes ( response ?. meta ?. ScopeTypes ?. ScopeType || [ ] ) ;
310
- } ) . catch ( e => {
311
- logger . error ( e ) ;
312
- } ) . finally ( ( ) => {
313
- setStatus ( FetchStatus . COMPLETE ) ;
314
- } ) ;
315
- } , [ workunit , state , count , scopeFilter , nestedFilter ] ) ;
283
+ if ( wuid && workunit ) {
284
+ const fetchDetailsNormalized = singletonDebounce ( workunit , "fetchDetailsNormalized" ) ;
285
+ setStatus ( FetchStatus . STARTED ) ;
286
+ fetchDetailsNormalized ( {
287
+ ScopeFilter : scopeFilter ,
288
+ NestedFilter : nestedFilter ,
289
+ PropertiesToReturn : {
290
+ AllScopes : true ,
291
+ AllAttributes : true ,
292
+ AllProperties : true ,
293
+ AllNotes : true ,
294
+ AllStatistics : true ,
295
+ AllHints : true
296
+ } ,
297
+ ScopeOptions : {
298
+ IncludeId : true ,
299
+ IncludeScope : true ,
300
+ IncludeScopeType : true ,
301
+ IncludeMatchedScopesInResults : true
302
+ } ,
303
+ PropertyOptions : {
304
+ IncludeName : true ,
305
+ IncludeRawValue : true ,
306
+ IncludeFormatted : true ,
307
+ IncludeMeasure : true ,
308
+ IncludeCreator : false ,
309
+ IncludeCreatorType : false
310
+ }
311
+ } ) . then ( response => {
312
+ setData ( response ?. data ) ;
313
+ setColumns ( response ?. columns ) ;
314
+ setActivities ( response ?. meta ?. Activities ?. Activity || [ ] ) ;
315
+ setProperties ( response ?. meta ?. Properties ?. Property || [ ] ) ;
316
+ setMeasures ( response ?. meta ?. Measures ?. Measure || [ ] ) ;
317
+ setScopeTypes ( response ?. meta ?. ScopeTypes ?. ScopeType || [ ] ) ;
318
+ } ) . catch ( e => {
319
+ logger . error ( e ) ;
320
+ } ) . finally ( ( ) => {
321
+ setStatus ( FetchStatus . COMPLETE ) ;
322
+ } ) ;
323
+ }
324
+ } , [ workunit , state , count , scopeFilter , nestedFilter , wuid ] ) ;
316
325
317
326
return { metrics : data , columns, activities, properties, measures, scopeTypes, status, refresh : increment } ;
318
327
}
@@ -335,45 +344,48 @@ export function useQueryMetrics(
335
344
const [ count , increment ] = useCounter ( ) ;
336
345
337
346
React . useEffect ( ( ) => {
338
- setStatus ( FetchStatus . STARTED ) ;
339
- query ?. fetchDetailsNormalized ( {
340
- ScopeFilter : scopeFilter ,
341
- NestedFilter : nestedFilter ,
342
- PropertiesToReturn : {
343
- AllScopes : true ,
344
- AllAttributes : true ,
345
- AllProperties : true ,
346
- AllNotes : true ,
347
- AllStatistics : true ,
348
- AllHints : true
349
- } ,
350
- ScopeOptions : {
351
- IncludeId : true ,
352
- IncludeScope : true ,
353
- IncludeScopeType : true ,
354
- IncludeMatchedScopesInResults : true
355
- } ,
356
- PropertyOptions : {
357
- IncludeName : true ,
358
- IncludeRawValue : true ,
359
- IncludeFormatted : true ,
360
- IncludeMeasure : true ,
361
- IncludeCreator : false ,
362
- IncludeCreatorType : false
363
- }
364
- } ) . then ( response => {
365
- setData ( response ?. data ) ;
366
- setColumns ( response ?. columns ) ;
367
- setActivities ( response ?. meta ?. Activities ?. Activity || [ ] ) ;
368
- setProperties ( response ?. meta ?. Properties ?. Property || [ ] ) ;
369
- setMeasures ( response ?. meta ?. Measures ?. Measure || [ ] ) ;
370
- setScopeTypes ( response ?. meta ?. ScopeTypes ?. ScopeType || [ ] ) ;
371
- } ) . catch ( e => {
372
- logger . error ( e ) ;
373
- } ) . finally ( ( ) => {
374
- setStatus ( FetchStatus . COMPLETE ) ;
375
- } ) ;
376
- } , [ query , state , count , scopeFilter , nestedFilter ] ) ;
347
+ if ( querySet && queryId && query ) {
348
+ const fetchDetailsNormalized = singletonDebounce ( query , "fetchDetailsNormalized" ) ;
349
+ setStatus ( FetchStatus . STARTED ) ;
350
+ fetchDetailsNormalized ( {
351
+ ScopeFilter : scopeFilter ,
352
+ NestedFilter : nestedFilter ,
353
+ PropertiesToReturn : {
354
+ AllScopes : true ,
355
+ AllAttributes : true ,
356
+ AllProperties : true ,
357
+ AllNotes : true ,
358
+ AllStatistics : true ,
359
+ AllHints : true
360
+ } ,
361
+ ScopeOptions : {
362
+ IncludeId : true ,
363
+ IncludeScope : true ,
364
+ IncludeScopeType : true ,
365
+ IncludeMatchedScopesInResults : true
366
+ } ,
367
+ PropertyOptions : {
368
+ IncludeName : true ,
369
+ IncludeRawValue : true ,
370
+ IncludeFormatted : true ,
371
+ IncludeMeasure : true ,
372
+ IncludeCreator : false ,
373
+ IncludeCreatorType : false
374
+ }
375
+ } ) . then ( response => {
376
+ setData ( response ?. data ) ;
377
+ setColumns ( response ?. columns ) ;
378
+ setActivities ( response ?. meta ?. Activities ?. Activity || [ ] ) ;
379
+ setProperties ( response ?. meta ?. Properties ?. Property || [ ] ) ;
380
+ setMeasures ( response ?. meta ?. Measures ?. Measure || [ ] ) ;
381
+ setScopeTypes ( response ?. meta ?. ScopeTypes ?. ScopeType || [ ] ) ;
382
+ } ) . catch ( e => {
383
+ logger . error ( e ) ;
384
+ } ) . finally ( ( ) => {
385
+ setStatus ( FetchStatus . COMPLETE ) ;
386
+ } ) ;
387
+ }
388
+ } , [ query , state , count , scopeFilter , nestedFilter , querySet , queryId ] ) ;
377
389
378
390
return { metrics : data , columns, activities, properties, measures, scopeTypes, status, refresh : increment } ;
379
391
}
@@ -385,7 +397,8 @@ export function useWUQueryMetrics(
385
397
scopeFilter : Partial < WsWorkunits . ScopeFilter > = scopeFilterDefault ,
386
398
nestedFilter : WsWorkunits . NestedFilter = nestedFilterDefault
387
399
) : useMetricsResult {
388
- const wuMetrics = useWorkunitMetrics ( wuid , scopeFilter , nestedFilter ) ;
389
- const queryMetrics = useQueryMetrics ( querySet , queryId , scopeFilter , nestedFilter ) ;
390
- return querySet && queryId ? { ...queryMetrics } : { ...wuMetrics } ;
400
+ const isQuery = querySet && queryId ;
401
+ const wuMetrics = useWorkunitMetrics ( isQuery ? "" : wuid , scopeFilter , nestedFilter ) ;
402
+ const queryMetrics = useQueryMetrics ( isQuery ? querySet : "" , isQuery ? queryId : "" , scopeFilter , nestedFilter ) ;
403
+ return isQuery ? { ...queryMetrics } : { ...wuMetrics } ;
391
404
}
0 commit comments