counterwise 0.1.3 → 0.1.4
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/README.md +6 -1
- data/app/models/concerns/counter/recalculatable.rb +9 -1
- data/app/models/concerns/counter/verifyable.rb +6 -3
- data/lib/counter/version.rb +1 -1
- metadata +5 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4486834d3cd8109cdc40ecd6cdcb7d9b40b689960550d1c68bbadb564d548726
|
|
4
|
+
data.tar.gz: b839de58dfe853a2b8f45414cc184053104fed3568cdbcb3569bbde060a10c6a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 76a8089e1a783202ab3401982ea3877e12138fe6ea379478113d6f1ce5daae2ae252255201c4195b1ce12b8507b7494c2dda0c4f1f67445a765c31d74d31338b
|
|
7
|
+
data.tar.gz: c542c109b5431240594f2d9ba22c8c8acd8503fa54231f0932ef67fc7d108cd9e7451310340113ba837967600bb4c7aafbb43a2766a84d821563cc130b56e514
|
data/README.md
CHANGED
|
@@ -129,10 +129,15 @@ this would use the definition of the counter, including any option to sum a colu
|
|
|
129
129
|
|
|
130
130
|
### Reset a counter
|
|
131
131
|
|
|
132
|
-
You can also reset a counter by calling `reset`.
|
|
132
|
+
You can also reset a counter by calling `reset`.
|
|
133
133
|
|
|
134
134
|
```ruby
|
|
135
135
|
store.order_revenue.reset
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Since counters are ActiveRecord objects, you could also reset them using:
|
|
139
|
+
|
|
140
|
+
```ruby
|
|
136
141
|
Counter::Value.update value: 0
|
|
137
142
|
```
|
|
138
143
|
|
|
@@ -9,7 +9,15 @@ module Counter::Recalculatable
|
|
|
9
9
|
else
|
|
10
10
|
with_lock do
|
|
11
11
|
new_value = definition.sum? ? sum_by_sql : count_by_sql
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
self.class.upsert(
|
|
14
|
+
attributes.without("id", "created_at", "updated_at").symbolize_keys.merge(value: new_value),
|
|
15
|
+
unique_by: [:parent_type, :parent_id, :name],
|
|
16
|
+
on_duplicate: Arel.sql("value = counter_values.value + EXCLUDED.value"),
|
|
17
|
+
record_timestamps: true
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
reload
|
|
13
21
|
end
|
|
14
22
|
end
|
|
15
23
|
end
|
|
@@ -35,11 +35,12 @@ module Counter::Verifyable
|
|
|
35
35
|
def sample_and_verify scope: -> { all }, samples: 1000, verbose: true, on_error: :raise
|
|
36
36
|
incorrect_counters = 0
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
counters = Counter::Value.merge(scope)
|
|
39
|
+
counter_range = counters.minimum(:id)..counters.maximum(:id)
|
|
39
40
|
|
|
40
41
|
samples.times do
|
|
41
42
|
random_id = rand(counter_range)
|
|
42
|
-
counter =
|
|
43
|
+
counter = counters.where("id >= ?", random_id).limit(1).first
|
|
43
44
|
next if counter.nil?
|
|
44
45
|
|
|
45
46
|
if counter.definition.global? || counter.definition.calculated?
|
|
@@ -56,7 +57,9 @@ module Counter::Verifyable
|
|
|
56
57
|
case on_error
|
|
57
58
|
when :raise then raise Counter::Error.new(message)
|
|
58
59
|
when :log then Rails.logger.error message
|
|
59
|
-
when :correct
|
|
60
|
+
when :correct
|
|
61
|
+
counter.correct!
|
|
62
|
+
puts "🔧 Corrected counter #{counter.id}" if verbose
|
|
60
63
|
end
|
|
61
64
|
end
|
|
62
65
|
sleep 0.1
|
data/lib/counter/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,43 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: counterwise
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jamie Lawrence
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-03-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
19
|
version: '7'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '7'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: standard
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - ">="
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
34
|
-
type: :development
|
|
35
|
-
prerelease: false
|
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
23
|
requirements:
|
|
38
24
|
- - ">="
|
|
39
25
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
26
|
+
version: '7'
|
|
41
27
|
description: Counting and aggregation library for Rails.
|
|
42
28
|
email:
|
|
43
29
|
- jamie@ideasasylum.com
|
|
@@ -101,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
101
87
|
- !ruby/object:Gem::Version
|
|
102
88
|
version: '0'
|
|
103
89
|
requirements: []
|
|
104
|
-
rubygems_version: 3.
|
|
90
|
+
rubygems_version: 3.4.10
|
|
105
91
|
signing_key:
|
|
106
92
|
specification_version: 4
|
|
107
93
|
summary: Counters and the counting counters that count them
|