Updates
This commit is contained in:
@@ -211,7 +211,7 @@ class GeoliteCountryImporter
|
||||
location_data = @locations_cache[geoname_id] || @locations_cache[registered_country_geoname_id] || {}
|
||||
|
||||
# Store raw GeoLite country data in network_data[:geolite]
|
||||
geolite_data = {
|
||||
geolite_country_data = {
|
||||
country: {
|
||||
geoname_id: geoname_id,
|
||||
registered_country_geoname_id: registered_country_geoname_id,
|
||||
@@ -227,16 +227,29 @@ class GeoliteCountryImporter
|
||||
}
|
||||
}.compact
|
||||
|
||||
# Use upsert with JSONB merge
|
||||
# COALESCE handles the case where network_data might be NULL
|
||||
# || is PostgreSQL's JSONB concatenation/merge operator
|
||||
NetworkRange.upsert(
|
||||
{
|
||||
network: network,
|
||||
country: location_data[:country_iso_code],
|
||||
is_proxy: is_anonymous_proxy,
|
||||
source: 'geolite_country',
|
||||
network_data: { geolite: geolite_data },
|
||||
network_data: { geolite: geolite_country_data },
|
||||
updated_at: Time.current
|
||||
},
|
||||
unique_by: :index_network_ranges_on_network_unique
|
||||
unique_by: :index_network_ranges_on_network_unique,
|
||||
on_duplicate: Arel.sql("
|
||||
country = EXCLUDED.country,
|
||||
is_proxy = EXCLUDED.is_proxy,
|
||||
network_data = COALESCE(network_ranges.network_data, '{}'::jsonb) ||
|
||||
jsonb_build_object('geolite',
|
||||
COALESCE(network_ranges.network_data->'geolite', '{}'::jsonb) ||
|
||||
EXCLUDED.network_data->'geolite'
|
||||
),
|
||||
updated_at = EXCLUDED.updated_at
|
||||
")
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user