Skip to content

Commit 3c31f6c

Browse files
committed
Use new index to simplify least new postcode collection
1 parent 63901af commit 3c31f6c

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

app/workers/postcodes_collection_worker.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ def perform
1212

1313
def postcodes
1414
Postcode.uncached do
15-
onspd_candidates = Postcode.onspd.active.order("updated_at ASC").select { |r| r.results.first["ONS"]["TYPE"] == "S" }.first(POSTCODES_PER_SECOND)
16-
os_places_candidates = Postcode.os_places.order("updated_at ASC").first(POSTCODES_PER_SECOND)
17-
(onspd_candidates + os_places_candidates).sort_by(&:updated_at).first(POSTCODES_PER_SECOND).pluck(:postcode)
15+
Postcode.active.small.order("updated_at ASC").limit(POSTCODES_PER_SECOND).pluck(:postcode)
1816
end
1917
end
2018
end

spec/workers/postcodes_collection_worker_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
context "when an ONSPD small active postcode is older than the oldest OS Places postcode" do
2222
before do
23-
Postcode.create(postcode: "E12AA", source: "onspd", updated_at: 3.days.ago, results: [{ "ONS" => { "TYPE" => "S" } }])
23+
Postcode.create(postcode: "E12AA", source: "onspd", updated_at: 3.days.ago)
2424
end
2525

2626
it "adds the onspd postcode to the update checker" do
@@ -35,7 +35,7 @@
3535

3636
context "when an ONSPD small retired postcode is older than the oldest OS Places postcode" do
3737
before do
38-
Postcode.create(postcode: "E12AA", source: "onspd", updated_at: 3.days.ago, results: [{ "ONS" => { "TYPE" => "S" } }], retired: true)
38+
Postcode.create(postcode: "E12AA", source: "onspd", updated_at: 3.days.ago, retired: true)
3939
end
4040

4141
it "does not attempt to update the ONSPD postcode" do
@@ -47,7 +47,7 @@
4747

4848
context "when an ONSPD large active postcode is older than the oldest OS Places postcode" do
4949
before do
50-
Postcode.create(postcode: "E12AA", source: "onspd", updated_at: 3.days.ago, results: [{ "ONS" => { "TYPE" => "L" } }])
50+
Postcode.create(postcode: "E12AA", source: "onspd", updated_at: 3.days.ago, large_user_postcode: true)
5151
end
5252

5353
it "does not attempt to update the ONSPD postcode" do

0 commit comments

Comments
 (0)