occams-record 1.1.4 → 1.1.5
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 +11 -1
- data/lib/occams-record/batches.rb +9 -3
- data/lib/occams-record/eager_loaders/belongs_to.rb +1 -0
- data/lib/occams-record/eager_loaders/has_one.rb +1 -0
- data/lib/occams-record/eager_loaders/polymorphic_belongs_to.rb +1 -0
- data/lib/occams-record/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 216f5b9aff38034e5bcaab036d4a5a20add7053062546eb827bd12269d49c766
|
|
4
|
+
data.tar.gz: f481e52c6d3390b7a3f5aa7497ac15d78774ef93f5d295dca472c75f558db9d2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ee45536cbf4ea6a317647e73ac30788416bebfb3b152350fdcb4ab7d6e6e747ef1eb1763ef2aec731e11a9fb5925a8b234787933418c8c74f0724dd3b1ee1b9e
|
|
7
|
+
data.tar.gz: 30ab20cdd8611e0fec40a7a2e1b3d516ac153a5d283a393860650588c2d6f1bc93f02c43f125bb1675824ef019a29e276a05e0900899e311b838eab87a186db4
|
data/README.md
CHANGED
|
@@ -297,15 +297,25 @@ bundle install
|
|
|
297
297
|
bundle exec rake test
|
|
298
298
|
```
|
|
299
299
|
|
|
300
|
+
**Specify ActiveRecord version**
|
|
301
|
+
|
|
300
302
|
By default, bundler will install the latest (supported) version of ActiveRecord. To specify a version to test against, run:
|
|
301
303
|
|
|
302
304
|
```bash
|
|
303
305
|
AR=5.2 bundle update activerecord
|
|
304
|
-
bundle exec rake test
|
|
306
|
+
AR=5.2 bundle exec rake test
|
|
305
307
|
```
|
|
306
308
|
|
|
307
309
|
Look inside `Gemfile` to see all testable versions.
|
|
308
310
|
|
|
311
|
+
**Run against Postgres**
|
|
312
|
+
|
|
313
|
+
By default the tests run against an in-memory Sqlite3 database. Use the following env var to force running against a Postgres database:
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
TEST_DATABASE_URL=postgres://postgres@localhost:5432/occams_record bundle exec rake test
|
|
317
|
+
```
|
|
318
|
+
|
|
309
319
|
# License
|
|
310
320
|
|
|
311
321
|
MIT License. See LICENSE for details.
|
|
@@ -7,8 +7,9 @@ module OccamsRecord
|
|
|
7
7
|
# Load records in batches of N and yield each record to a block if given. If no block is given,
|
|
8
8
|
# returns an Enumerator.
|
|
9
9
|
#
|
|
10
|
-
# NOTE Unlike ActiveRecord's find_each, ORDER BY is respected.
|
|
11
|
-
#
|
|
10
|
+
# NOTE Unlike ActiveRecord's find_each, ORDER BY is respected. The primary key will be appended
|
|
11
|
+
# to the ORDER BY clause to help ensure consistent batches. Additionally, it will be run inside
|
|
12
|
+
# of a transaction.
|
|
12
13
|
#
|
|
13
14
|
# @param batch_size [Integer]
|
|
14
15
|
# @param use_transaction [Boolean] Ensure it runs inside of a database transaction
|
|
@@ -80,10 +81,15 @@ module OccamsRecord
|
|
|
80
81
|
|
|
81
82
|
offset = scope.offset_value || 0
|
|
82
83
|
out_of_records, count = false, 0
|
|
84
|
+
pkey_regex = /#{model.primary_key}|\*/ # NOTE imperfect
|
|
85
|
+
order_by_pkey = !!model.primary_key &&
|
|
86
|
+
(scope.select_values.empty? || scope.select_values.any? { |v| v.to_s =~ pkey_regex })
|
|
83
87
|
|
|
84
88
|
until out_of_records
|
|
85
89
|
l = limit && batch_size > limit - count ? limit - count : batch_size
|
|
86
|
-
q = scope
|
|
90
|
+
q = scope
|
|
91
|
+
q = q.order(model.primary_key.to_sym) if order_by_pkey
|
|
92
|
+
q = q.offset(offset).limit(l)
|
|
87
93
|
results = Query.new(q, use: @use, query_logger: @query_logger, eager_loaders: @eager_loaders).run
|
|
88
94
|
|
|
89
95
|
y.yield results if results.any?
|
|
@@ -55,6 +55,7 @@ module OccamsRecord
|
|
|
55
55
|
next if type.nil? or type == ""
|
|
56
56
|
model = type.constantize
|
|
57
57
|
ids = rows_of_type.map(&@foreign_key).uniq
|
|
58
|
+
ids.sort! if $occams_record_test
|
|
58
59
|
q = base_scope(model).where(@ref.active_record_primary_key => ids)
|
|
59
60
|
yield q if ids.any?
|
|
60
61
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: occams-record
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.1.
|
|
4
|
+
version: 1.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jordan Hollinger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-05-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -81,8 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
83
|
requirements: []
|
|
84
|
-
|
|
85
|
-
rubygems_version: 2.7.6.2
|
|
84
|
+
rubygems_version: 3.0.3
|
|
86
85
|
signing_key:
|
|
87
86
|
specification_version: 4
|
|
88
87
|
summary: The missing high-efficiency query API for ActiveRecord
|