improvement in loading

This commit is contained in:
Scott Bell 2024-10-03 14:09:47 +02:00
parent 1a9401039e
commit 8e5ac68360
3 changed files with 25 additions and 8 deletions

View File

@ -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]
};

View File

@ -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];

View File

@ -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();
});