def get_total_events_count(organisation) -> int:  # type: ignore[no-untyped-def]
    """
    Return total number of events for an organisation in the last 30 days
    """
    if settings.USE_POSTGRES_FOR_ANALYTICS:
        count = APIUsageBucket.objects.filter(
            environment_id__in=_get_environment_ids_for_org(organisation),
            created_at__date__lte=date.today(),
            created_at__date__gt=date.today() - timedelta(days=30),
            bucket_size=constants.ANALYTICS_READ_BUCKET_SIZE,
        ).aggregate(total_count=Sum("total_count"))["total_count"]
    else:
        count = get_events_for_organisation(organisation.id)
    return count  # type: ignore[no-any-return]

    Return total number of events for an organisation in the last 30 days
    
api/app_analytics/analytics_db_service.py