dataviz: update statistic data asynchronously (#50892)
This commit is contained in:
parent
e7670e0ab1
commit
58de5909fe
|
@ -16,11 +16,12 @@
|
|||
|
||||
import copy
|
||||
import os
|
||||
import sys
|
||||
from datetime import date
|
||||
from requests.exceptions import RequestException
|
||||
|
||||
from django.urls import reverse
|
||||
from django.db import models
|
||||
from django.db import models, connection, transaction
|
||||
from django.utils import timezone
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.translation import ugettext_lazy as _, ungettext, gettext
|
||||
|
@ -281,7 +282,7 @@ class ChartNgCell(CellBase):
|
|||
ctx['table'] = ctx['table'].replace('<table>', '<table class="main">')
|
||||
return ctx
|
||||
|
||||
def get_statistic_data(self, raise_if_not_cached=False):
|
||||
def get_statistic_data(self, raise_if_not_cached=False, invalidate_cache=False):
|
||||
return requests.get(
|
||||
self.statistic.url,
|
||||
params=self.get_filter_params(),
|
||||
|
@ -290,9 +291,19 @@ class ChartNgCell(CellBase):
|
|||
without_user=True,
|
||||
raise_if_not_cached=raise_if_not_cached,
|
||||
log_errors=False,
|
||||
invalidate_cache=invalidate_cache,
|
||||
)
|
||||
|
||||
def get_chart(self, width=None, height=None, raise_if_not_cached=False):
|
||||
if 'uwsgi' in sys.modules:
|
||||
from combo.utils.spooler import refresh_statistics_data
|
||||
|
||||
tenant = getattr(connection, 'tenant', None)
|
||||
transaction.on_commit(
|
||||
lambda: refresh_statistics_data.spool(
|
||||
cell_pk=str(self.pk), domain=getattr(tenant, 'domain_url', None)
|
||||
)
|
||||
)
|
||||
response = self.get_statistic_data(raise_if_not_cached)
|
||||
response.raise_for_status()
|
||||
response = response.json()
|
||||
|
|
|
@ -18,7 +18,9 @@ from django.db import connection
|
|||
|
||||
from uwsgidecorators import spool
|
||||
|
||||
from combo.apps.dataviz.models import ChartNgCell
|
||||
from combo.apps.dataviz.utils import update_available_statistics
|
||||
from combo.utils import requests
|
||||
|
||||
|
||||
def set_connection(domain):
|
||||
|
@ -35,3 +37,13 @@ def refresh_statistics_list(args):
|
|||
set_connection(args['domain'])
|
||||
|
||||
update_available_statistics()
|
||||
|
||||
|
||||
@spool
|
||||
def refresh_statistics_data(args):
|
||||
if args.get('domain'):
|
||||
# multitenant installation
|
||||
set_connection(args['domain'])
|
||||
|
||||
cell = ChartNgCell.objects.get(pk=args['cell_pk'])
|
||||
cell.get_statistic_data(invalidate_cache=True)
|
||||
|
|
Loading…
Reference in New Issue