Compare commits

...

1 Commits

Author SHA1 Message Date
Gerda Shank
cd2bb9751a Use lazy_log method in RelationsCache for dump_graph events 2022-01-28 09:58:46 -05:00
2 changed files with 12 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
import threading import threading
from copy import deepcopy from copy import deepcopy
from typing import Any, Dict, Iterable, List, Optional, Set, Tuple from typing import Any, Dict, Iterable, List, Optional, Set, Tuple
import dbt.flags as flags
from dbt.adapters.reference_keys import _make_key, _ReferenceKey from dbt.adapters.reference_keys import _make_key, _ReferenceKey
import dbt.exceptions import dbt.exceptions
@@ -322,11 +323,11 @@ class RelationsCache:
""" """
cached = _CachedRelation(relation) cached = _CachedRelation(relation)
fire_event(AddRelation(relation=_make_key(cached))) fire_event(AddRelation(relation=_make_key(cached)))
fire_event(DumpBeforeAddGraph(dump=self.dump_graph())) self.lazy_log(DumpBeforeAddGraph)
with self.lock: with self.lock:
self._setdefault(cached) self._setdefault(cached)
fire_event(DumpAfterAddGraph(dump=self.dump_graph())) self.lazy_log(DumpAfterAddGraph)
def _remove_refs(self, keys): def _remove_refs(self, keys):
"""Removes all references to all entries in keys. This does not """Removes all references to all entries in keys. This does not
@@ -440,7 +441,7 @@ class RelationsCache:
new_key = _make_key(new) new_key = _make_key(new)
fire_event(RenameSchema(old_key=old_key, new_key=new_key)) fire_event(RenameSchema(old_key=old_key, new_key=new_key))
fire_event(DumpBeforeRenameSchema(dump=self.dump_graph())) self.lazy_log(DumpBeforeRenameSchema)
with self.lock: with self.lock:
if self._check_rename_constraints(old_key, new_key): if self._check_rename_constraints(old_key, new_key):
@@ -448,7 +449,7 @@ class RelationsCache:
else: else:
self._setdefault(_CachedRelation(new)) self._setdefault(_CachedRelation(new))
fire_event(DumpAfterRenameSchema(dump=self.dump_graph())) self.lazy_log(DumpAfterRenameSchema)
def get_relations( def get_relations(
self, database: Optional[str], schema: Optional[str] self, database: Optional[str], schema: Optional[str]
@@ -501,3 +502,10 @@ class RelationsCache:
drop_key = _make_key(relation) drop_key = _make_key(relation)
if drop_key in self.relations: if drop_key in self.relations:
self.drop(drop_key) self.drop(drop_key)
# We don't want to call the 'dump_graph' method if we're not logging
# the cache because of performance issues
def lazy_log(self, event_cls):
if not flags.LOG_CACHE_EVENTS:
return
event_cls(dump=self.dump_graph())

View File

@@ -317,10 +317,6 @@ def send_exc_to_logger(
# (i.e. - mutating the event history, printing to stdout, logging # (i.e. - mutating the event history, printing to stdout, logging
# to files, etc.) # to files, etc.)
def fire_event(e: Event) -> None: def fire_event(e: Event) -> None:
# skip logs when `--log-cache-events` is not passed
if isinstance(e, Cache) and not flags.LOG_CACHE_EVENTS:
return
# if and only if the event history deque will be completely filled by this event # if and only if the event history deque will be completely filled by this event
# fire warning that old events are now being dropped # fire warning that old events are now being dropped
global EVENT_HISTORY global EVENT_HISTORY