frozen_record 0.24.1 → 0.25.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -0
- data/lib/frozen_record/base.rb +22 -1
- data/lib/frozen_record/scope.rb +1 -1
- data/lib/frozen_record/version.rb +1 -1
- data/spec/fixtures/prices.yml.erb +13 -0
- data/spec/scope_spec.rb +18 -7
- data/spec/support/price.rb +13 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e254d236ad017c1f92834767dfb9f8daa686965ff6d3328543e6707be703280e
|
4
|
+
data.tar.gz: ea51bf7bdbae4103e9cb43bbe204e276efb9dea1e4cc6f36e11edac9977a6175
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca56d88a30cd1636ddeaed686c056a0352d295f3f0441c2b0a4861b5dcac7786497f140dbc351d0d332e862a03173ca5ace48fe880c1e1c934216034bfaa211a
|
7
|
+
data.tar.gz: 7522b566accc6d996eb79bb574f977ff82913e6d678b153cb7f0b58fd36dc0db7572611c769ac416c354673900412362f71da85573f3ea2cbc97675e1bbae1cb
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
+
# v0.25.2
|
4
|
+
|
5
|
+
- Fix FrozenRecord.ignore_max_records_scan not applying
|
6
|
+
|
7
|
+
# v0.25.1
|
8
|
+
|
9
|
+
- More reliable way to disable max_records_scan checks when loading records.
|
10
|
+
|
11
|
+
# v0.25.0
|
12
|
+
|
13
|
+
- Disable max_records_scan checks when loading records.
|
14
|
+
- Add `FrozenRecord::Base.with_max_record_scan` for more easily allowing larger amount in specific tests.
|
15
|
+
|
3
16
|
# v0.24.1
|
4
17
|
|
5
18
|
- Fix index selection not applying some restrictions.
|
data/lib/frozen_record/base.rb
CHANGED
@@ -6,6 +6,19 @@ require 'frozen_record/backends'
|
|
6
6
|
module FrozenRecord
|
7
7
|
SlowQuery = Class.new(StandardError)
|
8
8
|
|
9
|
+
class << self
|
10
|
+
attr_accessor :enforce_max_records_scan
|
11
|
+
|
12
|
+
def ignore_max_records_scan
|
13
|
+
previous = enforce_max_records_scan
|
14
|
+
self.enforce_max_records_scan = false
|
15
|
+
yield
|
16
|
+
ensure
|
17
|
+
self.enforce_max_records_scan = previous
|
18
|
+
end
|
19
|
+
end
|
20
|
+
@enforce_max_records_scan = true
|
21
|
+
|
9
22
|
class Base
|
10
23
|
extend ActiveSupport::DescendantsTracker
|
11
24
|
extend ActiveModel::Naming
|
@@ -45,6 +58,14 @@ module FrozenRecord
|
|
45
58
|
end
|
46
59
|
|
47
60
|
class << self
|
61
|
+
def with_max_records_scan(value)
|
62
|
+
previous_max_records_scan = max_records_scan
|
63
|
+
self.max_records_scan = value
|
64
|
+
yield
|
65
|
+
ensure
|
66
|
+
self.max_records_scan = previous_max_records_scan
|
67
|
+
end
|
68
|
+
|
48
69
|
alias_method :set_default_attributes, :default_attributes=
|
49
70
|
private :set_default_attributes
|
50
71
|
def default_attributes=(default_attributes)
|
@@ -148,7 +169,7 @@ module FrozenRecord
|
|
148
169
|
end
|
149
170
|
@attributes = list_attributes(records).freeze
|
150
171
|
define_attribute_methods(@attributes.to_a)
|
151
|
-
records = records.map { |r| load(r) }.freeze
|
172
|
+
records = FrozenRecord.ignore_max_records_scan { records.map { |r| load(r) }.freeze }
|
152
173
|
index_definitions.values.each { |index| index.build(records) }
|
153
174
|
records
|
154
175
|
end
|
data/lib/frozen_record/scope.rb
CHANGED
@@ -202,7 +202,7 @@ module FrozenRecord
|
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
205
|
-
if @klass.max_records_scan && records.size > @klass.max_records_scan
|
205
|
+
if FrozenRecord.enforce_max_records_scan && @klass.max_records_scan && records.size > @klass.max_records_scan
|
206
206
|
raise SlowQuery, "Scanning #{records.size} records is too slow, the allowed maximum is #{@klass.max_records_scan}. Try to find a better index or consider an alternative storage"
|
207
207
|
end
|
208
208
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<% 100.times.map { |i| "plan_#{i}"}.each do |plan_name| %>
|
2
|
+
<% ["base", "online", "retail"].each do |type| %>
|
3
|
+
<% [nil, "USD", "EUR", "GBP", "JPY"].each do |currency| %>
|
4
|
+
<% ["monthly", "annual", "biennial", "triennial"].each do |period| %>
|
5
|
+
- plan_name: <%= plan_name %>
|
6
|
+
type: <%= type %>
|
7
|
+
period: <%= period %>
|
8
|
+
currency: <%= currency %>
|
9
|
+
amount: 10.0
|
10
|
+
<% end %>
|
11
|
+
<% end %>
|
12
|
+
<% end %>
|
13
|
+
<% end %>
|
data/spec/scope_spec.rb
CHANGED
@@ -476,17 +476,28 @@ describe 'querying' do
|
|
476
476
|
|
477
477
|
context 'when max_records_scan is set' do
|
478
478
|
|
479
|
-
around :each do |example|
|
480
|
-
FrozenRecord::Base.max_records_scan = 1
|
481
|
-
example.run
|
482
|
-
FrozenRecord::Base.max_records_scan = nil
|
483
|
-
end
|
484
|
-
|
485
479
|
it 'raises on slow queries' do
|
486
480
|
expect {
|
487
|
-
|
481
|
+
FrozenRecord::Base.with_max_records_scan(1) do
|
482
|
+
Country.where(king: "Louis").to_a
|
483
|
+
end
|
488
484
|
}.to raise_error(FrozenRecord::SlowQuery)
|
489
485
|
end
|
490
486
|
|
487
|
+
it 'is accurate' do
|
488
|
+
FrozenRecord::Base.with_max_records_scan(60) do
|
489
|
+
expect(Price.count).to be == 6_000
|
490
|
+
|
491
|
+
Price.where(plan_name: "plan_24", currency: [nil, "EUR"], period: "monthly", type: "base").each do |price|
|
492
|
+
expect(price.plan_name).to be == "plan_24"
|
493
|
+
unless price.currency.nil?
|
494
|
+
expect(price.currency).to be == "EUR"
|
495
|
+
end
|
496
|
+
expect(price.period).to be == "monthly"
|
497
|
+
expect(price.type).to be == "base"
|
498
|
+
end
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
491
502
|
end
|
492
503
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: frozen_record
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.25.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-06-
|
11
|
+
date: 2022-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- spec/fixtures/cars.yml
|
106
106
|
- spec/fixtures/continents.yml.erb
|
107
107
|
- spec/fixtures/countries.yml.erb
|
108
|
+
- spec/fixtures/prices.yml.erb
|
108
109
|
- spec/fixtures/test_helper/continents.yml.erb
|
109
110
|
- spec/fixtures/test_helper/countries.yml.erb
|
110
111
|
- spec/frozen_record_spec.rb
|
@@ -115,6 +116,7 @@ files:
|
|
115
116
|
- spec/support/car.rb
|
116
117
|
- spec/support/continent.rb
|
117
118
|
- spec/support/country.rb
|
119
|
+
- spec/support/price.rb
|
118
120
|
- spec/test_helper_spec.rb
|
119
121
|
homepage: https://github.com/byroot/frozen_record
|
120
122
|
licenses:
|
@@ -144,6 +146,7 @@ test_files:
|
|
144
146
|
- spec/fixtures/cars.yml
|
145
147
|
- spec/fixtures/continents.yml.erb
|
146
148
|
- spec/fixtures/countries.yml.erb
|
149
|
+
- spec/fixtures/prices.yml.erb
|
147
150
|
- spec/fixtures/test_helper/continents.yml.erb
|
148
151
|
- spec/fixtures/test_helper/countries.yml.erb
|
149
152
|
- spec/frozen_record_spec.rb
|
@@ -154,4 +157,5 @@ test_files:
|
|
154
157
|
- spec/support/car.rb
|
155
158
|
- spec/support/continent.rb
|
156
159
|
- spec/support/country.rb
|
160
|
+
- spec/support/price.rb
|
157
161
|
- spec/test_helper_spec.rb
|