mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
This commit is contained in:
parent
843af318a1
commit
436757b334
2 changed files with 22 additions and 17 deletions
|
@ -41,9 +41,9 @@ const aggSchemas = new Schemas([
|
|||
}
|
||||
]);
|
||||
|
||||
export function extractPropertiesMap(resp, propertyNames, countPropertyName) {
|
||||
export function extractPropertiesMap(rawEsData, propertyNames, countPropertyName) {
|
||||
const propertiesMap = new Map();
|
||||
_.get(resp, ['aggregations', TERMS_AGG_NAME, 'buckets'], []).forEach(termBucket => {
|
||||
_.get(rawEsData, ['aggregations', TERMS_AGG_NAME, 'buckets'], []).forEach(termBucket => {
|
||||
const properties = {};
|
||||
if (countPropertyName) {
|
||||
properties[countPropertyName] = termBucket.doc_count;
|
||||
|
@ -106,7 +106,7 @@ export class ESJoinSource extends AbstractESSource {
|
|||
const configStates = this._makeAggConfigs();
|
||||
const aggConfigs = new AggConfigs(indexPattern, configStates, aggSchemas.all);
|
||||
|
||||
let resp;
|
||||
let rawEsData;
|
||||
try {
|
||||
const searchSource = new SearchSource();
|
||||
searchSource.setField('index', indexPattern);
|
||||
|
@ -122,7 +122,7 @@ export class ESJoinSource extends AbstractESSource {
|
|||
|
||||
const dsl = aggConfigs.toDsl();
|
||||
searchSource.setField('aggs', dsl);
|
||||
resp = await fetchSearchSourceAndRecordWithInspector({
|
||||
rawEsData = await fetchSearchSourceAndRecordWithInspector({
|
||||
searchSource,
|
||||
requestName: `${this._descriptor.indexPatternTitle}.${this._descriptor.term}`,
|
||||
requestId: this._descriptor.id,
|
||||
|
@ -148,15 +148,12 @@ export class ESJoinSource extends AbstractESSource {
|
|||
return configState.type === 'count';
|
||||
});
|
||||
const countPropertyName = _.get(countConfigState, 'id');
|
||||
|
||||
return {
|
||||
rawData: resp,
|
||||
propertiesMap: extractPropertiesMap(resp, metricPropertyNames, countPropertyName),
|
||||
propertiesMap: extractPropertiesMap(rawEsData, metricPropertyNames, countPropertyName),
|
||||
};
|
||||
}
|
||||
|
||||
isFilterByMapBounds() {
|
||||
// TODO
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -248,28 +248,31 @@ export class VectorLayer extends AbstractLayer {
|
|||
try {
|
||||
const canSkip = await this._canSkipSourceUpdate(joinSource, sourceDataId, dataFilters);
|
||||
if (canSkip) {
|
||||
const sourceDataRequest = this._findDataRequestForSource(sourceDataId);
|
||||
const propertiesMap = sourceDataRequest ? sourceDataRequest.getData() : null;
|
||||
return {
|
||||
shouldJoin: false,
|
||||
join: join
|
||||
dataHasChanged: false,
|
||||
join: join,
|
||||
propertiesMap: propertiesMap
|
||||
};
|
||||
}
|
||||
startLoading(sourceDataId, requestToken, dataFilters);
|
||||
const leftSourceName = await this.getSourceName();
|
||||
const {
|
||||
rawData,
|
||||
propertiesMap
|
||||
} = await joinSource.getPropertiesMap(dataFilters, leftSourceName, join.getLeftFieldName());
|
||||
stopLoading(sourceDataId, requestToken, rawData);
|
||||
stopLoading(sourceDataId, requestToken, propertiesMap);
|
||||
return {
|
||||
shouldJoin: true,
|
||||
dataHasChanged: true,
|
||||
join: join,
|
||||
propertiesMap: propertiesMap,
|
||||
};
|
||||
} catch(e) {
|
||||
onLoadError(sourceDataId, requestToken, `Join error: ${e.message}`);
|
||||
return {
|
||||
shouldJoin: false,
|
||||
join: join
|
||||
dataHasChanged: false,
|
||||
join: join,
|
||||
propertiesMap: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -332,13 +335,19 @@ export class VectorLayer extends AbstractLayer {
|
|||
}
|
||||
|
||||
_joinToFeatureCollection(sourceResult, joinState, updateSourceData) {
|
||||
if (!sourceResult.refreshed && !joinState.shouldJoin) {
|
||||
if (!sourceResult.refreshed && !joinState.dataHasChanged) {
|
||||
//no data changes in both the source data or the join data
|
||||
return false;
|
||||
}
|
||||
if (!sourceResult.featureCollection || !joinState.propertiesMap) {
|
||||
//no data available in source or join (ie. request is pending or data errored)
|
||||
return false;
|
||||
}
|
||||
|
||||
//all other cases, perform the join
|
||||
//- source data changed but join data has not
|
||||
//- join data changed but source data has not
|
||||
//- both source and join data changed
|
||||
const updatedFeatureCollection = joinState.join.joinPropertiesToFeatureCollection(
|
||||
sourceResult.featureCollection,
|
||||
joinState.propertiesMap);
|
||||
|
@ -352,7 +361,6 @@ export class VectorLayer extends AbstractLayer {
|
|||
const hasJoined = joinStates.map(joinState => {
|
||||
return this._joinToFeatureCollection(sourceResult, joinState, updateSourceData);
|
||||
});
|
||||
|
||||
return hasJoined.some(shouldRefresh => shouldRefresh === true);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue