Skip to content

Commit 9bbb1b1

Browse files
authored
feat: resolve data subjects in parallel (#127)
supersedes #117
1 parent 57b9832 commit 9bbb1b1

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

lib/utils.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,29 @@ const addDataSubjectForDetailsEntity = (row, log, req, entity, model) => {
239239
else map.set(role, _getDataSubjectIdQuery(dataSubjectInfo, row, model))
240240
}
241241

242-
const resolveDataSubjects = async (logs, req) => {
242+
const resolveDataSubjects = (logs, req) => {
243+
const ps = []
244+
243245
const map = _getDataSubjectsMap(req)
246+
244247
for (const each of Object.values(logs)) {
245248
if (each.data_subject.id instanceof cds.ql.Query) {
246249
const q = each.data_subject.id
247-
if (map.has(q)) {
248-
each.data_subject.id = map.get(q)
249-
} else {
250-
const res = await q
251-
map.set(q, res)
252-
each.data_subject.id = res
250+
if (!map.has(q)) {
251+
const p = cds.run(q).then(res => map.set(q, res))
252+
map.set(q, p)
253+
ps.push(p)
253254
}
254255
}
255256
}
257+
258+
return Promise.all(ps).then(() => {
259+
for (const each of Object.values(logs)) {
260+
if (each.data_subject.id instanceof cds.ql.Query) {
261+
each.data_subject.id = map.get(each.data_subject.id)
262+
}
263+
}
264+
})
256265
}
257266

258267
module.exports = {

0 commit comments

Comments
 (0)