Skip to content

Commit 1138f6a

Browse files
committed
Removed redundant MAX statement in the PostgreSQL append to stream function
1 parent bd65823 commit 1138f6a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/packages/emmett-postgresql/src/eventStore/schema/appendToStream.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ export const appendToStreamSQL = rawSql(
4848
v_transaction_id := pg_current_xact_id();
4949
5050
IF v_expected_stream_position IS NULL THEN
51-
SELECT COALESCE(max(stream_position), 0) INTO v_expected_stream_position
51+
SELECT COALESCE(stream_position, 0) INTO v_expected_stream_position
5252
FROM ${streamsTable.name}
53-
WHERE stream_id = v_stream_id AND partition = v_partition;
54-
END IF;
53+
WHERE stream_id = v_stream_id AND partition = v_partition AND is_archived = FALSE;
54+
END IF;
5555
5656
v_next_stream_position := v_expected_stream_position + array_upper(v_messages_data, 1);
5757
@@ -76,7 +76,7 @@ export const appendToStreamSQL = rawSql(
7676
WITH ev AS (
7777
SELECT row_number() OVER () + v_expected_stream_position AS stream_position,
7878
message_data,
79-
message_metadata,
79+
messAage_metadata,
8080
schema_version,
8181
message_id,
8282
message_type,

0 commit comments

Comments
 (0)