Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
a04b3a13
Unverified
Commit
a04b3a13
authored
May 09, 2019
by
Hugo Häggmark
Committed by
GitHub
May 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Explore: Removes Promise.All from runQueries thunk (#16957)
parent
2abb009d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
72 deletions
+67
-72
packages/grafana-ui/src/components/SetInterval/SetInterval.tsx
+27
-26
public/app/features/explore/ExploreToolbar.tsx
+1
-1
public/app/features/explore/state/actions.ts
+39
-45
No files found.
packages/grafana-ui/src/components/SetInterval/SetInterval.tsx
View file @
a04b3a13
import
{
PureComponent
}
from
'react'
;
import
{
interval
,
Subscription
,
empty
,
Subject
}
from
'rxjs'
;
import
{
tap
,
switchMap
}
from
'rxjs/operators'
;
import
{
stringToMs
}
from
'../../utils/string'
;
interface
Props
{
func
:
()
=>
any
;
// TODO
loading
:
boolean
;
interval
:
string
;
}
export
class
SetInterval
extends
PureComponent
<
Props
>
{
private
intervalId
=
0
;
private
propsSubject
:
Subject
<
Props
>
;
private
subscription
:
Subscription
|
null
;
componentDidMount
()
{
this
.
addInterval
();
constructor
(
props
:
Props
)
{
super
(
props
);
this
.
propsSubject
=
new
Subject
<
Props
>
();
this
.
subscription
=
null
;
}
componentDidUpdate
(
prevProps
:
Props
)
{
const
{
interval
}
=
this
.
props
;
if
(
interval
!==
prevProps
.
interval
)
{
this
.
clearInterval
();
this
.
addInterval
();
}
componentDidMount
()
{
this
.
subscription
=
this
.
propsSubject
.
pipe
(
switchMap
(
props
=>
{
return
props
.
loading
?
empty
()
:
interval
(
stringToMs
(
props
.
interval
));
}),
tap
(()
=>
this
.
props
.
func
())
)
.
subscribe
();
this
.
propsSubject
.
next
(
this
.
props
);
}
component
WillUnmount
()
{
this
.
clearInterval
(
);
component
DidUpdate
()
{
this
.
propsSubject
.
next
(
this
.
props
);
}
addInterval
=
()
=>
{
const
{
func
,
interval
}
=
this
.
props
;
if
(
interval
)
{
func
().
then
(()
=>
{
if
(
interval
)
{
this
.
intervalId
=
window
.
setTimeout
(()
=>
{
this
.
addInterval
();
},
stringToMs
(
interval
));
}
});
componentWillUnmount
()
{
if
(
this
.
subscription
)
{
this
.
subscription
.
unsubscribe
();
}
};
clearInterval
=
()
=>
{
window
.
clearTimeout
(
this
.
intervalId
);
};
this
.
propsSubject
.
unsubscribe
();
}
render
()
{
return
null
;
...
...
public/app/features/explore/ExploreToolbar.tsx
View file @
a04b3a13
...
...
@@ -171,7 +171,7 @@ export class UnConnectedExploreToolbar extends PureComponent<Props, {}> {
value=
{
refreshInterval
}
tooltip=
"Refresh"
/>
{
refreshInterval
&&
<
SetInterval
func=
{
this
.
onRunQuery
}
interval=
{
refreshInterval
}
/>
}
{
refreshInterval
&&
<
SetInterval
func=
{
this
.
onRunQuery
}
interval=
{
refreshInterval
}
loading=
{
loading
}
/>
}
</
div
>
<
div
className=
"explore-toolbar-content-item"
>
...
...
public/app/features/explore/state/actions.ts
View file @
a04b3a13
...
...
@@ -546,7 +546,7 @@ export function queryTransactionSuccess(
/**
* Main action to run queries and dispatches sub-actions based on which result viewers are active
*/
export
function
runQueries
(
exploreId
:
ExploreId
,
ignoreUIState
=
false
):
ThunkResult
<
Promise
<
any
>
>
{
export
function
runQueries
(
exploreId
:
ExploreId
,
ignoreUIState
=
false
):
ThunkResult
<
void
>
{
return
(
dispatch
,
getState
)
=>
{
const
{
datasourceInstance
,
...
...
@@ -563,13 +563,13 @@ export function runQueries(exploreId: ExploreId, ignoreUIState = false): ThunkRe
if
(
datasourceError
)
{
// let's not run any queries if data source is in a faulty state
return
Promise
.
resolve
()
;
return
;
}
if
(
!
hasNonEmptyQuery
(
queries
))
{
dispatch
(
clearQueriesAction
({
exploreId
}));
dispatch
(
stateSave
());
// Remember to saves to state and update location
return
Promise
.
resolve
()
;
return
;
}
// Some datasource's query builders allow per-query interval limits,
...
...
@@ -578,46 +578,41 @@ export function runQueries(exploreId: ExploreId, ignoreUIState = false): ThunkRe
dispatch
(
runQueriesAction
({
exploreId
}));
// Keep table queries first since they need to return quickly
const
tableQueriesPromise
=
(
ignoreUIState
||
showingTable
)
&&
supportsTable
?
dispatch
(
runQueriesForType
(
exploreId
,
'Table'
,
{
interval
,
format
:
'table'
,
instant
:
true
,
valueWithRefId
:
true
,
},
(
data
:
any
[])
=>
data
[
0
]
)
)
:
undefined
;
const
typeQueriesPromise
=
(
ignoreUIState
||
showingGraph
)
&&
supportsGraph
?
dispatch
(
runQueriesForType
(
exploreId
,
'Graph'
,
{
interval
,
format
:
'time_series'
,
instant
:
false
,
maxDataPoints
:
containerWidth
,
},
makeTimeSeriesList
)
)
:
undefined
;
const
logsQueriesPromise
=
(
ignoreUIState
||
showingLogs
)
&&
supportsLogs
?
dispatch
(
runQueriesForType
(
exploreId
,
'Logs'
,
{
interval
,
format
:
'logs'
}))
:
undefined
;
if
((
ignoreUIState
||
showingTable
)
&&
supportsTable
)
{
dispatch
(
runQueriesForType
(
exploreId
,
'Table'
,
{
interval
,
format
:
'table'
,
instant
:
true
,
valueWithRefId
:
true
,
},
(
data
:
any
[])
=>
data
[
0
]
)
);
}
if
((
ignoreUIState
||
showingGraph
)
&&
supportsGraph
)
{
dispatch
(
runQueriesForType
(
exploreId
,
'Graph'
,
{
interval
,
format
:
'time_series'
,
instant
:
false
,
maxDataPoints
:
containerWidth
,
},
makeTimeSeriesList
)
);
}
if
((
ignoreUIState
||
showingLogs
)
&&
supportsLogs
)
{
dispatch
(
runQueriesForType
(
exploreId
,
'Logs'
,
{
interval
,
format
:
'logs'
}));
}
dispatch
(
stateSave
());
return
Promise
.
all
([
tableQueriesPromise
,
typeQueriesPromise
,
logsQueriesPromise
]);
};
}
...
...
@@ -638,7 +633,8 @@ function runQueriesForType(
const
{
datasourceInstance
,
eventBridge
,
queries
,
queryIntervals
,
range
,
scanning
}
=
getState
().
explore
[
exploreId
];
const
datasourceId
=
datasourceInstance
.
meta
.
id
;
// Run all queries concurrently
const
queryPromises
=
queries
.
map
(
async
(
query
,
rowIndex
)
=>
{
for
(
let
rowIndex
=
0
;
rowIndex
<
queries
.
length
;
rowIndex
++
)
{
const
query
=
queries
[
rowIndex
];
const
transaction
=
buildQueryTransaction
(
query
,
rowIndex
,
...
...
@@ -661,9 +657,7 @@ function runQueriesForType(
eventBridge
.
emit
(
'data-error'
,
response
);
dispatch
(
queryTransactionFailure
(
exploreId
,
transaction
.
id
,
response
,
datasourceId
));
}
});
return
Promise
.
all
(
queryPromises
);
}
};
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment