Skip to content

Commit

Permalink
optimize message type detection for performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorrit Sandbrink committed Mar 25, 2024
1 parent 493147d commit 7bd211b
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions sources/pg_replication/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,20 +603,20 @@ def process_msg(self, msg: ReplicationMessage) -> None:
- `target_batch_size` is reached
- a table's schema has changed
"""
op = (msg.payload[:1]).decode("utf-8")
if op == "B":
self.last_commit_ts = Begin(msg.payload).commit_ts
elif op == "C":
self.process_commit(msg)
elif op == "R":
self.process_relation(Relation(msg.payload))
elif op == "I":
op = msg.payload[:1]
if op == b"I":
self.process_change(Insert(msg.payload), msg.data_start)
elif op == "U":
elif op == b"U":
self.process_change(Update(msg.payload), msg.data_start)
elif op == "D":
elif op == b"D":
self.process_change(Delete(msg.payload), msg.data_start)
elif op == "T":
elif op == b"B":
self.last_commit_ts = Begin(msg.payload).commit_ts
elif op == b"C":
self.process_commit(msg)
elif op == b"R":
self.process_relation(Relation(msg.payload))
elif op == b"T":
logger.warning(
"The truncate operation is currently not supported. "
"Truncate replication messages are ignored."
Expand Down

0 comments on commit 7bd211b

Please sign in to comment.