@@ -87,19 +87,17 @@ def __init__(
8787 self .committed = committed
8888
8989 def __lt__ (self , other ):
90- if self .entity_class_name == other .entity_class_name :
90+ entity_class = self .db_map .mapped_table ("entity_class" )[self .entity_class_id ]
91+ class_name = entity_class ["name" ]
92+ other_entity_class = other .db_map .mapped_table ("entity_class" )[other .entity_class_id ]
93+ other_class_name = other_entity_class ["name" ]
94+ if class_name == other_class_name :
9195 return self .db_mngr .name_registry .display_name (
9296 self .db_map .sa_url
9397 ) < self .db_mngr .name_registry .display_name (other .db_map .sa_url )
94- keys = {}
95- for side , model in {"left" : self , "right" : other }.items ():
96- dim = len (model .dimension_id_list )
97- class_name = model .entity_class_name
98- keys [side ] = (
99- dim ,
100- class_name ,
101- )
102- return keys ["left" ] < keys ["right" ]
98+ keys = (len (entity_class ["dimension_id_list" ]), class_name )
99+ other_keys = (len (other_entity_class ["dimension_id_list" ]), other_class_name )
100+ return keys < other_keys
103101
104102 @property
105103 def item_type (self ) -> str :
@@ -126,24 +124,14 @@ def _convert_to_db(self, item: dict) -> dict:
126124 def _references (self ) -> dict [str , tuple [str , str | None ]]:
127125 raise NotImplementedError ()
128126
129- @property
130- def entity_class_name (self ) -> str :
131- entity_class_table = self .db_map .mapped_table ("entity_class" )
132- return entity_class_table [self .entity_class_id ]["name" ]
133-
134- @property
135- def dimension_id_list (self ) -> list [TempId ]:
136- entity_class_table = self .db_map .mapped_table ("entity_class" )
137- return entity_class_table [self .entity_class_id ]["dimension_id_list" ]
138-
139127 def item_id (self , row : int ) -> TempId :
140- """Returns parameter id for row.
128+ """Returns item's id for row.
141129
142130 Args:
143131 row: row index
144132
145133 Returns:
146- parameter id
134+ item's id
147135 """
148136 return self ._main_data [row ]
149137
@@ -269,30 +257,24 @@ def set_filter_entity_ids(self, entity_selection: EntitySelection) -> bool:
269257 entity_ids = selected_entities_by_class [self .entity_class_id ]
270258 else :
271259 entity_ids = set ()
272- dimension_id_list = self .db_map .mapped_table ("entity_class" )[self .entity_class_id ][
273- "dimension_id_list"
274- ]
275- for dimension_id in dimension_id_list :
276- if dimension_id not in selected_entities_by_class :
277- continue
278- selected_entities = selected_entities_by_class [dimension_id ]
279- if selected_entities is Asterisk :
280- continue
281- entity_ids |= selected_entities
282- if dimension_id_list and not entity_ids :
283- entity_ids = Asterisk
260+ for class_id , entity_selection in selected_entities_by_class .items ():
261+ if entity_selection is Asterisk :
262+ entity_ids = Asterisk
263+ break
264+ entity_ids .update (entity_selection )
284265 if entity_ids == self ._filter_entity_ids :
285266 return False
286267 self ._filter_entity_ids = entity_ids
287268 return True
288269
289270 def filter_accepts_item (self , item : PublicItem ) -> bool :
290- """Reimplemented to also account for the entity and alternative filter."""
271+ """Reimplemented to also account for the entity filter."""
291272 if self ._filter_entity_ids is Asterisk :
292273 return super ().filter_accepts_item (item )
293- entity_accepts = item [
294- self ._ENTITY_ID_FIELD
295- ] in self ._filter_entity_ids or not self ._filter_entity_ids .isdisjoint (item ["element_id_list" ])
274+ entity_id = item [self ._ENTITY_ID_FIELD ]
275+ entity_accepts = entity_id in self ._filter_entity_ids or self .db_mngr .relationship_graph .is_any_id_reachable (
276+ self .db_map , entity_id , self ._filter_entity_ids
277+ )
296278 return entity_accepts and super ().filter_accepts_item (item )
297279
298280
@@ -314,7 +296,7 @@ def set_filter_alternative_ids(self, alternative_selection: AlternativeSelection
314296 return True
315297
316298 def filter_accepts_item (self , item : PublicItem ) -> bool :
317- """Reimplemented to also account for the entity and alternative filter."""
299+ """Reimplemented to also account for the alternative filter."""
318300 if self ._filter_alternative_ids is Asterisk :
319301 return super ().filter_accepts_item (item )
320302 return item ["alternative_id" ] in self ._filter_alternative_ids and super ().filter_accepts_item (item )
@@ -445,7 +427,7 @@ class EntityMixin:
445427
446428 def update_items_in_db (self , items : list [dict ]) -> None :
447429 """Overridden to create entities on the fly first."""
448- class_name = self .entity_class_name
430+ class_name = self .db_map . mapped_table ( "entity_class" )[ self . entity_class_id ][ "name" ]
449431 for item in items :
450432 item ["entity_class_name" ] = class_name
451433 entities = []
0 commit comments