Live: broadcast first event immediately (#34310)

This commit is contained in:
Ryan McKinley 2021-05-18 11:19:19 -07:00 committed by GitHub
parent 25485100b0
commit 18954aaa7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -214,23 +214,11 @@ export class CentrifugeSrv implements GrafanaLiveSrv {
return new Observable<DataQueryResponse>((subscriber) => {
const channel = this.getChannel(options.addr);
const key = options.key ?? `xstr/${streamCounter++}`;
let data: StreamingDataFrame | undefined = undefined;
let filtered: DataFrame | undefined = undefined;
let state = LoadingState.Loading;
let { key } = options;
let state = LoadingState.Streaming;
let last = perf.last;
if (options.frame) {
const msg = dataFrameToJSON(options.frame);
data = new StreamingDataFrame(msg, options.buffer);
state = LoadingState.Streaming;
}
if (channel.lastMessageWithSchema && !data) {
data = new StreamingDataFrame(channel.lastMessageWithSchema, options.buffer);
}
if (!key) {
key = `xstr/${streamCounter++}`;
}
const process = (msg: DataFrameJSON) => {
if (!data) {
@ -262,6 +250,12 @@ export class CentrifugeSrv implements GrafanaLiveSrv {
}
};
if (options.frame) {
process(dataFrameToJSON(options.frame));
} else if (channel.lastMessageWithSchema) {
process(channel.lastMessageWithSchema);
}
const sub = channel.getStream().subscribe({
error: (err: any) => {
console.log('LiveQuery [error]', { err }, options.addr);