2025-01-20 10:37:15 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
class Points::CreateJob < ApplicationJob
|
|
|
|
|
queue_as :default
|
|
|
|
|
|
|
|
|
|
def perform(params, user_id)
|
2025-01-20 11:59:13 -05:00
|
|
|
data = Points::Params.new(params, user_id).call
|
2025-01-20 10:37:15 -05:00
|
|
|
|
2025-01-20 11:59:13 -05:00
|
|
|
data.each_slice(1000) do |location_batch|
|
|
|
|
|
Point.upsert_all(
|
|
|
|
|
location_batch,
|
|
|
|
|
unique_by: %i[latitude longitude timestamp user_id]
|
|
|
|
|
)
|
2025-01-20 10:37:15 -05:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def point_exists?(params, user_id)
|
|
|
|
|
Point.exists?(
|
|
|
|
|
latitude: params[:latitude],
|
|
|
|
|
longitude: params[:longitude],
|
|
|
|
|
timestamp: params[:timestamp],
|
|
|
|
|
user_id:
|
|
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
end
|