Skip to content

Commit 4f143f8

Browse files
committed
Clean up write_unit checks with guards
1 parent 451b5c4 commit 4f143f8

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

packages/sync-service/lib/electric/shapes/consumer.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ defmodule Electric.Shapes.Consumer do
279279
{ShapeCache.Storage, :flushed, offset_in},
280280
%{write_unit: write_unit, pending_txn: pending_txn} = state
281281
)
282-
when write_unit == :txn_fragment and not is_nil(pending_txn) do
282+
when is_write_unit_txn_fragment(write_unit) and not is_nil(pending_txn) do
283283
state = notify_flushed_mappings(state, offset_in)
284284

285285
# Save the flushed offset for the current pending txn.
@@ -584,7 +584,7 @@ defmodule Electric.Shapes.Consumer do
584584
# With write_unit=txn all fragments are buffered until the Commit change is seen. At that
585585
# point, a transaction struct is produced from the buffered fragments and is written to
586586
# storage.
587-
state.write_unit == State.write_unit_txn() ->
587+
is_write_unit_txn(state.write_unit) ->
588588
{txns, transaction_builder} =
589589
TransactionBuilder.build(txn_fragment, state.transaction_builder)
590590

packages/sync-service/lib/electric/shapes/consumer/state.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,6 @@ defmodule Electric.Shapes.Consumer.State do
398398
]
399399
end
400400

401-
def write_unit_txn, do: @write_unit_txn
402-
def write_unit_txn_fragment, do: @write_unit_txn_fragment
401+
defguard is_write_unit_txn(write_unit) when write_unit == @write_unit_txn
402+
defguard is_write_unit_txn_fragment(write_unit) when write_unit == @write_unit_txn_fragment
403403
end

0 commit comments

Comments
 (0)