Compare commits

...

4 commits

Author SHA1 Message Date
Eugene Burmakin
43bc8c444c Fix name fetcher 2025-07-12 17:57:22 +02:00
Eugene Burmakin
6b96e1f0be Revert specs 2025-07-12 17:21:53 +02:00
Eugene Burmakin
0dff80e12b Fix some tests 2025-07-12 13:43:15 +02:00
Eugene Burmakin
58a7972976 Fix bulk name fetching job queue 2025-07-12 11:30:51 +02:00
10 changed files with 31 additions and 18 deletions

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class AreaVisitsCalculatingJob < ApplicationJob class AreaVisitsCalculatingJob < ApplicationJob
queue_as :default queue_as :visit_suggesting
sidekiq_options retry: false sidekiq_options retry: false
def perform(user_id) def perform(user_id)

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class AreaVisitsCalculationSchedulingJob < ApplicationJob class AreaVisitsCalculationSchedulingJob < ApplicationJob
queue_as :default queue_as :visit_suggesting
sidekiq_options retry: false sidekiq_options retry: false
def perform def perform

View file

@ -1,7 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
class Places::BulkNameFetchingJob < ApplicationJob class Places::BulkNameFetchingJob < ApplicationJob
queue_as :default queue_as :places
def perform def perform
Place.where(name: Place::DEFAULT_NAME).find_each do |place| Place.where(name: Place::DEFAULT_NAME).find_each do |place|

View file

@ -92,6 +92,9 @@ class Point < ApplicationRecord
end end
def country_name def country_name
# We have a country column in the database,
# but we also have a country_id column.
# TODO: rename country column to country_name
self.country&.name || read_attribute(:country) || '' self.country&.name || read_attribute(:country) || ''
end end

View file

@ -15,16 +15,18 @@ module Places
return if properties.blank? return if properties.blank?
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
@place.name = properties['name'] @place.name = properties['name'] if properties['name'].present?
@place.city = properties['city'] @place.city = properties['city'] if properties['city'].present?
@place.country = properties['country'] @place.country = properties['country'] if properties['country'].present?
@place.geodata = geodata.data if DawarichSettings.store_geodata? @place.geodata = geodata.data if DawarichSettings.store_geodata?
@place.save! @place.save!
@place if properties['name'].present?
.visits @place
.where(name: Place::DEFAULT_NAME) .visits
.update_all(name: properties['name']) .where(name: Place::DEFAULT_NAME)
.update_all(name: properties['name'])
end
@place @place
end end

View file

@ -37,5 +37,5 @@ tracks_bulk_creating_job:
place_name_fetching_job: place_name_fetching_job:
cron: "30 0 * * *" # every day at 00:30 cron: "30 0 * * *" # every day at 00:30
class: "Places::NameFetchingJob" class: "Places::BulkNameFetchingJob"
queue: places queue: places

View file

@ -4,13 +4,13 @@ require 'rails_helper'
RSpec.describe AreaVisitsCalculationSchedulingJob, type: :job do RSpec.describe AreaVisitsCalculationSchedulingJob, type: :job do
describe '#perform' do describe '#perform' do
let(:area) { create(:area) } let!(:user) { create(:user) }
let(:user) { create(:user) } let!(:area) { create(:area, user: user) }
it 'calls the AreaVisitsCalculationService' do it 'calls the AreaVisitsCalculationService' do
expect(AreaVisitsCalculatingJob).to receive(:perform_later).with(user.id).and_call_original expect(AreaVisitsCalculatingJob).to receive(:perform_later).with(user.id)
described_class.new.perform described_class.new.perform_now
end end
end end
end end

View file

@ -20,7 +20,7 @@ RSpec.describe Places::BulkNameFetchingJob, type: :job do
it 'can be enqueued' do it 'can be enqueued' do
expect { described_class.perform_later }.to have_enqueued_job(described_class) expect { described_class.perform_later }.to have_enqueued_job(described_class)
.on_queue('default') .on_queue('places')
end end
end end
end end

View file

@ -40,8 +40,10 @@ RSpec.configure do |config|
config.rswag_dry_run = false config.rswag_dry_run = false
config.before(:suite) do config.before(:suite) do
# Ensure Rails routes are loaded for Devise
Rails.application.reload_routes! Rails.application.reload_routes!
# DatabaseCleaner.strategy = :transaction
# DatabaseCleaner.clean_with(:truncation)
end end
config.before do config.before do
@ -90,6 +92,12 @@ RSpec.configure do |config|
config.after(:suite) do config.after(:suite) do
Rake::Task['rswag:generate'].invoke Rake::Task['rswag:generate'].invoke
end end
# config.around(:each) do |example|
# DatabaseCleaner.cleaning do
# example.run
# end
# end
end end
Shoulda::Matchers.configure do |config| Shoulda::Matchers.configure do |config|

View file

@ -29,7 +29,7 @@ RSpec.describe PointSerializer do
'inrids' => point.inrids, 'inrids' => point.inrids,
'in_regions' => point.in_regions, 'in_regions' => point.in_regions,
'city' => point.city, 'city' => point.city,
'country' => point.country, 'country' => point.read_attribute(:country),
'geodata' => point.geodata, 'geodata' => point.geodata,
'course' => point.course, 'course' => point.course,
'course_accuracy' => point.course_accuracy, 'course_accuracy' => point.course_accuracy,