dataviz: refresh statistics list more frequently using spooler (#50891)

This commit is contained in:
Valentin Deniaud 2021-02-17 11:37:13 +01:00
parent a6f2a755e1
commit e7670e0ab1
3 changed files with 40 additions and 1 deletions

View File

@ -14,13 +14,15 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
from collections import OrderedDict
from django import forms
from django.conf import settings
from django.db import transaction, connection
from django.db.models import Q
from combo.utils import requests
from combo.utils import requests, cache_during_request
from .models import ChartCell, ChartNgCell
@ -45,6 +47,17 @@ class ChartForm(forms.ModelForm):
self.fields['url'].widget = forms.Select(choices=available_charts)
@cache_during_request
def trigger_statistics_list_refresh():
if 'uwsgi' in sys.modules:
from combo.utils.spooler import refresh_statistics_list
tenant = getattr(connection, 'tenant', None)
transaction.on_commit(
lambda: refresh_statistics_list.spool(domain=getattr(tenant, 'domain_url', None))
)
class ChartNgForm(forms.ModelForm):
blank_choice = ('', '---------')
@ -67,6 +80,7 @@ class ChartNgForm(forms.ModelForm):
}
def __init__(self, *args, **kwargs):
trigger_statistics_list_refresh()
super().__init__(*args, **kwargs)
field_ids = list(self._meta.fields)

View File

@ -161,6 +161,9 @@ class ChartNgCell(CellBase):
null=True,
on_delete=models.SET_NULL,
related_name='cells',
help_text=_(
'This list may take a few seconds to be updated, please refresh the page if an item is missing.'
),
)
filter_params = JSONField(default=dict)
title = models.CharField(_('Title'), max_length=150, blank=True)

View File

@ -13,3 +13,25 @@
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.db import connection
from uwsgidecorators import spool
from combo.apps.dataviz.utils import update_available_statistics
def set_connection(domain):
from hobo.multitenant.middleware import TenantMiddleware
tenant = TenantMiddleware.get_tenant_by_hostname(domain)
connection.set_tenant(tenant)
@spool
def refresh_statistics_list(args):
if args.get('domain'):
# multitenant installation
set_connection(args['domain'])
update_available_statistics()