counterwise 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -0
- data/lib/counter/integration/countable.rb +3 -2
- data/lib/counter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c53c61fffe70d6bed84b2d5e5da5349b4a4285dbd7c19a8523721c449dcdbcc
|
4
|
+
data.tar.gz: 23e702c8cc478833aa555ad28f4456912420036063bf53d30c35d61b426cbff9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3dc224b1948220028726742754a51b4523147f86de67bac047a3159a0760782d68722ec5afcbd017ad5b5d3434430a6c8db960906360dae858f484f43177b8c6
|
7
|
+
data.tar.gz: 8ba0623f2cea3a11c538dbf10f8ac3cb0ebd49400b92a0617c630b62c297e34fefd6d6298a243f8615caeb238d47cffce4d5f1dd79e7701c01957737d958fb17
|
data/README.md
CHANGED
@@ -15,6 +15,7 @@ Counting and aggregation library for Rails.
|
|
15
15
|
- [Reset a counter](#reset-a-counter)
|
16
16
|
- [Verify a counter](#verify-a-counter)
|
17
17
|
- [Hooks](#hooks)
|
18
|
+
- [Testing the counters in production](#testing-the-counters-in-production)
|
18
19
|
- [TODO](#todo)
|
19
20
|
- [Usage](#usage)
|
20
21
|
- [Installation](#installation)
|
@@ -273,6 +274,29 @@ class OrderRevenueCounter < Counter::Definition
|
|
273
274
|
end
|
274
275
|
```
|
275
276
|
|
277
|
+
## Testing the counters in production
|
278
|
+
|
279
|
+
It may be useful to verify the accuracy of the counters in production, especially if you are concerned about conditional counters etc causing counter drift over time.
|
280
|
+
|
281
|
+
This form of script takes a sampling approach suitable for large collections. It will randomly select a record and verify that the counter value is correct; if it's not, it stops giving you a chance to investigate.
|
282
|
+
|
283
|
+
```ruby
|
284
|
+
site_range = Site.minimum(:id)..Site.maximum(:id)
|
285
|
+
|
286
|
+
1000.times do
|
287
|
+
random_id = rand(site_range)
|
288
|
+
site = Site.where("id >= ?", random_id).limit(1).first
|
289
|
+
next if site.nil?
|
290
|
+
if site.confirmed_subscribers_counter.correct?
|
291
|
+
puts "✅ site #{site.id} has correct counter value"
|
292
|
+
else
|
293
|
+
puts "❌ site #{site.id} has incorrect counter value. Expected #{site.confirmed_subscribers_counter.value} but got #{site.confirmed_subscribers_counter.count_by_sql}"
|
294
|
+
break
|
295
|
+
end
|
296
|
+
sleep 0.1
|
297
|
+
end
|
298
|
+
```
|
299
|
+
|
276
300
|
---
|
277
301
|
|
278
302
|
## TODO
|
@@ -26,8 +26,9 @@ module Counter::Countable
|
|
26
26
|
def each_counter_to_update
|
27
27
|
# For each definition, find or create the counter on the parent
|
28
28
|
self.class.counted_by.each do |counter_definition|
|
29
|
-
|
30
|
-
|
29
|
+
parent_association = association(counter_definition.inverse_association)
|
30
|
+
parent_association.load_target unless parent_association.loaded?
|
31
|
+
parent_model = parent_association.target
|
31
32
|
next unless parent_model
|
32
33
|
counter = parent_model.counters.find_or_create_counter!(counter_definition)
|
33
34
|
yield counter if counter
|
data/lib/counter/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jamie Lawrence
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|