Skip to content

Commit

Permalink
remove redundant calls to extract_card_exposures with empty cards
Browse files Browse the repository at this point in the history
  • Loading branch information
gouline committed Dec 13, 2024
1 parent 0bcfb5d commit e4417ac
Showing 1 changed file with 16 additions and 28 deletions.
44 changes: 16 additions & 28 deletions dbtmetabase/_exposures.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def extract_exposures(
f"Visualization: {entity.get('display', 'Unknown').title()}"
)

result = self.__extract_card_exposures(ctx, card=entity)
result = self.__extract_card_exposures(ctx, entity)
depends.update(result["depends"])
native_query = result["native_query"]

Expand Down Expand Up @@ -168,12 +168,9 @@ def extract_exposures(
if "id" not in card:
continue

depends.update(
self.__extract_card_exposures(
ctx,
card=self.metabase.find_card(uid=card["id"]),
)["depends"]
)
if card := self.metabase.find_card(uid=card["id"]):
result = self.__extract_card_exposures(ctx, card)
depends.update(result["depends"])
else:
_logger.warning("Unexpected collection item '%s'", item["model"])
continue
Expand Down Expand Up @@ -231,11 +228,7 @@ def extract_exposures(

return exposures

def __extract_card_exposures(
self,
ctx: __Context,
card: Optional[Mapping],
) -> Mapping:
def __extract_card_exposures(self, ctx: __Context, card: Mapping) -> Mapping:
"""Extracts exposures from Metabase questions."""

depends = set()
Expand All @@ -251,14 +244,11 @@ def __extract_card_exposures(

if str(query_source).startswith("card__"):
# Handle questions based on other questions
depends.update(
self.__extract_card_exposures(
ctx,
card=self.metabase.find_card(
uid=query_source.split("__")[-1]
),
)["depends"]
)
if source_card := self.metabase.find_card(
uid=query_source.split("__")[-1]
):
result = self.__extract_card_exposures(ctx, source_card)
depends.update(result["depends"])
elif query_source in ctx.table_names:
# Normal question
source_table = ctx.table_names.get(query_source)
Expand All @@ -273,14 +263,12 @@ def __extract_card_exposures(

if str(join_source).startswith("card__"):
# Handle questions based on other questions
depends.update(
self.__extract_card_exposures(
ctx,
card=self.metabase.find_card(
uid=join_source.split("__")[-1]
),
)["depends"]
)
if source_card := self.metabase.find_card(
uid=join_source.split("__")[-1]
):
result = self.__extract_card_exposures(ctx, source_card)
depends.update(result["depends"])

continue

# Joined model parsed
Expand Down

0 comments on commit e4417ac

Please sign in to comment.