mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 18:56:05 +02:00
Story#108602614 - optimize contacts history import
This commit is contained in:
parent
b75b35f554
commit
1fb0259806
6 changed files with 35 additions and 14 deletions
|
@ -28,7 +28,7 @@ module Legacy
|
|||
ident_type: ::Legacy::Contact::IDENT_TYPE_MAP[x.ssntype],
|
||||
auth_info: x.object_history.authinfopw.try(:strip),
|
||||
name: name,
|
||||
registrar_id: ::Registrar.find_by(legacy_id: x.object_history.try(:clid)).try(:id),
|
||||
registrar_id: ::Legacy::Domain.new_registrar_cached(x.object_history.try(:clid)).try(:id),
|
||||
creator_str: x.object_registry.try(:registrar).try(:name),
|
||||
updator_str: x.object_history.try(:registrar).try(:name) ? x.object_history.try(:registrar).try(:name) : x.object_registry.try(:registrar).try(:name),
|
||||
legacy_id: x.id,
|
||||
|
@ -43,13 +43,13 @@ module Legacy
|
|||
|
||||
class << self
|
||||
def changes_dates_for domain_id
|
||||
sql = %Q{SELECT dh.*, valid_from
|
||||
sql = %Q{SELECT dh.historyid, valid_from, valid_to
|
||||
FROM contact_history dh JOIN history h ON dh.historyid=h.id where dh.id=#{domain_id};}
|
||||
# find_by_sql(sql).map{|e| e.attributes.values_at("valid_from") }.flatten.each_with_object({}){|e,h|h[e.try(:to_f)] = [self]}
|
||||
|
||||
hash = {}
|
||||
find_by_sql(sql).each do |rec|
|
||||
hash[rec.valid_from.try(:to_time)] = [{id: rec.historyid, klass: self, param: :valid_from}] if rec.valid_from
|
||||
hash[rec.valid_to.try(:to_time)] = [{id: rec.historyid, klass: self, param: :valid_to}] if rec.valid_to
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
|
|
@ -25,5 +25,10 @@ module Legacy
|
|||
# OK status is default
|
||||
domain_statuses << DomainStatus::OK if domain_statuses.empty?
|
||||
end
|
||||
|
||||
def self.new_registrar_cached old_id
|
||||
@new_registrar_cache ||= {}
|
||||
@new_registrar_cache[old_id] ||= ::Registrar.select(:id).find_by(legacy_id: old_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,7 +18,7 @@ module Legacy
|
|||
x = self
|
||||
{
|
||||
name: SimpleIDN.to_unicode(x.object_registry.name.try(:strip)),
|
||||
registrar_id: ::Registrar.find_by(legacy_id: x.object_history.try(:clid)).try(:id),
|
||||
registrar_id: ::Legacy::Domain.new_registrar_cached(x.object_history.try(:clid)).try(:id),
|
||||
registrant_id: new_registrant_id,
|
||||
registered_at: x.object_registry.try(:crdate),
|
||||
valid_from: x.object_registry.try(:crdate),
|
||||
|
@ -55,7 +55,7 @@ module Legacy
|
|||
def user
|
||||
@user ||= begin
|
||||
obj_his = Legacy::ObjectHistory.find_by(historyid: historyid)
|
||||
Registrar.find_by(legacy_id: obj_his.upid || obj_his.clid).try(:api_users).try(:first)
|
||||
Legacy::Domain.new_registrar_cached(obj_his.upid || obj_his.clid).try(:api_users).try(:first)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -97,7 +97,10 @@ module Legacy
|
|||
ids << val
|
||||
else # if not found we should check current dnssec and historical if changes were done
|
||||
# firstly we need to select the first historical object to take the earliest from create or destroy
|
||||
if version = ::NameserverVersion.where("object->>'domain_id'='#{main_attrs[:domain_id]}'").where("object->>'legacy_domain_id'='#{main_attrs[:legacy_domain_id]}'").where("object->>'hostname'='#{main_attrs[:hostname]}'").reorder("created_at ASC").first
|
||||
if version = ::NameserverVersion.where("object->>'domain_id'='#{main_attrs[:domain_id]}'").
|
||||
where("object->>'legacy_domain_id'='#{main_attrs[:legacy_domain_id]}'").
|
||||
where("object->>'hostname'='#{main_attrs[:hostname]}'").
|
||||
reorder("created_at ASC").first
|
||||
server[:id] = version.item_id.to_i
|
||||
version.item.versions.where(event: :create).first_or_create!(
|
||||
whodunnit: user.try(:id),
|
||||
|
@ -209,11 +212,11 @@ module Legacy
|
|||
def changes_dates_for domain_id
|
||||
sql = %Q{SELECT dh.*, valid_from
|
||||
FROM domain_history dh JOIN history h ON dh.historyid=h.id where dh.id=#{domain_id};}
|
||||
# find_by_sql(sql).map{|e| e.attributes.values_at("valid_from") }.flatten.each_with_object({}){|e,h|h[e.try(:to_f)] = [self]}
|
||||
|
||||
hash = {}
|
||||
find_by_sql(sql).each do |rec|
|
||||
hash[rec.valid_from.try(:to_time)] = [{id: rec.historyid, klass: self, param: :valid_from}] if rec.valid_from
|
||||
hash[rec.valid_to.try(:to_time)] = [{id: rec.historyid, klass: self, param: :valid_to}] if rec.valid_to
|
||||
end
|
||||
hash
|
||||
end
|
||||
|
|
|
@ -101,7 +101,7 @@ module Legacy
|
|||
|
||||
class << self
|
||||
def changes_dates_for domain_id
|
||||
sql = %Q{SELECT distinct t_2.id, state.id state_dot_id, state.*,
|
||||
sql = %Q{SELECT distinct t_2.id, state.id state_dot_id, state.valid_from, state.valid_to,
|
||||
extract(epoch from valid_from) valid_from_unix, extract(epoch from valid_to) valid_to_unix
|
||||
FROM object_history t_2
|
||||
JOIN object_state state ON (t_2.historyid >= state.ohid_from
|
||||
|
@ -127,7 +127,7 @@ module Legacy
|
|||
end
|
||||
|
||||
def states_for_domain_at(domain_id, time)
|
||||
sql = %Q{SELECT state.*
|
||||
sql = %Q{SELECT state.state_id
|
||||
FROM object_history t_2
|
||||
JOIN object_state state ON (t_2.historyid >= state.ohid_from
|
||||
AND (t_2.historyid <= state.ohid_to OR state.ohid_to IS NULL))
|
||||
|
@ -143,7 +143,7 @@ module Legacy
|
|||
|
||||
|
||||
def states_for_contact_at(contact_id, time)
|
||||
sql = %Q{SELECT state.*
|
||||
sql = %Q{SELECT state.state_id
|
||||
FROM object_history t_2
|
||||
JOIN object_state state ON (t_2.historyid >= state.ohid_from
|
||||
AND (t_2.historyid <= state.ohid_to OR state.ohid_to IS NULL))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue