Skip to content

Commit

Permalink
Change metadata_vars if not to if ... is None (#37)
Browse files Browse the repository at this point in the history
Both None and {} evaluates to True when using if not metadata_vars. This caused us to loop over the environment variables unnecessarily. This provides a significant performance increase for large projects.
  • Loading branch information
truls-p authored Jan 24, 2024
1 parent 63a4861 commit 5ce19dd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/unreleased/Under the Hood-20240123-194242.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: Under the Hood
body: Change metadata_vars \`if not\` to \`if ... is None\`
time: 2024-01-23T19:42:42.95727089Z
custom:
Author: truls-p
Issue: "6073"
2 changes: 1 addition & 1 deletion dbt_common/events/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def fire_event(e: BaseEvent, level: Optional[EventLevel] = None) -> None:

def get_metadata_vars() -> Dict[str, str]:
global metadata_vars
if not metadata_vars:
if metadata_vars is None:
metadata_vars = {
k[len(_METADATA_ENV_PREFIX) :]: v for k, v in os.environ.items() if k.startswith(_METADATA_ENV_PREFIX)
}
Expand Down

0 comments on commit 5ce19dd

Please sign in to comment.