Caches parent-child relationships between DAL objects to avoid repeated DB calls.
Definition at line 31 of file rename_duplicate_dals.py.
◆ __init__()
| rename_duplicate_dals.RelationshipCache.__init__ |
( |
| self, |
|
|
Configuration | str | db ) |
Definition at line 34 of file rename_duplicate_dals.py.
34 def __init__(self, db: Configuration | str):
35 if isinstance(db, str):
36 db = Configuration("oksconflibs:" + db)
37 self.db = db
38 self._relations_cache: Dict[str, Any] = {}
39 self._parents_cache: Dict[Any, list] = {}
40 self.graph = self._build_graph()
41
◆ _build_graph()
| Dict[DalBase, List[DalBase]] rename_duplicate_dals.RelationshipCache._build_graph |
( |
| self | ) |
|
|
protected |
Definition at line 47 of file rename_duplicate_dals.py.
47 def _build_graph(self) -> Dict[DalBase, List[DalBase]]:
48 graph = {}
49 for obj in self.db.get_all_dals().values():
50 children = []
51 for rel in self._relations(obj.className()):
52 related = getattr(obj, rel, None)
53 if related is None:
54 continue
55 children.extend(related if isinstance(related, list) else [related])
56 if children:
57 graph[obj] = children
58 return graph
59
◆ _relations()
| rename_duplicate_dals.RelationshipCache._relations |
( |
| self, |
|
|
str | class_name ) |
|
protected |
Definition at line 42 of file rename_duplicate_dals.py.
42 def _relations(self, class_name: str):
43 if class_name not in self._relations_cache:
44 self._relations_cache[class_name] = self.db.relations(class_name, all=True)
45 return self._relations_cache[class_name]
46
◆ get_parents()
| List[DalBase] rename_duplicate_dals.RelationshipCache.get_parents |
( |
| self, |
|
|
DalBase | obj ) |
Definition at line 60 of file rename_duplicate_dals.py.
60 def get_parents(self, obj: DalBase) -> List[DalBase]:
61 if obj not in self._parents_cache:
62 self._parents_cache[obj] = [
63 parent for parent, children in self.graph.items() if obj in children
64 ]
65 return self._parents_cache[obj]
66
67
68
69
◆ _parents_cache [1/2]
| dict rename_duplicate_dals.RelationshipCache._parents_cache = {} |
|
protected |
◆ _parents_cache [2/2]
| list rename_duplicate_dals.RelationshipCache._parents_cache |
Initial value:= [
parent for parent, children in self.graph.items() if obj in children
]
Definition at line 61 of file rename_duplicate_dals.py.
◆ _relations_cache
| rename_duplicate_dals.RelationshipCache._relations_cache = {} |
|
protected |
◆ db
| rename_duplicate_dals.RelationshipCache.db = db |
◆ graph
| Dict[DalBase, List[DalBase]] rename_duplicate_dals.RelationshipCache.graph = self._build_graph() |
The documentation for this class was generated from the following file: