mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 06:38:17 +00:00
When searching, build the path objects asynchronously while returning the results (#7265)
* build paths as fast as we can * fix tests * add abort controllers and async load tags
This commit is contained in:
@ -366,15 +366,19 @@ export default class AnnotationAPI extends EventEmitter {
|
||||
return tagsAddedToResults;
|
||||
}
|
||||
|
||||
async #addTargetModelsToResults(results) {
|
||||
async #addTargetModelsToResults(results, abortSignal) {
|
||||
const modelAddedToResults = await Promise.all(
|
||||
results.map(async (result) => {
|
||||
const targetModels = await Promise.all(
|
||||
result.targets.map(async (target) => {
|
||||
const targetID = target.keyString;
|
||||
const targetModel = await this.openmct.objects.get(targetID);
|
||||
const targetModel = await this.openmct.objects.get(targetID, abortSignal);
|
||||
const targetKeyString = this.openmct.objects.makeKeyString(targetModel.identifier);
|
||||
const originalPathObjects = await this.openmct.objects.getOriginalPath(targetKeyString);
|
||||
const originalPathObjects = await this.openmct.objects.getOriginalPath(
|
||||
targetKeyString,
|
||||
[],
|
||||
abortSignal
|
||||
);
|
||||
|
||||
return {
|
||||
originalPath: originalPathObjects,
|
||||
@ -442,7 +446,7 @@ export default class AnnotationAPI extends EventEmitter {
|
||||
* @param {Object} [abortController] An optional abort method to stop the query
|
||||
* @returns {Promise} returns a model of matching tags with their target domain objects attached
|
||||
*/
|
||||
async searchForTags(query, abortController) {
|
||||
async searchForTags(query, abortSignal) {
|
||||
const matchingTagKeys = this.#getMatchingTags(query);
|
||||
if (!matchingTagKeys.length) {
|
||||
return [];
|
||||
@ -452,7 +456,7 @@ export default class AnnotationAPI extends EventEmitter {
|
||||
await Promise.all(
|
||||
this.openmct.objects.search(
|
||||
matchingTagKeys,
|
||||
abortController,
|
||||
abortSignal,
|
||||
this.openmct.objects.SEARCH_TYPES.TAGS
|
||||
)
|
||||
)
|
||||
@ -465,7 +469,10 @@ export default class AnnotationAPI extends EventEmitter {
|
||||
combinedSameTargets,
|
||||
matchingTagKeys
|
||||
);
|
||||
const appliedTargetsModels = await this.#addTargetModelsToResults(appliedTagSearchResults);
|
||||
const appliedTargetsModels = await this.#addTargetModelsToResults(
|
||||
appliedTagSearchResults,
|
||||
abortSignal
|
||||
);
|
||||
const resultsWithValidPath = appliedTargetsModels.filter((result) => {
|
||||
return this.openmct.objects.isReachable(result.targetModels?.[0]?.originalPath);
|
||||
});
|
||||
|
@ -786,16 +786,17 @@ export default class ObjectAPI {
|
||||
* Given an identifier, constructs the original path by walking up its parents
|
||||
* @param {module:openmct.ObjectAPI~Identifier} identifier
|
||||
* @param {Array<module:openmct.DomainObject>} path an array of path objects
|
||||
* @param {AbortSignal} abortSignal (optional) signal to abort fetch requests
|
||||
* @returns {Promise<Array<module:openmct.DomainObject>>} a promise containing an array of domain objects
|
||||
*/
|
||||
async getOriginalPath(identifier, path = []) {
|
||||
const domainObject = await this.get(identifier);
|
||||
async getOriginalPath(identifier, path = [], abortSignal = null) {
|
||||
const domainObject = await this.get(identifier, abortSignal);
|
||||
path.push(domainObject);
|
||||
const { location } = domainObject;
|
||||
if (location && !this.#pathContainsDomainObject(location, path)) {
|
||||
// if we have a location, and we don't already have this in our constructed path,
|
||||
// then keep walking up the path
|
||||
return this.getOriginalPath(utils.parseKeyString(location), path);
|
||||
return this.getOriginalPath(utils.parseKeyString(location), path, abortSignal);
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
|
Reference in New Issue
Block a user