mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 17:21:38 -05:00
32 lines
709 B
Ruby
32 lines
709 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Points::Create
|
|
attr_reader :user, :params
|
|
|
|
def initialize(user, params)
|
|
@user = user
|
|
@params = params
|
|
end
|
|
|
|
# rubocop:disable Metrics/MethodLength
|
|
def call
|
|
data = Points::Params.new(params, user.id).call
|
|
|
|
created_points = []
|
|
|
|
data.each_slice(1000) do |location_batch|
|
|
# rubocop:disable Rails/SkipsModelValidations
|
|
result = Point.upsert_all(
|
|
location_batch,
|
|
unique_by: %i[lonlat timestamp user_id],
|
|
returning: %i[id lonlat timestamp]
|
|
)
|
|
# rubocop:enable Rails/SkipsModelValidations
|
|
|
|
created_points.concat(result)
|
|
end
|
|
|
|
created_points
|
|
end
|
|
# rubocop:enable Metrics/MethodLength
|
|
end
|