def refresh_if_need(cls, instance): cache_field_name = cls.model_cache_field_mapper.get(type(instance)) if cache_field_name: org_cache = OrgResourceStatisticsCache(instance.org) org_cache.expire(*cache_field_name) OrgResourceStatisticsCache( Organization.root()).expire(*cache_field_name)
def refresh_user_amount_on_user_create_or_delete(user_id): orgs = Organization.objects.filter( m2m_org_members__user_id=user_id).distinct() for org in orgs: org_cache = OrgResourceStatisticsCache(org) org_cache.expire('users_amount') OrgResourceStatisticsCache(Organization.root()).expire('users_amount')
def _refresh_session_org_resource_statistics_cache(instance: Session): cache_field_name = [ 'total_count_online_users', 'total_count_online_sessions' ] org_cache = OrgResourceStatisticsCache(instance.org) org_cache.expire(*cache_field_name) OrgResourceStatisticsCache(Organization.root()).expire(*cache_field_name)
def on_org_user_changed_refresh_cache(sender, action, instance, reverse, pk_set, **kwargs): if not action.startswith(POST_PREFIX): return if reverse: orgs = Organization.objects.filter(id__in=pk_set) else: orgs = [instance] for org in orgs: org_cache = OrgResourceStatisticsCache(org) org_cache.expire('users_amount')
def expire_org_resource_statistics_cache(): orgs = Organization.objects.all() for org in orgs: cache = OrgResourceStatisticsCache(org) cache.expire()