Skip to content

Commit

Permalink
Optimization function add_component_to_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jieguangzhou committed Jan 2, 2024
1 parent 294ea00 commit e36268b
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions superduperdb/base/datalayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ def _add(
if parent is not None:
self.metadata.create_parent_child(parent, object.unique_id)
object.post_create(self)
self.add_component_to_cache(object)
self._add_component_to_cache(object)
these_jobs = object.schedule_jobs(self, dependencies=dependencies)
jobs.extend(these_jobs)
return jobs
Expand Down Expand Up @@ -1263,15 +1263,15 @@ def close(self):
# TODO: gracefully close all opened connections
return

def add_component_to_cache(self, component: Component):
def _add_component_to_cache(self, component: Component):
"""
Add component to cache when it is added to the db.
Avoiding the need to load it from the db again.
"""
type_id = component.type_id

# TODO: Only added model,
# if add other component will get an error, need to fix
if type_id != "model":
return

self.models[component.identifier] = component
if cm := self.type_id_to_cache_mapping.get(type_id):
getattr(self, cm)[component.identifier] = component
component.on_load(self)


@dc.dataclass
Expand Down

0 comments on commit e36268b

Please sign in to comment.