Skip to content

Commit 29f7818

Browse files
committed
ManyGet now works in chunks. Fixed bug with async decryption.
1 parent 7873fab commit 29f7818

File tree

1 file changed

+49
-47
lines changed

1 file changed

+49
-47
lines changed

src/main/server/skyRepo.js

+49-47
Original file line numberDiff line numberDiff line change
@@ -206,31 +206,29 @@ const filterResults = async function (o, dontDecryptInSso) {
206206
}
207207
if (EcArray.isArray(o)) {
208208
let me = this;
209-
return (await Promise.all(o.map(x => {
210-
return new Promise((resolve,reject)=>{
211-
try {
212-
resolve(filterResults.call(me, x, dontDecryptInSso));
213-
} catch (ex) {
214-
if (ex != null && ex.toString().indexOf('Object not found or you did not supply sufficient permissions to access the object.') == -1) {
215-
reject(ex);
216-
}
217-
resolve(null);
209+
return (await Promise.all(o.map(async (x) => {
210+
try {
211+
return await filterResults.call(me, x, dontDecryptInSso);
212+
} catch (ex) {
213+
if (ex != null && ex.toString().indexOf('Object not found or you did not supply sufficient permissions to access the object.') == -1) {
214+
throw ex;
218215
}
219-
});
220-
}))).filter(x => x);
216+
return null;
217+
}
218+
}))).filter((x) => x);
221219
} else if (EcObject.isObject(o)) {
222220
delete o.decryptedSecret;
223221
const rld = new EcRemoteLinkedData((o)['@context'], (o)['@type']);
224222
rld.copyFrom(o);
225223
if ((rld.reader != null && rld.reader.length != 0) || isEncryptedType(rld)) {
226224
const signatures = await (signatureSheet).call(this);
227225
let foundSignature = false;
228-
for (let i = 0; i < signatures.length; i++) {
229-
if (JSON.stringify(o).indexOf(signatures[i].owner) != -1) {
226+
for (let signature of signatures) {
227+
if (JSON.stringify(o).indexOf(signature.owner) != -1) {
230228
foundSignature = true;
231229
break;
232230
}
233-
if (EcPk.fromPem(skyrepoAdminPk()).equals(EcPk.fromPem(signatures[i].owner))) {
231+
if (EcPk.fromPem(skyrepoAdminPk()).equals(EcPk.fromPem(signature.owner))) {
234232
foundSignature = true;
235233
break;
236234
}
@@ -252,10 +250,9 @@ const filterResults = async function (o, dontDecryptInSso) {
252250
}
253251
}
254252
const keys = EcObject.keys(o);
255-
for (let i = 0; i < keys.length; i++) {
256-
const key = keys[i];
253+
for (let key of keys) {
257254
let result = null;
258-
try{
255+
try {
259256
result = await (filterResults).call(this, (o)[key], dontDecryptInSso);
260257
} catch (ex) {
261258
if (ex != null && ex.toString().indexOf('Object not found or you did not supply sufficient permissions to access the object.') == -1) {
@@ -8451,7 +8448,7 @@ const getTypeForObject = function (o, type) {
84518448
return inferTypeFromObj(o, type);
84528449
}
84538450
};
8454-
const removeNonIndexables = function(o) {
8451+
const removeNonIndexables = function (o) {
84558452
if (o != null && EcObject.isObject(o)) {
84568453
const keys = EcObject.keys(o);
84578454
for (let i = 0; i < keys.length; i++) {
@@ -8913,34 +8910,40 @@ const skyrepoGetIndexSearch = async function (id, version, type) {
89138910
};
89148911

89158912
const skyrepoManyGetIndexSearch = async function (ary) {
8916-
if (ary.length === 0) {
8917-
return [];
8918-
}
8919-
let microSearchUrl = elasticEndpoint + '/_search?version&q=';
8920-
for (let i = 0; i < ary.length; i++) {
8921-
microSearchUrl += '_id:"' + ary[i].id + '"';
8922-
if (i < ary.length - 1) {
8923-
microSearchUrl += ' OR ';
8913+
let results = [];
8914+
if (ary.length == 0) {
8915+
return results;
8916+
}
8917+
while (ary.length > 0) {
8918+
let batch = ary.splice(0, 50);
8919+
let microSearchUrl = elasticEndpoint + '/_search?version&q=';
8920+
for (let i = 0; i < batch.length; i++) {
8921+
microSearchUrl += '_id:"' + batch[i].id + '"';
8922+
if (i < batch.length - 1) {
8923+
microSearchUrl += ' OR ';
8924+
}
89248925
}
8925-
}
89268926

8927-
const microSearch = await httpGet(microSearchUrl, true, elasticHeaders());
8927+
const microSearch = await httpGet(microSearchUrl, true, elasticHeaders());
89288928

8929-
if (global.skyrepoDebug) {
8930-
global.auditLogger.report(global.auditLogger.LogCategory.NETWORK, global.auditLogger.Severity.DEBUG, 'SkyrepManyGetIndexSearch', microSearchUrl);
8931-
}
8932-
if (microSearch == null) {
8933-
return [];
8934-
}
8935-
const hitshits = (microSearch)['hits'];
8936-
if (hitshits == null) {
8937-
return [];
8938-
}
8939-
const hits = (hitshits)['hits'];
8940-
if (hits.length == 0) {
8941-
return [];
8929+
if (global.skyrepoDebug) {
8930+
global.auditLogger.report(global.auditLogger.LogCategory.NETWORK, global.auditLogger.Severity.DEBUG, 'SkyrepManyGetIndexSearch', microSearchUrl);
8931+
}
8932+
if (microSearch == null) {
8933+
return [];
8934+
}
8935+
const hitshits = (microSearch)['hits'];
8936+
if (hitshits == null) {
8937+
return [];
8938+
}
8939+
const hits = (hitshits)['hits'];
8940+
if (hits.length == 0) {
8941+
return [];
8942+
}
8943+
for (let hit of hits)
8944+
results.push(hit);
89428945
}
8943-
return hits;
8946+
return results;
89448947
};
89458948

89468949
let skyrepoGetIndexRecords = async function (id) {
@@ -9132,14 +9135,13 @@ global.skyrepoManyGetInternal = async function (manyParseParams) {
91329135
}
91339136

91349137
if (global.skyrepoDebug && notFoundInPermanent.length > 0) {
9135-
global.auditLogger.report(global.auditLogger.LogCategory.NETWORK, global.auditLogger.Severity.DEBUG, 'SkyrepManyGetInternal', 'Failed to find ' + manyParseParams + ' -- trying degraded form from search index.');
9138+
global.auditLogger.report(global.auditLogger.LogCategory.NETWORK, global.auditLogger.Severity.DEBUG, 'SkyrepManyGetInternal', 'Failed to find ' + notFoundInPermanent + ' -- trying degraded form from search index.');
91369139
}
91379140

91389141
response = await (skyrepoManyGetIndex).call(this, notFoundInPermanent);
9139-
resultDocs = (response)['docs'];
9140-
if (resultDocs != null) {
9141-
for (let i = 0; i < resultDocs.length; i++) {
9142-
let doc = resultDocs[i];
9142+
let resultDocs2 = (response)['docs'];
9143+
if (resultDocs2 != null) {
9144+
for (let doc of resultDocs2) {
91439145
if ((doc)['found']) {
91449146
delete (lookup)[((doc)['_id']).substring(0, ((doc)['_id']).length - 1)];
91459147
results.push(JSON.parse(((doc)['_source'])['data']));

0 commit comments

Comments
 (0)