Skip to content

Commit

Permalink
Optimize logbook row matching (home-assistant#123127)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Aug 4, 2024
1 parent 6b7307d commit 4fd92c1
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions homeassistant/components/logbook/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def augment(
if not (context_row := self._get_context_row(context_id_bin, row)):
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
# a parent event?
context_parent_id_bin = row[CONTEXT_PARENT_ID_BIN_POS]
Expand All @@ -348,7 +348,7 @@ def augment(
return
# Ensure the (parent) context_event exists and is not the root cause of
# this log entry.
if _rows_match(row, context_row):
if row is context_row or _rows_ids_match(row, context_row):
return
event_type = context_row[EVENT_TYPE_POS]
# State change
Expand Down Expand Up @@ -396,13 +396,9 @@ def augment(
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__."""
return bool(
row is other_row
or (row_id := row[ROW_ID_POS])
and row_id == other_row[ROW_ID_POS]
)
return bool((row_id := row[ROW_ID_POS]) and row_id == other_row[ROW_ID_POS])


class EntityNameCache:
Expand Down

0 comments on commit 4fd92c1

Please sign in to comment.