Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Conditionals] Increase performance, switch to TelemetryCollections #7841

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
70 changes: 31 additions & 39 deletions src/plugins/condition/ConditionManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class ConditionManager extends EventEmitter {
this.shouldEvaluateNewTelemetry = this.shouldEvaluateNewTelemetry.bind(this);

this.compositionLoad = this.composition.load();
this.subscriptions = {};
this.telemetryCollections = {};
jvigliotta marked this conversation as resolved.
Show resolved Hide resolved
this.telemetryObjects = {};
this.testData = {
conditionTestInputs: this.conditionSetDomainObject.configuration.conditionTestData,
Expand All @@ -48,55 +48,44 @@ export default class ConditionManager extends EventEmitter {
this.initialize();
}

async requestLatestValue(endpoint) {
const options = {
size: 1,
strategy: 'latest'
};
const latestData = await this.openmct.telemetry.request(endpoint, options);
subscribeToTelemetry(telemetryObject) {
const keyString = this.openmct.objects.makeKeyString(telemetryObject.identifier);

if (!latestData) {
throw new Error('Telemetry request failed by returning a falsy response');
}
if (latestData.length === 0) {
if (this.telemetryCollections[keyString]) {
return;
}
this.telemetryReceived(endpoint, latestData[0]);
}

subscribeToTelemetry(endpoint) {
const telemetryKeyString = this.openmct.objects.makeKeyString(endpoint.identifier);
if (this.subscriptions[telemetryKeyString]) {
return;
}
const requestOptions = {
size: 1,
strategy: 'latest'
};

const metadata = this.openmct.telemetry.getMetadata(endpoint);
this.telemetryCollections[keyString] = this.openmct.telemetry.requestCollection(
telemetryObject,
requestOptions
);

this.telemetryObjects[telemetryKeyString] = Object.assign({}, endpoint, {
telemetryMetaData: metadata ? metadata.valueMetadatas : []
});
const metadata = this.openmct.telemetry.getMetadata(telemetryObject);
const telemetryMetaData = metadata ? metadata.valueMetadatas : [];
const telemetryProcessor = this.telemetryReceived.bind(this, telemetryObject);

// get latest telemetry value (in case subscription is cached and no new data is coming in)
this.requestLatestValue(endpoint);
this.telemetryObjects[keyString] = Object.assign({}, telemetryObject, { telemetryMetaData });
jvigliotta marked this conversation as resolved.
Show resolved Hide resolved

this.telemetryCollections[keyString].on('add', telemetryProcessor);
jvigliotta marked this conversation as resolved.
Show resolved Hide resolved
this.telemetryCollections[keyString].load();

this.subscriptions[telemetryKeyString] = this.openmct.telemetry.subscribe(
endpoint,
this.telemetryReceived.bind(this, endpoint)
);
this.updateConditionTelemetryObjects();
}

unsubscribeFromTelemetry(endpointIdentifier) {
const id = this.openmct.objects.makeKeyString(endpointIdentifier);
if (!this.subscriptions[id]) {
console.log('no subscription to remove');

const keyString = this.openmct.objects.makeKeyString(endpointIdentifier);
if (!this.telemetryCollections[keyString]) {
return;
}

this.subscriptions[id]();
delete this.subscriptions[id];
delete this.telemetryObjects[id];
this.telemetryCollections[keyString].destroy();
delete this.telemetryCollections[keyString];
delete this.telemetryObjects[keyString];
jvigliotta marked this conversation as resolved.
Show resolved Hide resolved
this.removeConditionTelemetryObjects();

//force re-computation of condition set result as we might be in a state where
Expand All @@ -107,7 +96,7 @@ export default class ConditionManager extends EventEmitter {
this.timeSystems,
this.openmct.time.getTimeSystem()
);
this.updateConditionResults({ id: id });
this.updateConditionResults({ id: keyString });
jvigliotta marked this conversation as resolved.
Show resolved Hide resolved
this.updateCurrentCondition(latestTimestamp);

if (Object.keys(this.telemetryObjects).length === 0) {
Expand Down Expand Up @@ -410,11 +399,13 @@ export default class ConditionManager extends EventEmitter {
return this.openmct.time.getBounds().end >= currentTimestamp;
}

telemetryReceived(endpoint, datum) {
telemetryReceived(endpoint, data) {
if (!this.isTelemetryUsed(endpoint)) {
return;
}

const datum = data[0];
ozyx marked this conversation as resolved.
Show resolved Hide resolved

const normalizedDatum = this.createNormalizedDatum(datum, endpoint);
const timeSystemKey = this.openmct.time.getTimeSystem().key;
let timestamp = {};
Expand Down Expand Up @@ -507,8 +498,9 @@ export default class ConditionManager extends EventEmitter {
destroy() {
this.composition.off('add', this.subscribeToTelemetry, this);
this.composition.off('remove', this.unsubscribeFromTelemetry, this);
Object.values(this.subscriptions).forEach((unsubscribe) => unsubscribe());
delete this.subscriptions;
Object.values(this.telemetryCollections).forEach((telemetryCollection) =>
telemetryCollection.destroy()
);

this.conditions.forEach((condition) => {
condition.destroy();
Expand Down
45 changes: 20 additions & 25 deletions src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,36 +128,31 @@
}
},
updateStyle(styleObj) {
let elemToStyle = this.getStyleReceiver();
const elemToStyle = this.getStyleReceiver();

Check warning on line 131 in src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js#L131

Added line #L131 was not covered by tests

if (!styleObj || elemToStyle === undefined) {
if (!styleObj || !elemToStyle) {

Check warning on line 133 in src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js#L133

Added line #L133 was not covered by tests
jvigliotta marked this conversation as resolved.
Show resolved Hide resolved
return;
}

let keys = Object.keys(styleObj);

keys.forEach((key) => {
if (elemToStyle) {
if (typeof styleObj[key] === 'string' && styleObj[key].indexOf('__no_value') > -1) {
if (elemToStyle.style[key]) {
elemToStyle.style[key] = '';
}
} else {
if (
!styleObj.isStyleInvisible &&
elemToStyle.classList.contains(STYLE_CONSTANTS.isStyleInvisible)
) {
elemToStyle.classList.remove(STYLE_CONSTANTS.isStyleInvisible);
} else if (
styleObj.isStyleInvisible &&
!elemToStyle.classList.contains(styleObj.isStyleInvisible)
) {
elemToStyle.classList.add(styleObj.isStyleInvisible);
}

elemToStyle.style[key] = styleObj[key];
// handle visibility separately
if (styleObj.isStyleInvisible !== undefined) {
elemToStyle.classList.toggle(STYLE_CONSTANTS.isStyleInvisible, styleObj.isStyleInvisible);
jvigliotta marked this conversation as resolved.
Show resolved Hide resolved
delete styleObj.isStyleInvisible;

Check warning on line 140 in src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js#L138-L140

Added lines #L138 - L140 were not covered by tests
jvigliotta marked this conversation as resolved.
Show resolved Hide resolved
}

// build style string
const styleString = Object.entries(styleObj)

Check warning on line 144 in src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js#L144

Added line #L144 was not covered by tests
.map(([key, value]) => {
if (typeof value === 'string' && value.includes('__no_value')) {
return `${key}: ;`; // removes the property

Check warning on line 147 in src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js#L146-L147

Added lines #L146 - L147 were not covered by tests
}
}
return `${key}: ${value};`;

Check warning on line 149 in src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js#L149

Added line #L149 was not covered by tests
})
.join(' ');

// apply styles in one operation
requestAnimationFrame(() => {
elemToStyle.style.cssText += styleString;

Check warning on line 155 in src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js

View check run for this annotation

Codecov / codecov/patch

src/plugins/plot/stackedPlot/mixins/objectStyles-mixin.js#L154-L155

Added lines #L154 - L155 were not covered by tests
});
}
}
jvigliotta marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Loading