diff --git a/src/plugins/persistence/couch/CouchObjectProvider.js b/src/plugins/persistence/couch/CouchObjectProvider.js index 2507801532..e7ab40025c 100644 --- a/src/plugins/persistence/couch/CouchObjectProvider.js +++ b/src/plugins/persistence/couch/CouchObjectProvider.js @@ -298,18 +298,12 @@ class CouchObjectProvider { return Array.from(new Set(array)); } - search(query, abortSignal) { - const filter = { - "selector": { - "model": { - "name": { - "$regex": `(?i)${query}` - } - } - } - }; - - return this.getObjectsByFilter(filter, abortSignal); + search() { + // Dummy search function. It has to appear to support search, + // otherwise the in-memory indexer will index all of its objects, + // but actually search results will be provided by a separate search provider + // see CoucheSearchProvider.js + return Promise.resolve([]); } async getObjectsByFilter(filter, abortSignal) { diff --git a/src/plugins/persistence/couch/CouchSearchProvider.js b/src/plugins/persistence/couch/CouchSearchProvider.js new file mode 100644 index 0000000000..7ef264d5e8 --- /dev/null +++ b/src/plugins/persistence/couch/CouchSearchProvider.js @@ -0,0 +1,49 @@ +/***************************************************************************** + * Open MCT, Copyright (c) 2014-2021, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ + +// This provider exists because due to legacy reasons, we need to install +// two plugins for two namespaces for CouchDB: one for "mct", and one for "". +// Because of this, we need to separate out the search provider from the object +// provider so we don't return two results for each found object. +// If the above namespace is ever resolved, we can fold this search provider +// back into the object provider. + +class CouchSearchProvider { + constructor(couchObjectProvider) { + this.couchObjectProvider = couchObjectProvider; + } + + search(query, abortSignal) { + const filter = { + "selector": { + "model": { + "name": { + "$regex": `(?i)${query}` + } + } + } + }; + + return this.couchObjectProvider.getObjectsByFilter(filter, abortSignal); + } +} +export default CouchSearchProvider; diff --git a/src/plugins/persistence/couch/plugin.js b/src/plugins/persistence/couch/plugin.js index 4652069348..5796b96956 100644 --- a/src/plugins/persistence/couch/plugin.js +++ b/src/plugins/persistence/couch/plugin.js @@ -21,8 +21,10 @@ *****************************************************************************/ import CouchObjectProvider from './CouchObjectProvider'; +import CouchSearchProvider from './CouchSearchProvider'; const NAMESPACE = ''; const LEGACY_SPACE = 'mct'; +const COUCH_SEARCH_ONLY_NAMESPACE = `COUCH_SEARCH_${Date.now()}`; export default function CouchPlugin(options) { return function install(openmct) { @@ -32,5 +34,6 @@ export default function CouchPlugin(options) { // Installing the same provider under both namespaces means that it can respond to object gets for both namespaces. openmct.objects.addProvider(LEGACY_SPACE, install.couchProvider); openmct.objects.addProvider(NAMESPACE, install.couchProvider); + openmct.objects.addProvider(COUCH_SEARCH_ONLY_NAMESPACE, new CouchSearchProvider(install.couchProvider)); }; } diff --git a/src/plugins/persistence/couch/pluginSpec.js b/src/plugins/persistence/couch/pluginSpec.js index b4011f5360..3db7d7d136 100644 --- a/src/plugins/persistence/couch/pluginSpec.js +++ b/src/plugins/persistence/couch/pluginSpec.js @@ -262,7 +262,9 @@ describe('the plugin', () => { await Promise.all(openmct.objects.search('test')); const requestUrl = fetch.calls.mostRecent().args[0]; - expect(fetch).toHaveBeenCalled(); + // we only want one call to fetch, not 2! + // see https://github.com/nasa/openmct/issues/4667 + expect(fetch).toHaveBeenCalledTimes(1); expect(requestUrl.endsWith('_find')).toBeTrue(); });