diff --git a/src/plugins/comps/CompsMathWorker.js b/src/plugins/comps/CompsMathWorker.js index 125b6648a2..adec37f357 100644 --- a/src/plugins/comps/CompsMathWorker.js +++ b/src/plugins/comps/CompsMathWorker.js @@ -31,7 +31,7 @@ onconnect = function (e) { function getFullDataFrame(telemetryForComps, parameters) { const dataFrame = {}; - Object.keys(telemetryForComps).forEach((key) => { + Object.keys(telemetryForComps)?.forEach((key) => { const parameter = parameters.find((p) => p.keyString === key); const dataSet = telemetryForComps[key]; const telemetryMap = new Map(dataSet.map((item) => [item[parameter.timeKey], item])); @@ -61,7 +61,7 @@ function calculate(dataFrame, parameters, expression) { const otherParameters = parameters.slice(1); // iterate over the reference telemetry data const referenceTelemetry = dataFrame[referenceParameter.keyString]; - referenceTelemetry.forEach((referenceTelemetryItem) => { + referenceTelemetry?.forEach((referenceTelemetryItem) => { const scope = { [referenceParameter.name]: referenceTelemetryItem[referenceParameter.valueToUse] }; diff --git a/src/plugins/comps/CompsTelemetryProvider.js b/src/plugins/comps/CompsTelemetryProvider.js index 56d0154a2f..bf069fd36d 100644 --- a/src/plugins/comps/CompsTelemetryProvider.js +++ b/src/plugins/comps/CompsTelemetryProvider.js @@ -63,7 +63,9 @@ export default class CompsTelemetryProvider { ); specificCompsManager.load(options).then(() => { const callbackID = this.#getCallbackID(); - const telemetryForComps = specificCompsManager.requestUnderlyingTelemetry(); + const telemetryForComps = JSON.parse( + JSON.stringify(specificCompsManager.requestUnderlyingTelemetry()) + ); const expression = specificCompsManager.getExpression(); const parameters = JSON.parse(JSON.stringify(specificCompsManager.getParameters())); if (!expression || !parameters) { @@ -78,6 +80,11 @@ export default class CompsTelemetryProvider { parameters, callbackID }; + console.debug( + `📝 Requesting calculation for ${domainObject.name} with callback ID ${callbackID}:`, + options, + payload + ); this.#sharedWorker.port.postMessage(payload); }); }); @@ -117,12 +124,22 @@ export default class CompsTelemetryProvider { callbackID ); specificCompsManager.on('underlyingTelemetryUpdated', boundComputeOnNewTelemetry); - specificCompsManager.load(); + const telemetryOptions = { + strategy: 'latest', + size: 1 + }; + specificCompsManager.load(telemetryOptions); + console.debug( + `📝 Starting subscription for ${domainObject.name} with callback ID ${callbackID}` + ); return () => { - specificCompsManager.off('underlyingTelemetryUpdated', boundComputeOnNewTelemetry); delete this.#subscriptionCallbacks[callbackID]; - // if this is the last subscription, tell the comp manager to stop listening + console.debug( + `🛑 Stopping subscription for ${domainObject.name} with callback ID ${callbackID}. We now have ${Object.keys(this.#subscriptionCallbacks).length} subscribers`, + this.#subscriptionCallbacks + ); specificCompsManager.stopListeningToUnderlyingTelemetry(); + specificCompsManager.off('underlyingTelemetryUpdated', boundComputeOnNewTelemetry); }; } @@ -157,6 +174,7 @@ export default class CompsTelemetryProvider { console.error('📝 Error calculating request:', event.data); this.#requestPromises[callbackID].resolve([]); } else { + console.debug(`🧮 Calculation request result for ${callbackID}:`, result); this.#requestPromises[callbackID].resolve(result); } delete this.#requestPromises[callbackID]; diff --git a/src/plugins/comps/components/CompsView.vue b/src/plugins/comps/components/CompsView.vue index 58f3009011..ec8f1abeab 100644 --- a/src/plugins/comps/components/CompsView.vue +++ b/src/plugins/comps/components/CompsView.vue @@ -185,11 +185,10 @@ onBeforeMount(async () => { compsManager.on('parameterAdded', reloadParameters); compsManager.on('parameterRemoved', reloadParameters); compsManager.on('outputFormatChanged', updateOutputFormat); - await compsManager.load(); + await outputTelemetryCollection.load(telemetryOptions); // will implicitly load compsManager parameters.value = compsManager.getParameters(); expression.value = compsManager.getExpression(); outputFormat.value = compsManager.getOutputFormat(); - outputTelemetryCollection.load(); applyTestData(); });