Compare commits

...

6 Commits

Author SHA1 Message Date
4ff96ff091 Don't delete cache entry 2021-03-13 17:26:02 -08:00
ad87dd6fdc Only batch if > 1 2021-03-13 17:20:23 -08:00
80c833db88 Batch requests 2021-03-13 13:32:02 -08:00
a756891ccd Promises, not await 2021-03-13 11:57:12 -08:00
2e1b6c5190 Implemented search in couch provider 2021-03-13 10:30:55 -08:00
b042d9098d doing correct comparison to find page to delete (#3754) 2021-03-12 15:49:58 -08:00
5 changed files with 87 additions and 18 deletions

View File

@ -180,7 +180,7 @@ ObjectAPI.prototype.get = function (identifier, abortSignal) {
this.cache[keystring] = objectPromise; this.cache[keystring] = objectPromise;
return objectPromise.then(result => { return objectPromise.then(result => {
delete this.cache[keystring]; //delete this.cache[keystring];
result = this.applyGetInterceptors(identifier, result); result = this.applyGetInterceptors(identifier, result);
return result; return result;

View File

@ -69,7 +69,7 @@ export default {
methods: { methods: {
deletePage(id) { deletePage(id) {
const selectedSection = this.sections.find(s => s.isSelected); const selectedSection = this.sections.find(s => s.isSelected);
const page = this.pages.find(p => p.id !== id); const page = this.pages.find(p => p.id === id);
deleteNotebookEntries(this.openmct, this.domainObject, selectedSection, page); deleteNotebookEntries(this.openmct, this.domainObject, selectedSection, page);
const selectedPage = this.pages.find(p => p.isSelected); const selectedPage = this.pages.find(p => p.isSelected);

View File

@ -26,6 +26,7 @@ import CouchObjectQueue from "./CouchObjectQueue";
const REV = "_rev"; const REV = "_rev";
const ID = "_id"; const ID = "_id";
const HEARTBEAT = 50000; const HEARTBEAT = 50000;
const ALL_DOCS = "_all_docs?include_docs=true";
export default class CouchObjectProvider { export default class CouchObjectProvider {
// options { // options {
@ -67,6 +68,9 @@ export default class CouchObjectProvider {
// stringify body if needed // stringify body if needed
if (fetchOptions.body) { if (fetchOptions.body) {
fetchOptions.body = JSON.stringify(fetchOptions.body); fetchOptions.body = JSON.stringify(fetchOptions.body);
fetchOptions.headers = {
"Content-Type": "application/json"
};
} }
return fetch(this.url + '/' + subPath, fetchOptions) return fetch(this.url + '/' + subPath, fetchOptions)
@ -131,10 +135,70 @@ export default class CouchObjectProvider {
} }
get(identifier, abortSignal) { get(identifier, abortSignal) {
return this.request(identifier.key, "GET", undefined, abortSignal).then(this.getModel.bind(this)); return new Promise((resolve, reject) => {
this.batchIds = this.batchIds || [];
this.batchIds.push(identifier.key);
if (this.bulkPromise === undefined) {
this.bulkPromise = new Promise((bulkResolve, bulkReject) => {
setTimeout(() => {
let batchIds = this.batchIds;
delete this.batchIds;
delete this.bulkPromise;
if (batchIds.length === 1) {
this.request(identifier.key, "GET", undefined, abortSignal)
.then((result) => resolve(this.getModel(result)));
} else {
this.bulkGet(batchIds, abortSignal)
.then(bulkResolve)
.catch(bulkReject);
}
});
});
}
this.bulkPromise
.then((domainObjectMap) => {
resolve(domainObjectMap[identifier.key]);
})
.catch(error => reject(error));
});
} }
async getObjectsByFilter(filter) { bulkGet(ids, signal) {
//Remove dupes
ids = Array.from(new Set(ids));
const query = {
'keys': ids
};
return this.request(ALL_DOCS, 'POST', query, signal).then((response) => {
return response.rows.reduce((map, row) => {
if (row.doc !== undefined) {
map[row.key] = this.getModel(row.doc);
}
return map;
}, {});
});
}
search(query, abortSignal) {
const filter = {
"selector": {
"model": {
"name": {
"$regex": `(?i)${query}`
}
}
}
};
return this.getObjectsByFilter(filter, abortSignal);
}
async getObjectsByFilter(filter, abortSignal) {
let objects = []; let objects = [];
let url = `${this.url}/_find`; let url = `${this.url}/_find`;
@ -149,6 +213,7 @@ export default class CouchObjectProvider {
headers: { headers: {
"Content-Type": "application/json" "Content-Type": "application/json"
}, },
signal: abortSignal,
body body
}); });

View File

@ -143,5 +143,9 @@ describe('the plugin', () => {
expect(couchProvider.updateQueued).toHaveBeenCalledTimes(2); expect(couchProvider.updateQueued).toHaveBeenCalledTimes(2);
}); });
describe('batches object requests', () => {
//NEED TO MAKE SURE THERE ARE NO RACE CONDITIONS WHERE REQUESTS FOR OBJECTS ARE DROPPED
});
}); });
}); });

View File

@ -710,25 +710,25 @@ export default {
} }
}); });
}, },
async aggregateSearchResults(results, abortSignal) { aggregateSearchResults(results, abortSignal) {
for (const result of results) { for (const result of results) {
if (!abortSignal.aborted) { if (!abortSignal.aborted) {
const objectPath = await this.openmct.objects.getOriginalPath(result.identifier); this.openmct.objects.getOriginalPath(result.identifier).then((objectPath) => {
// removing the item itself, as the path we pass to buildTreeItem is a parent path
objectPath.shift();
// removing the item itself, as the path we pass to buildTreeItem is a parent path // if root, remove, we're not using in object path for tree
objectPath.shift(); let lastObject = objectPath.length ? objectPath[objectPath.length - 1] : false;
if (lastObject && lastObject.type === 'root') {
objectPath.pop();
}
// if root, remove, we're not using in object path for tree // we reverse the objectPath in the tree, so have to do it here first,
let lastObject = objectPath.length ? objectPath[objectPath.length - 1] : false; // since this one is already in the correct direction
if (lastObject && lastObject.type === 'root') { let resultObject = this.buildTreeItem(result, objectPath.reverse());
objectPath.pop();
}
// we reverse the objectPath in the tree, so have to do it here first, this.searchResultItems.push(resultObject);
// since this one is already in the correct direction });
let resultObject = this.buildTreeItem(result, objectPath.reverse());
this.searchResultItems.push(resultObject);
} }
} }
}, },