Inject Filter in charts view comes after the view is totally rendered?!

As far as I understood creating a charts view will cache the results for a user (default 1h).
While embedding the chart you can use getFilter function to filter your data.

So my function is like

function getFilter(context) {
  return { tenant_id: { "$in": context.token.authorized_tenant_ids.map(id => ObjectId(id)) } };
}

My JWT token containt those object id’s. So all reports are rendered correctly.
But with a horrible performance.

As charts are cached on a user base it looks like

  • chart view is rendered complete data
  • then the filter applies
  • the results are cached for the user

In my opinion the following order should be in place:

  • chart view is rendered complete data
  • the results are cached
  • then the filter applies
  • optional: cached for the user

Another way would be if it is possible to inject my filter earlier.
My aggregations are super fast if I do filter with my tenant list first. But the concept of the injection does not allow this.

So anyone who have tips or design patterns how to improve this?

1 Like