iknow_view_models 3.0.3 → 3.1.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: e468d13031e18589144a941463c993e5f10bf4588ef0b69f412fa7498f54a339
4
- data.tar.gz: 6366dfda3ef8869fcab34111394fb4c35f10f1e469b2c800dc02ff2bd83e3542
3
+ metadata.gz: f9459a78038ecf77ab3855e7e4ea6a0899ac31fd3e7dd05be247d9e0b72284f3
4
+ data.tar.gz: 34d662ae8733173dd3372ef9af5cd68b133848e1a94e5b1250624ec50dd4b0eb
5
5
  SHA512:
6
- metadata.gz: 82cf736f4fd3d28a88a565c9c9d3bb2952804846429c4a3487f6594e9d42fee24345441de65195932923adcdda9c3d17e584baff74f060b7eb925f68be3f8b23
7
- data.tar.gz: 951ca783e17c738a7ca742aaaa5e8cd7342d526a59ea3ee4726b130f8e55add82ff50ec431cf7c27997354ea0987e82b1c929268771aa146792f7cff8329bf87
6
+ metadata.gz: 7841f336c7f1604e3b2dbd54fb7209be02ecae7d19100707bef4ecc9b9ef2ae4d741f74d205fe468ac7ce9f14bd359d1b67b3ec1b76507ea9b51f812d0375972
7
+ data.tar.gz: 6b7aaa8742bdb52afa77c37be699da4c4896ab25a1bb560e5b404506e4f97730dad6659c062ff1443bdb2f21ff120e205b888d3d742b372d9306062a515c8ad4
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.0.3'
4
+ VERSION = '3.1.0'
5
5
  end
@@ -12,7 +12,17 @@ module ViewModel::ActiveRecord::Cache::CacheableView
12
12
  CacheClearer = Struct.new(:cache, :id) do
13
13
  include ViewModel::AfterTransactionRunner
14
14
 
15
- def after_transaction
15
+ # It's important that we clear the cache before committing, because we rely
16
+ # on database locking to prevent cache race conditions. We require
17
+ # reading/refreshing the cache to obtain a FOR SHARE lock, which means that
18
+ # a reader must wait for a concurrent writer to commit before continuing to
19
+ # the cache. If the writer cleared the cache after commit, the reader could
20
+ # obtain old data before the clear, and then save the old data after it.
21
+ def before_commit
22
+ cache.delete(id)
23
+ end
24
+
25
+ def after_rollback
16
26
  cache.delete(id)
17
27
  end
18
28
 
@@ -4,16 +4,31 @@
4
4
  # `add_to_transaction`, the abstract method `after_transaction` will be invoked
5
5
  # by AR's callbacks.
6
6
  module ViewModel::AfterTransactionRunner
7
- def committed!(*); end
7
+ # Rails' internal API
8
+ def committed!(*)
9
+ after_commit
10
+ end
8
11
 
9
12
  def before_committed!
10
- after_transaction
13
+ before_commit
11
14
  end
12
15
 
13
16
  def rolledback!(*)
14
- after_transaction
17
+ after_rollback
18
+ end
19
+
20
+ def trigger_transactional_callbacks?
21
+ true
15
22
  end
16
23
 
24
+ # Our simplified API
25
+
26
+ def before_commit; end
27
+
28
+ def after_commit; end
29
+
30
+ def after_rollback; end
31
+
17
32
  def add_to_transaction
18
33
  if connection.transaction_open?
19
34
  connection.add_transaction_record(self)
@@ -22,9 +37,6 @@ module ViewModel::AfterTransactionRunner
22
37
  end
23
38
  end
24
39
 
25
- def trigger_transactional_callbacks?
26
- true
27
- end
28
40
 
29
41
  # Override to tie to a specific connection.
30
42
  def connection
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iknow_view_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - iKnow Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-29 00:00:00.000000000 Z
11
+ date: 2019-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord