iknow_view_models 2.8.10 → 2.9.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: 51b9c3c09028c03ae788841cce54fd75bee5c01fa2052a50404c3ae4d65fd1e5
4
- data.tar.gz: 46bbee4b8f0c18c29d204af1dd1bf2ab318b7b15ea3df062c861bf13eb7317a2
3
+ metadata.gz: 53525088a6e3b8f394861ea5326ee235d94eb69a7b49b346ca09f26894e62f38
4
+ data.tar.gz: e394ad428ee6131d5dcdf7107ca5fea22d23eb41ab6bc6c5ba96626343180f89
5
5
  SHA512:
6
- metadata.gz: f2d24ad04de38a97931d0f04b7b6ed98756bd8b7c6cb33624bd165b350c138c12f5b6c8ed95ae0e8e1a980295994238056961469f807e40be1e14c0515b983bc
7
- data.tar.gz: 10f420fe6acbb77a4285bb17b6598e29a22974b987dc47ea9027bbf5d657d9955439e876d52aa32e47d19342928f482ba4cf9a1ec6bdf2562d4b977d1d19a9cc
6
+ metadata.gz: 342baae02e08f68f1f4b624c153bb9fd00144f21aef38c5623144899a4554730fd98651411e26528e05f40b16fa51136235ae1831ebc25bb4860904de465aef8
7
+ data.tar.gz: af565e5b9374ce950178437a16def8cda1b50639d2e98e5c367be5af0cacaff85ddcb7f0fc57a1a4309466e3f682760ae8a213f0ac9ed740eeed4bd9b975736e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '2.8.10'
4
+ VERSION = '2.9.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)
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: 2.8.10
4
+ version: 2.9.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