Optimize logbook row matching (#123127)
This commit is contained in:
parent
6b7307df81
commit
4fd92c17f0
1 changed files with 4 additions and 8 deletions
|
@ -332,7 +332,7 @@ class ContextAugmenter:
|
||||||
if not (context_row := self._get_context_row(context_id_bin, row)):
|
if not (context_row := self._get_context_row(context_id_bin, row)):
|
||||||
return
|
return
|
||||||
|
|
||||||
if _rows_match(row, context_row):
|
if row is context_row or _rows_ids_match(row, context_row):
|
||||||
# This is the first event with the given ID. Was it directly caused by
|
# This is the first event with the given ID. Was it directly caused by
|
||||||
# a parent event?
|
# a parent event?
|
||||||
context_parent_id_bin = row[CONTEXT_PARENT_ID_BIN_POS]
|
context_parent_id_bin = row[CONTEXT_PARENT_ID_BIN_POS]
|
||||||
|
@ -348,7 +348,7 @@ class ContextAugmenter:
|
||||||
return
|
return
|
||||||
# Ensure the (parent) context_event exists and is not the root cause of
|
# Ensure the (parent) context_event exists and is not the root cause of
|
||||||
# this log entry.
|
# this log entry.
|
||||||
if _rows_match(row, context_row):
|
if row is context_row or _rows_ids_match(row, context_row):
|
||||||
return
|
return
|
||||||
event_type = context_row[EVENT_TYPE_POS]
|
event_type = context_row[EVENT_TYPE_POS]
|
||||||
# State change
|
# State change
|
||||||
|
@ -396,13 +396,9 @@ class ContextAugmenter:
|
||||||
data[CONTEXT_ENTITY_ID_NAME] = self.entity_name_cache.get(attr_entity_id)
|
data[CONTEXT_ENTITY_ID_NAME] = self.entity_name_cache.get(attr_entity_id)
|
||||||
|
|
||||||
|
|
||||||
def _rows_match(row: Row | EventAsRow, other_row: Row | EventAsRow) -> bool:
|
def _rows_ids_match(row: Row | EventAsRow, other_row: Row | EventAsRow) -> bool:
|
||||||
"""Check of rows match by using the same method as Events __hash__."""
|
"""Check of rows match by using the same method as Events __hash__."""
|
||||||
return bool(
|
return bool((row_id := row[ROW_ID_POS]) and row_id == other_row[ROW_ID_POS])
|
||||||
row is other_row
|
|
||||||
or (row_id := row[ROW_ID_POS])
|
|
||||||
and row_id == other_row[ROW_ID_POS]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class EntityNameCache:
|
class EntityNameCache:
|
||||||
|
|
Loading…
Add table
Reference in a new issue