Handled chunked response from CouchDB for search results (#3701)

This commit is contained in:
Shefali Joshi 2021-02-24 15:59:41 -08:00 committed by GitHub
parent 169eec0a51
commit 15778b00a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -145,7 +145,8 @@ export default class CouchObjectProvider {
const reader = response.body.getReader();
let completed = false;
let decoder = new TextDecoder("utf-8");
let decodedChunk = '';
while (!completed) {
const {done, value} = await reader.read();
//done is true when we lose connection with the provider
@ -156,7 +157,11 @@ export default class CouchObjectProvider {
if (value) {
let chunk = new Uint8Array(value.length);
chunk.set(value, 0);
const decodedChunk = new TextDecoder("utf-8").decode(chunk);
const partial = decoder.decode(chunk, {stream: !completed});
decodedChunk = decodedChunk + partial;
}
}
try {
const json = JSON.parse(decodedChunk);
if (json) {
@ -171,9 +176,6 @@ export default class CouchObjectProvider {
} catch (e) {
//do nothing
}
}
}
return objects;
}