pg_eventstore 1.0.0.rc2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84901d9b6a866b451fe90706312302ffd2bdbcd22a5a54cbff5c10123601336c
4
- data.tar.gz: 2f1e79704c3823763a65b5ddf8554413c3c684782454b1e4e5eaf562ae9a1699
3
+ metadata.gz: ebd667d51438040640b8edeee4d75fe2a88f6f0605c33f7dcb70a5a250d92efd
4
+ data.tar.gz: 5ca82322415c77be0ef1a44efe594bd6a3813552157e7bffcc67d64f8703718e
5
5
  SHA512:
6
- metadata.gz: 2155de5400e32927278cdb79554b1f0276ebf3e134e8317f099d1b782bf626a3ad10c5dbdfbab0cd194abc59987a03d83dc7c0dae3a1449f35875a8fc17d6edc
7
- data.tar.gz: e39889f475939611609d5f48c8742da829ea691b603affda17358ab27d2a4a0f5877c0dd186ce356ffc8951c3700fe59d2258b124205eca4b1bab972f755b868
6
+ metadata.gz: b339460c69fd29a43b23cc9d48847527e24a0c3a32b2524f03bec348058f1bad8873508cdf219d83a27ed4fefdb04ef3691aaeca9f67e93d78fff9556fbd1857
7
+ data.tar.gz: a122c0c6dcd1a65a12fbdf76df47167d26a727db6df47bd38122a0943622433dd410430450fcc9355bfc1ceb2b7f312eed03f1f25ababa4e897d56f8f3f60b76
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.0.0]
4
+
5
+ - Improve performance of Subscription#update by relaxing transaction isolation level
6
+ - Fix calculation of events number in the subscription's chunk
7
+
3
8
  ## [1.0.0.rc2]
4
9
 
5
10
  - Implement confirmation dialog for sensitive admin UI actions
@@ -84,7 +84,7 @@ module PgEventstore
84
84
  end.join(', ')
85
85
  sql =
86
86
  "UPDATE subscriptions SET #{attrs_sql} WHERE id = $#{attrs.keys.size + 1} RETURNING *"
87
- updated_attrs = transaction_queries.transaction do
87
+ updated_attrs = transaction_queries.transaction(:read_committed) do
88
88
  pg_result = connection.with do |conn|
89
89
  conn.exec_params(sql, [*attrs.values, id])
90
90
  end
@@ -3,6 +3,14 @@
3
3
  module PgEventstore
4
4
  # @!visibility private
5
5
  class TransactionQueries
6
+ ISOLATION_LEVELS = {
7
+ read_committed: 'READ COMMITTED',
8
+ repeatable_read: 'REPEATABLE READ',
9
+ serializable: 'SERIALIZABLE'
10
+ }.tap do |h|
11
+ h.default = h[:serializable]
12
+ end.freeze
13
+
6
14
  attr_reader :connection
7
15
  private :connection
8
16
 
@@ -11,15 +19,16 @@ module PgEventstore
11
19
  @connection = connection
12
20
  end
13
21
 
22
+ # @param level [Symbol] transaction isolation level
14
23
  # @return [void]
15
- def transaction
24
+ def transaction(level = :serializable)
16
25
  connection.with do |conn|
17
26
  # We are inside a transaction already - no need to start another one
18
27
  if [PG::PQTRANS_ACTIVE, PG::PQTRANS_INTRANS].include?(conn.transaction_status)
19
28
  next yield
20
29
  end
21
30
 
22
- pg_transaction(conn) do
31
+ pg_transaction(ISOLATION_LEVELS[level], conn) do
23
32
  yield
24
33
  end
25
34
  end
@@ -27,11 +36,12 @@ module PgEventstore
27
36
 
28
37
  private
29
38
 
39
+ # @param level [String] PostgreSQL transaction isolation level
30
40
  # @param pg_connection [PG::Connection]
31
41
  # @return [void]
32
- def pg_transaction(pg_connection)
42
+ def pg_transaction(level, pg_connection)
33
43
  pg_connection.transaction do
34
- pg_connection.exec("SET TRANSACTION ISOLATION LEVEL SERIALIZABLE")
44
+ pg_connection.exec("SET TRANSACTION ISOLATION LEVEL #{level}")
35
45
  yield
36
46
  end
37
47
  rescue PG::TRSerializationFailure, PG::TRDeadlockDetected
@@ -55,8 +55,8 @@ module PgEventstore
55
55
  def estimate_events_number
56
56
  return INITIAL_EVENTS_PER_CHUNK if @stats.average_event_processing_time.zero?
57
57
 
58
- events_per_chunk = @subscription.chunk_query_interval / @stats.average_event_processing_time
59
- [events_per_chunk, MAX_EVENTS_PER_CHUNK].min - @events_processor.events_left_in_chunk
58
+ events_per_chunk = (@subscription.chunk_query_interval / @stats.average_event_processing_time).round
59
+ [[events_per_chunk, MAX_EVENTS_PER_CHUNK].min - @events_processor.events_left_in_chunk, 0].max
60
60
  end
61
61
 
62
62
  # @return [void]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgEventstore
4
- VERSION = "1.0.0.rc2"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_eventstore
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Dzyzenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-10 00:00:00.000000000 Z
11
+ date: 2024-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg