pilipinas 1.1.2 → 1.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/CHANGELOG.md +34 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +33 -30
- data/README.md +1 -1
- data/lib/generators/pilipinas/code_indexes_generator.rb +4 -4
- data/lib/generators/templates/add_pilipinas_code_indexes.rb +5 -5
- data/lib/pilipinas/loader.rb +31 -12
- data/lib/pilipinas/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 04ff6a464b6a25a7b5e47ed3ef768ebef163e2be65421f3bc2e757abf70d8e1d
|
|
4
|
+
data.tar.gz: ba4d5c34f920ad0c764df2fbb932faa0325771bef95c60753065a7a9b895ff74
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fbd098e73fe2b1158946dc2a9076b1b0f402309d5d25689131056c2c9783c9728857c3f840108755fa4c111b7cdb6c6da5872e791dc29edab264bffbdaaff7f8
|
|
7
|
+
data.tar.gz: ab1056dac9fb59bd9c07e2256ce535a5e60acf1bbd5efda3447ac1e4b377542052d20ee31c8f92f7752225723bb67253e8ac0af2961629c3a84efcb7bbc22571
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,38 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
|
+
## [1.1.4] - 2026-06-26
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- `rake pilipinas:load` now wraps the entire seed transaction in `ActiveRecord::Base.uncached` so a long-running Rails process cannot serve stale query-cache hits during seeding.
|
|
15
|
+
- `Loader` clears the per-connection query cache after every `bulk_insert` batch and in the `run` `ensure` block, preventing cached bind-values from accumulating across batches.
|
|
16
|
+
- Batch arrays are now cleared in-place (`batch.clear`) instead of being replaced by a new object, allowing Ruby's GC to reclaim the memory sooner.
|
|
17
|
+
- The full location records table is released in `run`'s `ensure` block so memory is freed even if an exception interrupts seeding.
|
|
18
|
+
|
|
19
|
+
### Dependencies
|
|
20
|
+
|
|
21
|
+
- Updated `json` to 2.19.9.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## [1.1.3] - 2026-06-13
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- `rake pilipinas:load` now upserts ActiveRecord seed rows by `location_id` instead of `code`, matching the stable identifier from `lib/data/pilipinas_data.yml`.
|
|
30
|
+
- `rails generate pilipinas:code_indexes` now generates a migration that adds unique `location_id` indexes to all four `pilipinas_*` tables, matching the loader's upsert conflict target.
|
|
31
|
+
|
|
32
|
+
### Changed
|
|
33
|
+
|
|
34
|
+
- Updated loader upgrade guidance and README wording to reference the required `location_id` unique indexes.
|
|
35
|
+
|
|
36
|
+
### Tests
|
|
37
|
+
|
|
38
|
+
- Added regression coverage that asserts `Loader.bulk_insert` uses `location_id` as the `upsert_all` unique key and reports the matching missing-index guidance.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
10
42
|
## [1.1.2] - 2026-06-12
|
|
11
43
|
|
|
12
44
|
### Fixed
|
|
@@ -94,6 +126,8 @@ Complete rewrite of the gem. Zero runtime dependencies.
|
|
|
94
126
|
- Rails generator for migrations.
|
|
95
127
|
- Railtie for automatic Rake task loading in Rails apps.
|
|
96
128
|
|
|
129
|
+
[1.1.4]: https://github.com/denmarkmeralpis/pilipinas/compare/v1.1.3...v1.1.4
|
|
130
|
+
[1.1.3]: https://github.com/denmarkmeralpis/pilipinas/compare/v1.1.2...v1.1.3
|
|
97
131
|
[1.1.2]: https://github.com/denmarkmeralpis/pilipinas/compare/v1.1.1...v1.1.2
|
|
98
132
|
[1.1.1]: https://github.com/denmarkmeralpis/pilipinas/compare/v1.1.0...v1.1.1
|
|
99
133
|
[1.1.0]: https://github.com/denmarkmeralpis/pilipinas/compare/v1.0.0...v1.1.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
pilipinas (1.1.
|
|
4
|
+
pilipinas (1.1.4)
|
|
5
5
|
|
|
6
6
|
GEM
|
|
7
7
|
remote: https://rubygems.org/
|
|
@@ -48,12 +48,12 @@ GEM
|
|
|
48
48
|
base64 (0.3.0)
|
|
49
49
|
bigdecimal (4.1.2)
|
|
50
50
|
builder (3.3.0)
|
|
51
|
-
concurrent-ruby (1.3.
|
|
51
|
+
concurrent-ruby (1.3.7)
|
|
52
52
|
connection_pool (3.0.2)
|
|
53
53
|
crack (1.0.1)
|
|
54
54
|
bigdecimal
|
|
55
55
|
rexml
|
|
56
|
-
crass (1.0.
|
|
56
|
+
crass (1.0.7)
|
|
57
57
|
date (3.5.1)
|
|
58
58
|
debug (1.11.1)
|
|
59
59
|
irb (~> 1.10)
|
|
@@ -68,7 +68,7 @@ GEM
|
|
|
68
68
|
activesupport (>= 3.0.0)
|
|
69
69
|
railties (>= 3.0.0)
|
|
70
70
|
hashdiff (1.2.1)
|
|
71
|
-
i18n (1.
|
|
71
|
+
i18n (1.15.2)
|
|
72
72
|
concurrent-ruby (~> 1.0)
|
|
73
73
|
io-console (0.8.2)
|
|
74
74
|
irb (1.18.0)
|
|
@@ -76,7 +76,7 @@ GEM
|
|
|
76
76
|
prism (>= 1.3.0)
|
|
77
77
|
rdoc (>= 4.0.0)
|
|
78
78
|
reline (>= 0.4.2)
|
|
79
|
-
json (2.
|
|
79
|
+
json (2.20.0)
|
|
80
80
|
language_server-protocol (3.17.0.5)
|
|
81
81
|
lint_roller (1.1.0)
|
|
82
82
|
logger (1.7.0)
|
|
@@ -86,27 +86,27 @@ GEM
|
|
|
86
86
|
minitest (6.0.6)
|
|
87
87
|
drb (~> 2.0)
|
|
88
88
|
prism (~> 1.5)
|
|
89
|
-
nokogiri (1.19.
|
|
89
|
+
nokogiri (1.19.4-aarch64-linux-gnu)
|
|
90
90
|
racc (~> 1.4)
|
|
91
|
-
nokogiri (1.19.
|
|
91
|
+
nokogiri (1.19.4-aarch64-linux-musl)
|
|
92
92
|
racc (~> 1.4)
|
|
93
|
-
nokogiri (1.19.
|
|
93
|
+
nokogiri (1.19.4-arm-linux-gnu)
|
|
94
94
|
racc (~> 1.4)
|
|
95
|
-
nokogiri (1.19.
|
|
95
|
+
nokogiri (1.19.4-arm-linux-musl)
|
|
96
96
|
racc (~> 1.4)
|
|
97
|
-
nokogiri (1.19.
|
|
97
|
+
nokogiri (1.19.4-arm64-darwin)
|
|
98
98
|
racc (~> 1.4)
|
|
99
|
-
nokogiri (1.19.
|
|
99
|
+
nokogiri (1.19.4-x86_64-darwin)
|
|
100
100
|
racc (~> 1.4)
|
|
101
|
-
nokogiri (1.19.
|
|
101
|
+
nokogiri (1.19.4-x86_64-linux-gnu)
|
|
102
102
|
racc (~> 1.4)
|
|
103
|
-
nokogiri (1.19.
|
|
103
|
+
nokogiri (1.19.4-x86_64-linux-musl)
|
|
104
104
|
racc (~> 1.4)
|
|
105
105
|
parallel (2.1.0)
|
|
106
106
|
parser (3.3.11.1)
|
|
107
107
|
ast (~> 2.4.1)
|
|
108
108
|
racc
|
|
109
|
-
pp (0.6.
|
|
109
|
+
pp (0.6.4)
|
|
110
110
|
prettyprint
|
|
111
111
|
prettyprint (0.2.0)
|
|
112
112
|
prism (1.9.0)
|
|
@@ -162,7 +162,7 @@ GEM
|
|
|
162
162
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
163
163
|
rspec-support (~> 3.13.0)
|
|
164
164
|
rspec-support (3.13.7)
|
|
165
|
-
rubocop (1.
|
|
165
|
+
rubocop (1.88.0)
|
|
166
166
|
json (~> 2.3)
|
|
167
167
|
language_server-protocol (~> 3.17.0.2)
|
|
168
168
|
lint_roller (~> 1.1.0)
|
|
@@ -196,6 +196,7 @@ GEM
|
|
|
196
196
|
simplecov
|
|
197
197
|
terminal-table
|
|
198
198
|
simplecov-html (0.13.2)
|
|
199
|
+
simplecov-lcov (0.9.0)
|
|
199
200
|
simplecov_json_formatter (0.1.4)
|
|
200
201
|
sqlite3 (2.9.5-aarch64-linux-gnu)
|
|
201
202
|
sqlite3 (2.9.5-aarch64-linux-musl)
|
|
@@ -248,6 +249,7 @@ DEPENDENCIES
|
|
|
248
249
|
shoulda-matchers (~> 6.0)
|
|
249
250
|
simplecov (~> 0.22)
|
|
250
251
|
simplecov-console (~> 0.9)
|
|
252
|
+
simplecov-lcov (~> 0.8)
|
|
251
253
|
sqlite3 (~> 2.0)
|
|
252
254
|
webmock
|
|
253
255
|
|
|
@@ -263,10 +265,10 @@ CHECKSUMS
|
|
|
263
265
|
base64 (0.3.0) sha256=27337aeabad6ffae05c265c450490628ef3ebd4b67be58257393227588f5a97b
|
|
264
266
|
bigdecimal (4.1.2) sha256=53d217666027eab4280346fba98e7d5b66baaae1b9c3c1c0ffe89d48188a3fbd
|
|
265
267
|
builder (3.3.0) sha256=497918d2f9dca528fdca4b88d84e4ef4387256d984b8154e9d5d3fe5a9c8835f
|
|
266
|
-
concurrent-ruby (1.3.
|
|
268
|
+
concurrent-ruby (1.3.7) sha256=4412caec3a5ea2e5fdc52076724c071a81f2c0593d83b2ac8cbb8ca63b3151b0
|
|
267
269
|
connection_pool (3.0.2) sha256=33fff5ba71a12d2aa26cb72b1db8bba2a1a01823559fb01d29eb74c286e62e0a
|
|
268
270
|
crack (1.0.1) sha256=ff4a10390cd31d66440b7524eb1841874db86201d5b70032028553130b6d4c7e
|
|
269
|
-
crass (1.0.
|
|
271
|
+
crass (1.0.7) sha256=94868719948664c89ddcaf0a37c65048413dfcb1c869470a5f7a7ceb5390b295
|
|
270
272
|
date (3.5.1) sha256=750d06384d7b9c15d562c76291407d89e368dda4d4fff957eb94962d325a0dc0
|
|
271
273
|
debug (1.11.1) sha256=2e0b0ac6119f2207a6f8ac7d4a73ca8eb4e440f64da0a3136c30343146e952b6
|
|
272
274
|
diff-lcs (1.6.2) sha256=9ae0d2cba7d4df3075fe8cd8602a8604993efc0dfa934cff568969efb1909962
|
|
@@ -277,27 +279,27 @@ CHECKSUMS
|
|
|
277
279
|
erubi (1.13.1) sha256=a082103b0885dbc5ecf1172fede897f9ebdb745a4b97a5e8dc63953db1ee4ad9
|
|
278
280
|
generator_spec (0.10.0) sha256=4343152308dcfb30bba7583fc0e79acf8c626597686cfe3e9b168f6ab745b37a
|
|
279
281
|
hashdiff (1.2.1) sha256=9c079dbc513dfc8833ab59c0c2d8f230fa28499cc5efb4b8dd276cf931457cd1
|
|
280
|
-
i18n (1.
|
|
282
|
+
i18n (1.15.2) sha256=00f9eb62412fe593b2a65a97daa75300d37abb8f7202ec748e94b6d46a9dd1b5
|
|
281
283
|
io-console (0.8.2) sha256=d6e3ae7a7cc7574f4b8893b4fca2162e57a825b223a177b7afa236c5ef9814cc
|
|
282
284
|
irb (1.18.0) sha256=de9454a0703a54704b9811a5ef31a60c86949fbf4013fcf244fabc7c775248e3
|
|
283
|
-
json (2.
|
|
285
|
+
json (2.20.0) sha256=9362bc6e55a952b056abf9167cf053358181c904cb70cd6eee0808ea830fc32b
|
|
284
286
|
language_server-protocol (3.17.0.5) sha256=fd1e39a51a28bf3eec959379985a72e296e9f9acfce46f6a79d31ca8760803cc
|
|
285
287
|
lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
|
|
286
288
|
logger (1.7.0) sha256=196edec7cc44b66cfb40f9755ce11b392f21f7967696af15d274dde7edff0203
|
|
287
289
|
loofah (2.25.1) sha256=d436c73dbd0c1147b16c4a41db097942d217303e1f7728704b37e4df9f6d2e04
|
|
288
290
|
minitest (6.0.6) sha256=153ea36d1d987a62942382b61075745042a2b3123b1cd48f4c3675af9cc7d6f1
|
|
289
|
-
nokogiri (1.19.
|
|
290
|
-
nokogiri (1.19.
|
|
291
|
-
nokogiri (1.19.
|
|
292
|
-
nokogiri (1.19.
|
|
293
|
-
nokogiri (1.19.
|
|
294
|
-
nokogiri (1.19.
|
|
295
|
-
nokogiri (1.19.
|
|
296
|
-
nokogiri (1.19.
|
|
291
|
+
nokogiri (1.19.4-aarch64-linux-gnu) sha256=1269fb644a6de405057a53dd5c762b1209b43ca7424f839454d3dbc677c31a8f
|
|
292
|
+
nokogiri (1.19.4-aarch64-linux-musl) sha256=35c65b9ce72b3bb03207bdbe7067915019dc18c1b9b59139684bd6690fdd01af
|
|
293
|
+
nokogiri (1.19.4-arm-linux-gnu) sha256=a301313e38bb065d68239e79734bcd6f56fb6efaacebde29e9abf2a4735340ca
|
|
294
|
+
nokogiri (1.19.4-arm-linux-musl) sha256=588923c101bcfa78869734d247d25b598674323e7f22474fc468f6e5647311eb
|
|
295
|
+
nokogiri (1.19.4-arm64-darwin) sha256=a46db9853286e6597b36ebc6953817d15acf3a299583eb3f89fdc6f91dd63527
|
|
296
|
+
nokogiri (1.19.4-x86_64-darwin) sha256=7fd17057d3e1f00e9954a74b3cd76595d3d4a5ef233b7ed9599047c204f70551
|
|
297
|
+
nokogiri (1.19.4-x86_64-linux-gnu) sha256=379fae440b28915e3f19d752ce2dcf8465ed2b2fbefd2a7ca0dd497bc981a06a
|
|
298
|
+
nokogiri (1.19.4-x86_64-linux-musl) sha256=17dfb7c1fa194ae02fbf7c51a7afc8d278045ab3fdacfd86f91d02d7b274470b
|
|
297
299
|
parallel (2.1.0) sha256=b35258865c2e31134c5ecb708beaaf6772adf9d5efae28e93e99260877b09356
|
|
298
300
|
parser (3.3.11.1) sha256=d17ace7aabe3e72c3cc94043714be27cc6f852f104d81aa284c2281aecc65d54
|
|
299
|
-
pilipinas (1.1.
|
|
300
|
-
pp (0.6.
|
|
301
|
+
pilipinas (1.1.4)
|
|
302
|
+
pp (0.6.4) sha256=dfcb0fce700c41456265922884f9fe195d7fbb0674a3578e6c0f69588e82b570
|
|
301
303
|
prettyprint (0.2.0) sha256=2bc9e15581a94742064a3cc8b0fb9d45aae3d03a1baa6ef80922627a0766f193
|
|
302
304
|
prism (1.9.0) sha256=7b530c6a9f92c24300014919c9dcbc055bf4cdf51ec30aed099b06cd6674ef85
|
|
303
305
|
psych (5.4.0) sha256=14f72d69a611af663d7d70e4a7b67d9eb1f3ae9f8d916b478961d5a0075ba5b7
|
|
@@ -321,7 +323,7 @@ CHECKSUMS
|
|
|
321
323
|
rspec-expectations (3.13.5) sha256=33a4d3a1d95060aea4c94e9f237030a8f9eae5615e9bd85718fe3a09e4b58836
|
|
322
324
|
rspec-mocks (3.13.8) sha256=086ad3d3d17533f4237643de0b5c42f04b66348c28bf6b9c2d3f4a3b01af1d47
|
|
323
325
|
rspec-support (3.13.7) sha256=0640e5570872aafefd79867901deeeeb40b0c9875a36b983d85f54fb7381c47c
|
|
324
|
-
rubocop (1.
|
|
326
|
+
rubocop (1.88.0) sha256=e420ddf1662d0ef34bc8a2910ac4b396a7ddda0b51a708264405241734b08e0b
|
|
325
327
|
rubocop-ast (1.49.1) sha256=4412f3ee70f6fe4546cc489548e0f6fcf76cafcfa80fa03af67098ffed755035
|
|
326
328
|
rubocop-rake (0.7.1) sha256=3797f2b6810c3e9df7376c26d5f44f3475eda59eb1adc38e6f62ecf027cbae4d
|
|
327
329
|
rubocop-rspec (3.10.2) sha256=0b3e2ecc592cd10ecbf0095bb58d1e357905276e069643523cc19eb7495f65e2
|
|
@@ -331,6 +333,7 @@ CHECKSUMS
|
|
|
331
333
|
simplecov (0.22.0) sha256=fe2622c7834ff23b98066bb0a854284b2729a569ac659f82621fc22ef36213a5
|
|
332
334
|
simplecov-console (0.9.5) sha256=b1108bcfff5f210143e2b8301698c367b01586f20d25a73e95475a5df6fc6ff6
|
|
333
335
|
simplecov-html (0.13.2) sha256=bd0b8e54e7c2d7685927e8d6286466359b6f16b18cb0df47b508e8d73c777246
|
|
336
|
+
simplecov-lcov (0.9.0) sha256=7a77a31e200a595ed4b0249493056efd0c920601f53d2ef135ca34ee796346cd
|
|
334
337
|
simplecov_json_formatter (0.1.4) sha256=529418fbe8de1713ac2b2d612aa3daa56d316975d307244399fa4838c601b428
|
|
335
338
|
sqlite3 (2.9.5-aarch64-linux-gnu) sha256=78075b6337d3d182c6d2b4691049ed45cd220826160c9ea18946bf6a1de200dc
|
|
336
339
|
sqlite3 (2.9.5-aarch64-linux-musl) sha256=18c801185deb4adc01ddb281e8f672a39e3d1729979ca91e39439cd3eac0402d
|
data/README.md
CHANGED
|
@@ -177,7 +177,7 @@ rake pilipinas:load
|
|
|
177
177
|
> **Upgrading from an older version?**
|
|
178
178
|
>
|
|
179
179
|
> If `rake pilipinas:load` raises
|
|
180
|
-
> `Pilipinas::Error: pilipinas:load requires a unique index on the
|
|
180
|
+
> `Pilipinas::Error: pilipinas:load requires a unique index on the location_id column`,
|
|
181
181
|
> your database was created with an earlier migration that did not include those
|
|
182
182
|
> indexes. Add them with the dedicated generator:
|
|
183
183
|
>
|
|
@@ -4,13 +4,13 @@ require 'rails/generators/base'
|
|
|
4
4
|
require 'rails/generators/active_record'
|
|
5
5
|
|
|
6
6
|
module Pilipinas
|
|
7
|
-
# Rails generator that adds unique indexes on the +
|
|
8
|
-
# pilipinas_* tables.
|
|
7
|
+
# Rails generator that adds unique indexes on the +location_id+ column to all
|
|
8
|
+
# four pilipinas_* tables.
|
|
9
9
|
#
|
|
10
10
|
# Run this if your database was created with an older version of the gem
|
|
11
11
|
# that did not include these indexes, and +rake pilipinas:load+ raises:
|
|
12
12
|
#
|
|
13
|
-
# ArgumentError: No unique index found for
|
|
13
|
+
# ArgumentError: No unique index found for location_id
|
|
14
14
|
#
|
|
15
15
|
# @example
|
|
16
16
|
# rails generate pilipinas:code_indexes
|
|
@@ -23,7 +23,7 @@ module Pilipinas
|
|
|
23
23
|
|
|
24
24
|
def generate_migration
|
|
25
25
|
migration_template 'templates/add_pilipinas_code_indexes.rb',
|
|
26
|
-
'db/migrate/
|
|
26
|
+
'db/migrate/add_pilipinas_location_id_indexes.rb'
|
|
27
27
|
end
|
|
28
28
|
|
|
29
29
|
# @param _dir [String] unused (required by the interface)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
class
|
|
1
|
+
class AddPilipinasLocationIdIndexes < ActiveRecord::Migration<%= migration_version %>
|
|
2
2
|
def change
|
|
3
|
-
add_index :pilipinas_regions, :
|
|
4
|
-
add_index :pilipinas_provinces, :
|
|
5
|
-
add_index :pilipinas_cities, :
|
|
6
|
-
add_index :pilipinas_barangays, :
|
|
3
|
+
add_index :pilipinas_regions, :location_id, unique: true, if_not_exists: true
|
|
4
|
+
add_index :pilipinas_provinces, :location_id, unique: true, if_not_exists: true
|
|
5
|
+
add_index :pilipinas_cities, :location_id, unique: true, if_not_exists: true
|
|
6
|
+
add_index :pilipinas_barangays, :location_id, unique: true, if_not_exists: true
|
|
7
7
|
end
|
|
8
8
|
end
|
data/lib/pilipinas/loader.rb
CHANGED
|
@@ -42,15 +42,21 @@ module Pilipinas
|
|
|
42
42
|
#
|
|
43
43
|
# @return [void]
|
|
44
44
|
def run
|
|
45
|
+
records = nil
|
|
45
46
|
column_indexes, records = full_location_table
|
|
46
47
|
|
|
47
|
-
ActiveRecord::Base.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
ActiveRecord::Base.uncached do
|
|
49
|
+
ActiveRecord::Base.transaction do
|
|
50
|
+
FULL_DATA_SEEDS.each do |model_name, type, attributes|
|
|
51
|
+
model = Db.const_get(model_name)
|
|
52
|
+
delete_stale_compact_rows(model)
|
|
53
|
+
seed_full_data(model, records, column_indexes, type, attributes)
|
|
54
|
+
end
|
|
52
55
|
end
|
|
53
56
|
end
|
|
57
|
+
ensure
|
|
58
|
+
records&.clear
|
|
59
|
+
clear_query_cache
|
|
54
60
|
end
|
|
55
61
|
|
|
56
62
|
private
|
|
@@ -92,10 +98,11 @@ module Pilipinas
|
|
|
92
98
|
next if batch.size < BATCH_SIZE
|
|
93
99
|
|
|
94
100
|
bulk_insert(model, batch)
|
|
95
|
-
batch
|
|
101
|
+
batch.clear
|
|
96
102
|
end
|
|
97
103
|
|
|
98
104
|
bulk_insert(model, batch) unless batch.empty?
|
|
105
|
+
batch.clear
|
|
99
106
|
end
|
|
100
107
|
|
|
101
108
|
# @param record [Array] full location dump row
|
|
@@ -135,16 +142,17 @@ module Pilipinas
|
|
|
135
142
|
records.each_slice(BATCH_SIZE) do |slice|
|
|
136
143
|
batch = slice.map { |r| r.transform_keys(&:to_s).merge('created_at' => now, 'updated_at' => now) }
|
|
137
144
|
bulk_insert(model, batch)
|
|
145
|
+
batch.clear
|
|
138
146
|
end
|
|
139
147
|
end
|
|
140
148
|
|
|
141
149
|
# Perform the most capable bulk-insert available for this AR version.
|
|
142
150
|
#
|
|
143
151
|
# +upsert_all+ (Rails 6.1+) is idempotent — it updates existing rows
|
|
144
|
-
# matched by the unique index on +
|
|
145
|
-
#
|
|
146
|
-
#
|
|
147
|
-
#
|
|
152
|
+
# matched by the unique index on +location_id+, the stable identifier in
|
|
153
|
+
# the full location dump. Compact rows from older loader versions have a
|
|
154
|
+
# NULL +location_id+ and are deleted before the canonical full-data rows
|
|
155
|
+
# are inserted.
|
|
148
156
|
#
|
|
149
157
|
# +insert_all+ (Rails 6.0) silently skips conflicts.
|
|
150
158
|
# Legacy path: individual +create!+ calls (raises on conflict).
|
|
@@ -155,10 +163,10 @@ module Pilipinas
|
|
|
155
163
|
def bulk_insert(model, batch)
|
|
156
164
|
if model.respond_to?(:upsert_all)
|
|
157
165
|
begin
|
|
158
|
-
model.upsert_all(batch, unique_by: :
|
|
166
|
+
model.upsert_all(batch, unique_by: :location_id)
|
|
159
167
|
rescue ArgumentError
|
|
160
168
|
raise Pilipinas::Error,
|
|
161
|
-
'pilipinas:load requires a unique index on the `
|
|
169
|
+
'pilipinas:load requires a unique index on the `location_id` column, ' \
|
|
162
170
|
"which is missing from #{model.table_name}. " \
|
|
163
171
|
'Your database was likely created with an older version of the gem. ' \
|
|
164
172
|
"Run the following to add the missing indexes and retry:\n\n " \
|
|
@@ -170,6 +178,17 @@ module Pilipinas
|
|
|
170
178
|
else
|
|
171
179
|
batch.each { |attrs| model.unscoped.create!(attrs) }
|
|
172
180
|
end
|
|
181
|
+
ensure
|
|
182
|
+
clear_query_cache
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
# Clear any per-connection query-cache state so a long-running Rails
|
|
186
|
+
# process does not retain loader queries or bind values between batches.
|
|
187
|
+
#
|
|
188
|
+
# @return [void]
|
|
189
|
+
def clear_query_cache
|
|
190
|
+
connection = ActiveRecord::Base.connection
|
|
191
|
+
connection.clear_query_cache if connection.respond_to?(:clear_query_cache)
|
|
173
192
|
end
|
|
174
193
|
|
|
175
194
|
# @return [Time] current UTC time, compatible with or without ActiveSupport
|
data/lib/pilipinas/version.rb
CHANGED