mirror of
https://github.com/grafana/grafana.git
synced 2025-01-26 16:27:02 -06:00
QueryProcessing: Fixes showing last result in initial loading state (#19057)
* PanelQueryRunner: Need to cache preProcessPanelData function between runs so last result can be remembered * Better fix for remembering lastResult * Code simplification * Simplify code a bit
This commit is contained in:
parent
e3a99a0a3d
commit
55717769a3
@ -44,6 +44,7 @@ export class PanelQueryRunner {
|
|||||||
private subject?: ReplaySubject<PanelData>;
|
private subject?: ReplaySubject<PanelData>;
|
||||||
private subscription?: Unsubscribable;
|
private subscription?: Unsubscribable;
|
||||||
private transformations?: DataTransformerConfig[];
|
private transformations?: DataTransformerConfig[];
|
||||||
|
private lastResult?: PanelData;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.subject = new ReplaySubject(1);
|
this.subject = new ReplaySubject(1);
|
||||||
@ -153,12 +154,10 @@ export class PanelQueryRunner {
|
|||||||
this.subscription.unsubscribe();
|
this.subscription.unsubscribe();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makes sure everything is a proper DataFrame
|
|
||||||
const prepare = preProcessPanelData();
|
|
||||||
|
|
||||||
this.subscription = observable.subscribe({
|
this.subscription = observable.subscribe({
|
||||||
next: (data: PanelData) => {
|
next: (data: PanelData) => {
|
||||||
this.subject.next(prepare(data));
|
this.lastResult = preProcessPanelData(data, this.lastResult);
|
||||||
|
this.subject.next(this.lastResult);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -187,25 +187,18 @@ export function getProcessedDataFrames(results?: DataQueryResponseData[]): DataF
|
|||||||
return dataFrames;
|
return dataFrames;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function preProcessPanelData() {
|
export function preProcessPanelData(data: PanelData, lastResult: PanelData) {
|
||||||
let lastResult: PanelData = null;
|
let { series } = data;
|
||||||
|
|
||||||
return function mapper(data: PanelData) {
|
// for loading states with no data, use last result
|
||||||
let { series } = data;
|
if (data.state === LoadingState.Loading && series.length === 0) {
|
||||||
|
if (!lastResult) {
|
||||||
// for loading states with no data, use last result
|
lastResult = data;
|
||||||
if (data.state === LoadingState.Loading && series.length === 0) {
|
|
||||||
if (!lastResult) {
|
|
||||||
lastResult = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return { ...lastResult, state: LoadingState.Loading };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Makes sure the data is properly formatted
|
return { ...lastResult, state: LoadingState.Loading };
|
||||||
series = getProcessedDataFrames(series);
|
}
|
||||||
|
|
||||||
lastResult = { ...data, series };
|
// Makes sure the data is properly formatted
|
||||||
return lastResult;
|
return getProcessedDataFrames(series);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
@ -439,6 +439,7 @@ export function runQueries(exploreId: ExploreId): ThunkResult<void> {
|
|||||||
queryIntervals,
|
queryIntervals,
|
||||||
range,
|
range,
|
||||||
scanning,
|
scanning,
|
||||||
|
queryResponse,
|
||||||
querySubscription,
|
querySubscription,
|
||||||
history,
|
history,
|
||||||
mode,
|
mode,
|
||||||
@ -479,7 +480,11 @@ export function runQueries(exploreId: ExploreId): ThunkResult<void> {
|
|||||||
let firstResponse = true;
|
let firstResponse = true;
|
||||||
|
|
||||||
const newQuerySub = runRequest(datasourceInstance, transaction.request)
|
const newQuerySub = runRequest(datasourceInstance, transaction.request)
|
||||||
.pipe(map(preProcessPanelData()))
|
.pipe(
|
||||||
|
map((data: PanelData) => {
|
||||||
|
return preProcessPanelData(data, queryResponse);
|
||||||
|
})
|
||||||
|
)
|
||||||
.subscribe((data: PanelData) => {
|
.subscribe((data: PanelData) => {
|
||||||
if (!data.error && firstResponse) {
|
if (!data.error && firstResponse) {
|
||||||
// Side-effect: Saving history in localstorage
|
// Side-effect: Saving history in localstorage
|
||||||
|
@ -618,8 +618,8 @@ export const processQueryResponse = (
|
|||||||
|
|
||||||
const latency = request.endTime ? request.endTime - request.startTime : 0;
|
const latency = request.endTime ? request.endTime - request.startTime : 0;
|
||||||
const processor = new ResultProcessor(state, series);
|
const processor = new ResultProcessor(state, series);
|
||||||
const graphResult = processor.getGraphResult() || state.graphResult; // don't replace results until we receive new results
|
const graphResult = processor.getGraphResult();
|
||||||
const tableResult = processor.getTableResult() || state.tableResult || new TableModel(); // don't replace results until we receive new results
|
const tableResult = processor.getTableResult();
|
||||||
const logsResult = processor.getLogsResult();
|
const logsResult = processor.getLogsResult();
|
||||||
|
|
||||||
// Send legacy data to Angular editors
|
// Send legacy data to Angular editors
|
||||||
|
Loading…
Reference in New Issue
Block a user