Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More performant data subject resolving #117

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,28 @@ const addDataSubjectForDetailsEntity = (row, log, req, entity, model) => {

const resolveDataSubjects = async (logs, req) => {
const map = _getDataSubjectsMap(req)
const reqs = [], qtoReqs = new Map(), rowToResMap = new Map();
for (const each of Object.values(logs)) {
if (each.data_subject.id instanceof cds.ql.Query) {
const q = each.data_subject.id
if (map.has(q)) {
each.data_subject.id = map.get(q)
} else {
const res = await q
map.set(q, res)
each.data_subject.id = res
if (!qtoReqs.has(q)) {
reqs.push(q)
qtoReqs.set(q, reqs.length - 1);
rowToResMap.set(each, reqs.length - 1);
} else {
rowToResMap.set(each, qtoReqs.get(q));
}
}
}
}
const dsIDs = await Promise.all(reqs);
rowToResMap.forEach((idx, each) => {
map.set(each.data_subject.id, dsIDs[idx]);
each.data_subject.id = dsIDs[idx];
});
}

module.exports = {
Expand Down
Loading