Return a mapping of organisation_id -> total integration count.
(
org_ids: set[int],
)
| 394 | |
| 395 | |
| 396 | def _get_integration_counts_by_org( |
| 397 | org_ids: set[int], |
| 398 | ) -> dict[int, int]: |
| 399 | """Return a mapping of organisation_id -> total integration count.""" |
| 400 | result: dict[int, int] = defaultdict(int) |
| 401 | registry = get_integration_registry() |
| 402 | |
| 403 | for model, org_lookup_path, _ in registry.values(): |
| 404 | counts = ( |
| 405 | model.objects.filter(**{f"{org_lookup_path}__in": org_ids}) |
| 406 | .values(**{"org_id": F(org_lookup_path)}) |
| 407 | .annotate(count=Count("id")) |
| 408 | ) |
| 409 | for row in counts: |
| 410 | result[row["org_id"]] += row["count"] |
| 411 | |
| 412 | return result |
| 413 | |
| 414 | |
| 415 | def get_usage_trends( |
no test coverage detected
searching dependent graphs…