counter_culture 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +1 -1
- data/VERSION +1 -1
- data/counter_culture.gemspec +3 -3
- data/lib/counter_culture.rb +1 -0
- data/lib/counter_culture/reconciler.rb +11 -6
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 17e2e8471fc8063fc35d135431aee0c6f9b88945
|
|
4
|
+
data.tar.gz: 3501cf53a5553393f1d23727938f09b8c2007447
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e1081eced18d4ef33bb20ea1ceabd0bab38e2deb9a9549dd1610274879739ef48e047fb2d2cdf45ebe7f644a7cc4723e4b8213b4db3b692c0a8c50cad7147fbf
|
|
7
|
+
data.tar.gz: 0cbf2af0334ee313cb789fadb3a38e592fe5f712b5c703d702fac6ae78a55c892ecde74f0108bab0b35c054abe9bed24716fb8621ff961ee27b5f7756159d1ce
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -281,7 +281,7 @@ counter_culture currently does *not* support polymorphic associations. Check [th
|
|
|
281
281
|
|
|
282
282
|
counter_culture will not update counters in your automated tests *if* you use transactional fixtures. That's because transactional fixtures roll back all your database transactions and they are never committed. But counter_culture will only update its counters in the ```after_commit``` callback, which in this case will never run.
|
|
283
283
|
|
|
284
|
-
counter_culture itself has extensive automated tests so there should not be a need to test counter caches in your own tests. I therefore recommend removing any checks of counter caches as that will avoid this issue. If that is not an option for you, you can use the [`test_after_commit` gem](https://github.com/grosser/test_after_commit) to trigger `after_commit` callbacks even with transactional
|
|
284
|
+
counter_culture itself has extensive automated tests so there should not be a need to test counter caches in your own tests. I therefore recommend removing any checks of counter caches as that will avoid this issue. If that is not an option for you, you can use the [`test_after_commit` gem](https://github.com/grosser/test_after_commit) to trigger `after_commit` callbacks even with transactional fixtures enabled. Another option is to turn off transactional fixtures and use something like [database_cleaner](https://github.com/bmabey/database_cleaner) instead to clean your database between tests.
|
|
285
285
|
|
|
286
286
|
## Contributing to counter_culture
|
|
287
287
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.3
|
data/counter_culture.gemspec
CHANGED
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
|
4
4
|
# -*- encoding: utf-8 -*-
|
|
5
|
-
# stub: counter_culture 0.2.
|
|
5
|
+
# stub: counter_culture 0.2.3 ruby lib
|
|
6
6
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.name = "counter_culture"
|
|
9
|
-
s.version = "0.2.
|
|
9
|
+
s.version = "0.2.3"
|
|
10
10
|
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
12
12
|
s.require_paths = ["lib"]
|
|
13
13
|
s.authors = ["Magnus von Koeller"]
|
|
14
|
-
s.date = "2016-
|
|
14
|
+
s.date = "2016-10-18"
|
|
15
15
|
s.description = "counter_culture provides turbo-charged counter caches that are kept up-to-date not just on create and destroy, that support multiple levels of indirection through relationships, allow dynamic column names and that avoid deadlocks by updating in the after_commit callback."
|
|
16
16
|
s.email = "magnus@vonkoeller.de"
|
|
17
17
|
s.extra_rdoc_files = [
|
data/lib/counter_culture.rb
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
require 'active_support/core_ext/module/delegation'
|
|
2
|
+
require 'active_support/core_ext/module/attribute_accessors'
|
|
3
|
+
|
|
1
4
|
module CounterCulture
|
|
2
5
|
class Reconciler
|
|
3
6
|
attr_reader :counter, :options, :changes
|
|
@@ -54,14 +57,16 @@ module CounterCulture
|
|
|
54
57
|
|
|
55
58
|
counts_query.group(full_primary_key(relation_class)).find_in_batches(batch_size: batch_size) do |records|
|
|
56
59
|
# now iterate over all the models and see whether their counts are right
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
+
ActiveRecord::Base.transaction do
|
|
61
|
+
records.each do |record|
|
|
62
|
+
count = record.read_attribute('count') || 0
|
|
63
|
+
next if record.read_attribute(column_name) == count
|
|
60
64
|
|
|
61
|
-
|
|
65
|
+
track_change(record, column_name, count)
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
67
|
+
# use update_all because it's faster and because a fixed counter-cache shouldn't update the timestamp
|
|
68
|
+
relation_class.where(relation_class.primary_key => record.send(relation_class.primary_key)).update_all(column_name => count)
|
|
69
|
+
end
|
|
65
70
|
end
|
|
66
71
|
end
|
|
67
72
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: counter_culture
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Magnus von Koeller
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: after_commit_action
|