Skip to content

Commit

Permalink
Move setting reverse_geocoded_at to background job
Browse files Browse the repository at this point in the history
  • Loading branch information
Freika committed Dec 16, 2024
1 parent 5e3f5a7 commit 3554e40
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .app_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.20.0
0.20.1
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

# 0.20.1 - 2024-12-16

### Fixed

- Setting `reverse_geocoded_at` for points that don't have geodata is now being performed in background job, in batches of 10,000 points to prevent memory exhaustion.

# 0.20.0 - 2024-12-16

### Added
Expand Down
17 changes: 17 additions & 0 deletions app/jobs/data_migrations/set_reverse_geocoded_at_for_points_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

class DataMigrations::SetReverseGeocodedAtForPointsJob < ApplicationJob
queue_as :default

def perform
timestamp = Time.current

Point.where.not(geodata: {})
.where(reverse_geocoded_at: nil)
.in_batches(of: 10_000) do |relation|
# rubocop:disable Rails/SkipsModelValidations
relation.update_all(reverse_geocoded_at: timestamp)
# rubocop:enable Rails/SkipsModelValidations
end
end
end
4 changes: 1 addition & 3 deletions db/data/20241202125248_set_reverse_geocoded_at_for_points.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

class SetReverseGeocodedAtForPoints < ActiveRecord::Migration[7.2]
def up
# rubocop:disable Rails/SkipsModelValidations
Point.where.not(geodata: {}).update_all(reverse_geocoded_at: Time.current)
# rubocop:enable Rails/SkipsModelValidations
DataMigrations::SetReverseGeocodedAtForPointsJob.perform_later
end

def down
Expand Down

0 comments on commit 3554e40

Please sign in to comment.