Skip to content

Commit

Permalink
[backend] expand entity resolution when converting aggregate distribu…
Browse files Browse the repository at this point in the history
…tion (#6319)
  • Loading branch information
labo-flg committed Mar 12, 2024
1 parent 698b5a3 commit 9fae026
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions opencti-platform/opencti-graphql/src/database/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,11 +429,16 @@ export const stixLoadByFilters = async (context, user, types, args) => {

// region Graphics
const convertAggregateDistributions = async (context, user, limit, orderingFunction, distribution) => {
const data = R.take(limit, R.sortWith([orderingFunction(R.prop('value'))])(distribution));
const data = R.sortWith([orderingFunction(R.prop('value'))])(distribution);
// we try to resolve the complete batch of 100 results
const resolveLabels = await elFindByIds(context, user, data.map((d) => d.label), { toMap: true });
return data // Depending of user access, info can be empty, must be filtered
// Depending of user access, info can be empty, must be filtered
const filteredEntities = data
.filter((n) => isNotEmptyField(resolveLabels[n.label.toLowerCase()]))
.map((n) => R.assoc('entity', resolveLabels[n.label.toLowerCase()], n));
// take only the 'limit' first match
// TODO: integrate data access restriction into aggregation query, and directly return 'limit' element instead of 100
return R.take(limit, filteredEntities);
};
export const timeSeriesHistory = async (context, user, types, args) => {
const { startDate, endDate, interval } = args;
Expand Down

0 comments on commit 9fae026

Please sign in to comment.