Skip to content

Commit

Permalink
fix: sync sub queries before executing stored query
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Sep 18, 2023
1 parent da47457 commit 8bda570
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self) -> None:
self.data_source = "Query Store"

def import_query(self, query):
result = query.retrieve_results(fetch_if_not_cached=True)
result = query.fetch_results()
if not result:
return
columns = [col["label"] for col in result[0]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

import frappe

from insights.insights.doctype.insights_data_source.sources.query_store import (
sync_query_store,
)
from insights.utils import InsightsDataSource, InsightsQuery, InsightsTable

from .utils import (
Expand Down Expand Up @@ -106,7 +109,12 @@ def get_selected_tables(self):
return tables + join_tables

def before_fetch(self):
return
if self.doc.data_source != "Query Store":
return
sub_queries = [
t.get("table") for t in self.get_selected_tables() if t.get("table") != self.doc.name
]
sync_query_store(sub_queries)

def after_fetch(self, results):
if not self.has_cumulative_columns():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def before_fetch(self):
if self.doc.data_source != "Query Store":
return
sub_stored_queries = [t.table for t in self.doc.tables if t.table != self.doc.name]
sync_query_store(sub_stored_queries, force=True)
sync_query_store(sub_stored_queries)

def after_fetch(self, results):
if not self.has_cumulative_columns():
Expand Down
5 changes: 3 additions & 2 deletions insights/insights/doctype/insights_query/insights_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def get_columns(self):
def update_query_store(self):
if not self.is_stored:
return
sync_query_store([self.name], force=True)
sync_query_store([self.name])

def update_linked_docs(self):
old_self = self.get("_doc_before_save")
Expand Down Expand Up @@ -189,7 +189,8 @@ def fetch_results(self, additional_filters=None):
return self._results

def before_fetch(self):
self.variant_controller.before_fetch()
if hasattr(self.variant_controller, "before_fetch"):
self.variant_controller.before_fetch()

@log_error(raise_exc=True)
def process_results_columns(self, results):
Expand Down

0 comments on commit 8bda570

Please sign in to comment.