Skip to content

Commit

Permalink
Move run_extra_queries outsize of BaseViz init
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Mar 16, 2018
1 parent 93ec76f commit b906fec
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def __init__(self, datasource, form_data, force=False):
self._some_from_cache = False
self._any_cache_key = None
self._any_cached_dttm = None

self.run_extra_queries()
self._extra_chart_data = None

def run_extra_queries(self):
"""Lyfecycle method to use when more than one query is needed
Expand Down Expand Up @@ -286,6 +285,7 @@ def cache_key(self, query_obj):

def get_payload(self, query_obj=None):
"""Returns a payload of metadata and data"""
self.run_extra_queries()
payload = self.get_df_payload(query_obj)

df = payload.get('df')
Expand Down Expand Up @@ -1119,7 +1119,6 @@ def process_data(self, df, aggregate=False):
def run_extra_queries(self):
fd = self.form_data
time_compare = fd.get('time_compare')
self.extra_chart_data = None
if time_compare:
query_object = self.query_obj()
delta = utils.parse_human_timedelta(time_compare)
Expand All @@ -1137,15 +1136,15 @@ def run_extra_queries(self):
if df2 is not None:
df2[DTTM_ALIAS] += delta
df2 = self.process_data(df2)
self.extra_chart_data = self.to_series(
self._extra_chart_data = self.to_series(
df2, classed='superset', title_suffix='---')

def get_data(self, df):
df = self.process_data(df)
chart_data = self.to_series(df)

if self.extra_chart_data:
chart_data += self.extra_chart_data
if self._extra_chart_data:
chart_data += self._extra_chart_data
chart_data = sorted(chart_data, key=lambda x: x['key'])

return chart_data
Expand Down

0 comments on commit b906fec

Please sign in to comment.