Fix couchdb no response (#5474)

* Update the creation date only when the document is created for the first time

* If there is no response from a bulk get, couch db has issues

* Check the response - if it's null, don't apply interceptors
This commit is contained in:
Shefali Joshi 2022-07-10 10:50:23 -07:00 committed by GitHub
parent e9c0909415
commit 0af7965021
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -233,7 +233,11 @@ export default class ObjectAPI {
delete this.cache[keystring];
result = this.applyGetInterceptors(identifier);
if (!result) {
//no result means resource either doesn't exist or is missing
//otherwise it's an error, and we shouldn't apply interceptors
result = this.applyGetInterceptors(identifier);
}
return result;
});

View File

@ -45,8 +45,7 @@ export default function CouchDocument(id, model, rev, markDeleted) {
"category": "domain object",
"type": model.type,
"owner": "admin",
"name": model.name,
"created": Date.now()
"name": model.name
},
"model": model
};

View File

@ -215,6 +215,8 @@ class CouchObjectProvider {
// Network error, CouchDB unreachable.
if (response === null) {
this.indicator.setIndicatorToState(DISCONNECTED);
console.error(error.message);
throw new Error(`CouchDB Error - No response"`);
}
console.error(error.message);
@ -379,6 +381,8 @@ class CouchObjectProvider {
return this.request(ALL_DOCS, 'POST', query, signal).then((response) => {
if (response && response.rows !== undefined) {
return response.rows.reduce((map, row) => {
//row.doc === null if the document does not exist.
//row.doc === undefined if the document is not found.
if (row.doc !== undefined) {
map[row.key] = this.#getModel(row.doc);
}
@ -647,6 +651,7 @@ class CouchObjectProvider {
this.objectQueue[key].pending = true;
const queued = this.objectQueue[key].dequeue();
let document = new CouchDocument(key, queued.model);
document.metadata.created = Date.now();
this.request(key, "PUT", document).then((response) => {
console.log('create check response', key);
this.#checkResponse(response, queued.intermediateResponse, key);