Dashboards: Prevent shared queries from being unnecessarily re-run (#77490)

* Dashboards: Prevent shared queries from being unnecessarily re-run

* Minor change

* Set solo panel as being viewed

---------

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
This commit is contained in:
kay delaney
2023-11-09 14:41:47 +00:00
committed by GitHub
parent 3a4f73338c
commit 5f78542366
4 changed files with 18 additions and 9 deletions

View File

@ -74,7 +74,6 @@ export interface State {
isFirstLoad: boolean;
renderCounter: number;
errorMessage?: string;
refreshWhenInView: boolean;
context: PanelContext;
data: PanelData;
liveTime?: TimeRange;
@ -95,7 +94,6 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
this.state = {
isFirstLoad: true,
renderCounter: 0,
refreshWhenInView: false,
context: {
eventsScope: '__global_',
eventBus,
@ -258,7 +256,7 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
}
componentDidUpdate(prevProps: Props) {
const { isInView, width } = this.props;
const { isInView, width, panel } = this.props;
const { context } = this.state;
const app = this.getPanelContextApp();
@ -276,7 +274,7 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
if (isInView !== prevProps.isInView) {
if (isInView) {
// Check if we need a delayed refresh
if (this.state.refreshWhenInView) {
if (panel.refreshWhenInView) {
this.onRefresh();
}
}
@ -343,7 +341,7 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
const { dashboard, panel, isInView, width } = this.props;
if (!isInView) {
this.setState({ refreshWhenInView: true });
panel.refreshWhenInView = true;
return;
}
@ -355,9 +353,7 @@ export class PanelStateWrapper extends PureComponent<Props, State> {
return;
}
if (this.state.refreshWhenInView) {
this.setState({ refreshWhenInView: false });
}
panel.refreshWhenInView = false;
panel.runAllPanelQueries({
dashboardUID: dashboard.uid,
dashboardTimezone: dashboard.getTimezone(),