Skip to content

Commit

Permalink
[fix] Fixed slow query for WifiSession dashboard pie chart #528
Browse files Browse the repository at this point in the history
Closes #528
  • Loading branch information
pandafy committed Sep 8, 2023
1 parent 6e2e126 commit 6770e17
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
- name: Install openwisp-monitoring
run: |
pip install -U -I -e .
pip install --no-deps --no-cache-dir --force-reinstall --upgrade https://github.com/openwisp/openwisp-utils/tarball/dashboard-chart-filter
pip uninstall -y django
pip install ${{ matrix.django-version }}
Expand Down
21 changes: 6 additions & 15 deletions openwisp_monitoring/device/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.apps import AppConfig
from django.conf import settings
from django.core.cache import cache
from django.db.models import Case, Count, Sum, When
from django.db.models import Count
from django.db.models.signals import post_delete, post_save
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -350,30 +350,21 @@ def register_dashboard_items(self):
'query_params': {
'app_label': WifiSession._meta.app_label,
'model': WifiSession._meta.model_name,
'annotate': {
'active': Count(
Case(
When(
stop_time__isnull=True,
then=1,
)
)
),
},
'filter': {'stop_time__isnull': True},
'aggregate': {
'active__sum': Sum('active'),
'active__count': Count('id'),
},
'organization_field': 'device__organization_id',
},
'filters': {
'key': 'stop_time__isnull',
'active__sum': 'true',
'active__count': 'true',
},
'colors': {
'active__sum': '#267126',
'active__count': '#267126',
},
'labels': {
'active__sum': _('Currently Active WiFi Sessions'),
'active__count': _('Currently Active WiFi Sessions'),
},
'quick_link': {
'url': reverse_lazy(
Expand Down

0 comments on commit 6770e17

Please sign in to comment.