From 4a301a15d2b6c8abe552ce46ecbb0d770d26465d Mon Sep 17 00:00:00 2001 From: Scott Bell Date: Wed, 25 Sep 2024 13:19:00 +0200 Subject: [PATCH] ensure derived DERIVED telemetry loads in the proper order. also have telemetry collections prioritize request options over clock --- src/api/telemetry/TelemetryCollection.js | 12 +++++++-- src/plugins/comps/CompsManager.js | 27 +++++++++++++-------- src/plugins/comps/CompsTelemetryProvider.js | 2 +- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/api/telemetry/TelemetryCollection.js b/src/api/telemetry/TelemetryCollection.js index 2e736a1d6a..8ccae3210f 100644 --- a/src/api/telemetry/TelemetryCollection.js +++ b/src/api/telemetry/TelemetryCollection.js @@ -216,12 +216,20 @@ export default class TelemetryCollection extends EventEmitter { let hasDataBeforeStartBound = false; let size = this.options.size; let enforceSize = size !== undefined && this.options.enforceSize; + // prioritize request bounds over time context bounds + let boundsToUse = this.lastBounds; + if (this.options.start) { + boundsToUse.start = this.options.start; + } + if (this.options.end) { + boundsToUse.end = this.options.end; + } // loop through, sort and dedupe for (let datum of data) { parsedValue = this.parseTime(datum); - beforeStartOfBounds = parsedValue < this.lastBounds.start; - afterEndOfBounds = parsedValue > this.lastBounds.end; + beforeStartOfBounds = parsedValue < boundsToUse.start; + afterEndOfBounds = parsedValue > boundsToUse.end; if ( !afterEndOfBounds && diff --git a/src/plugins/comps/CompsManager.js b/src/plugins/comps/CompsManager.js index e049aeb286..e151c604e8 100644 --- a/src/plugins/comps/CompsManager.js +++ b/src/plugins/comps/CompsManager.js @@ -1,4 +1,5 @@ import { EventEmitter } from 'eventemitter3'; +import _ from 'lodash'; export default class CompsManager extends EventEmitter { #openmct; @@ -112,20 +113,23 @@ export default class CompsManager extends EventEmitter { } async load(telemetryOptions) { + // if our options change, we need to reload the composition + if (!_.isEqual(telemetryOptions, this.#telemetryOptions) && this.#loaded) { + this.#destroy(); + } + this.#telemetryOptions = telemetryOptions; if (!this.#compositionLoaded) { - this.#telemetryOptions = telemetryOptions; await this.#loadComposition(); this.#compositionLoaded = true; } if (!this.#loaded) { - await Promise.all(this.#telemetryLoadedPromises); + await this.startListeningToUnderlyingTelemetry(); this.#telemetryLoadedPromises = []; this.#loaded = true; } } async startListeningToUnderlyingTelemetry() { - this.#loaded = false; Object.keys(this.#telemetryCollections).forEach((keyString) => { if (!this.#telemetryCollections[keyString].loaded) { this.#telemetryCollections[keyString].on('add', this.#getTelemetryProcessor(keyString)); @@ -136,7 +140,15 @@ export default class CompsManager extends EventEmitter { }); await Promise.all(this.#telemetryLoadedPromises); this.#telemetryLoadedPromises = []; - this.#loaded = true; + } + + #destroy() { + this.stopListeningToUnderlyingTelemetry(); + this.#composition = null; + this.#telemetryCollections = {}; + this.#compositionLoaded = false; + this.#loaded = false; + this.#telemetryObjects = {}; } stopListeningToUnderlyingTelemetry() { @@ -208,7 +220,7 @@ export default class CompsManager extends EventEmitter { this.deleteParameter(keyString); }; - requestUnderlyingTelemetry(options) { + requestUnderlyingTelemetry() { const underlyingTelemetry = {}; Object.keys(this.#telemetryCollections).forEach((collectionKey) => { const collection = this.#telemetryCollections[collectionKey]; @@ -259,11 +271,6 @@ export default class CompsManager extends EventEmitter { this.#telemetryOptions ); - this.#telemetryCollections[keyString].on('add', this.#getTelemetryProcessor(keyString)); - this.#telemetryCollections[keyString].on('clear', this.clearData); - const telemetryLoadedPromise = this.#telemetryCollections[keyString].load(); - this.#telemetryLoadedPromises.push(telemetryLoadedPromise); - // check to see if we have a corresponding parameter // if not, add one const parameterExists = this.#domainObject.configuration.comps.parameters.some( diff --git a/src/plugins/comps/CompsTelemetryProvider.js b/src/plugins/comps/CompsTelemetryProvider.js index c1eb983624..56d0154a2f 100644 --- a/src/plugins/comps/CompsTelemetryProvider.js +++ b/src/plugins/comps/CompsTelemetryProvider.js @@ -117,7 +117,7 @@ export default class CompsTelemetryProvider { callbackID ); specificCompsManager.on('underlyingTelemetryUpdated', boundComputeOnNewTelemetry); - specificCompsManager.startListeningToUnderlyingTelemetry(); + specificCompsManager.load(); return () => { specificCompsManager.off('underlyingTelemetryUpdated', boundComputeOnNewTelemetry); delete this.#subscriptionCallbacks[callbackID];