mirror of
https://github.com/internetee/registry.git
synced 2025-07-26 04:28:27 +02:00
Merge pull request #101 from internetee/story/113066359-optimization
Story/113066359 optimization
This commit is contained in:
commit
30697a3b6d
11 changed files with 92 additions and 73 deletions
|
@ -25,10 +25,11 @@ class Admin::AccountActivitiesController < AdminController
|
||||||
@account_activities = @q.result.page(params[:page]).per(params[:results_per_page])
|
@account_activities = @q.result.page(params[:page]).per(params[:results_per_page])
|
||||||
sort = @account_activities.orders.map(&:to_sql).join(",")
|
sort = @account_activities.orders.map(&:to_sql).join(",")
|
||||||
|
|
||||||
|
# can do here inline SQL as it's our
|
||||||
if params[:page] && params[:page].to_i > 1
|
if params[:page] && params[:page].to_i > 1
|
||||||
@sum = @q.result.reorder(sort).limit(@account_activities.offset_value) + @b.result.where.not(id: @q.result.map(&:id))
|
@sum = @q.result.reorder(sort).limit(@account_activities.offset_value).sum(:sum) + @b.result.where("account_activities.id NOT IN (#{@q.result.select(:id).to_sql})").sum(:sum)
|
||||||
else
|
else
|
||||||
@sum = @b.result.where.not(id: @q.result.map(&:id))
|
@sum = @b.result.where("account_activities.id NOT IN (#{@q.result.select(:id).to_sql})").sum(:sum)
|
||||||
end
|
end
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -3,8 +3,8 @@ class RegenerateRegistrarWhoisesJob < Que::Job
|
||||||
# no return as we want restart job if fails
|
# no return as we want restart job if fails
|
||||||
registrar = Registrar.find(registrar_id)
|
registrar = Registrar.find(registrar_id)
|
||||||
|
|
||||||
registrar.whois_records.select(:id).find_in_batches(batch_size: 20) do |group|
|
registrar.whois_records.select(:name).find_in_batches(batch_size: 20) do |group|
|
||||||
RegenerateWhoisRecordJob.enqueue group.map(&:id), :id
|
UpdateWhoisRecordJob.enqueue group.map(&:name), 'domain'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -1,10 +0,0 @@
|
||||||
class RegenerateWhoisRecordJob < Que::Job
|
|
||||||
def run(ids, attr = :id)
|
|
||||||
ids.each do |id|
|
|
||||||
record = WhoisRecord.find_by(attr => id)
|
|
||||||
return unless record
|
|
||||||
|
|
||||||
record.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,16 +1,52 @@
|
||||||
class UpdateWhoisRecordJob < Que::Job
|
class UpdateWhoisRecordJob < Que::Job
|
||||||
|
|
||||||
def run(ids, type)
|
def run(names, type)
|
||||||
klass = case type
|
klass = case type
|
||||||
when 'reserved'then ReservedDomain
|
when 'reserved'then ReservedDomain
|
||||||
when 'blocked' then BlockedDomain
|
when 'blocked' then BlockedDomain
|
||||||
else Domain
|
when 'domain' then Domain
|
||||||
end
|
end
|
||||||
|
|
||||||
ids.each do |id|
|
Array(names).each do |name|
|
||||||
record = klass.find_by(id: id)
|
record = klass.find_by(name: name)
|
||||||
next unless record
|
if record
|
||||||
record.update_whois_record
|
send "update_#{type}", record
|
||||||
|
else
|
||||||
|
send "delete_#{type}", name
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def update_domain(domain)
|
||||||
|
domain.whois_record ? domain.whois_record.save : domain.create_whois_record
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_reserved(record)
|
||||||
|
record.generate_data
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_blocked(record)
|
||||||
|
update_reserved(record)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
# 1. deleting own
|
||||||
|
# 2. trying to regenerate reserved in order domain is still in the list
|
||||||
|
def delete_domain(name)
|
||||||
|
WhoisRecord.where(name: name).destroy_all
|
||||||
|
|
||||||
|
BlockedDomain.find_by(name: name).try(:generate_data)
|
||||||
|
ReservedDomain.find_by(name: name).try(:generate_data)
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_reserved(name)
|
||||||
|
Domain.where(name: name).any?
|
||||||
|
Whois::Record.where(name: name).delete_all
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_blocked(name)
|
||||||
|
delete_reserved(name)
|
||||||
|
end
|
||||||
end
|
end
|
|
@ -1,8 +1,9 @@
|
||||||
class BlockedDomain < ActiveRecord::Base
|
class BlockedDomain < ActiveRecord::Base
|
||||||
include Versions
|
include Versions
|
||||||
before_save :generate_data
|
before_save :generate_data
|
||||||
before_destroy :remove_data
|
after_destroy :remove_data
|
||||||
validates :name, domain_name: true, uniqueness: true
|
|
||||||
|
validates :name, domain_name: true, uniqueness: true
|
||||||
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
|
@ -22,19 +23,14 @@ validates :name, domain_name: true, uniqueness: true
|
||||||
def generate_data
|
def generate_data
|
||||||
return if Domain.where(name: name).any?
|
return if Domain.where(name: name).any?
|
||||||
|
|
||||||
@json = generate_json
|
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||||
@body = generate_body
|
wr.json = @json = generate_json # we need @json to bind to class
|
||||||
update_whois_server
|
wr.body = generate_body
|
||||||
|
wr.save
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :update_whois_record, :generate_data
|
alias_method :update_whois_record, :generate_data
|
||||||
|
|
||||||
def update_whois_server
|
|
||||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
|
||||||
wr.body = @body
|
|
||||||
wr.json = @json
|
|
||||||
wr.save
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate_body
|
def generate_body
|
||||||
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
||||||
|
@ -49,8 +45,6 @@ validates :name, domain_name: true, uniqueness: true
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_data
|
def remove_data
|
||||||
return if Domain.where(name: name).any?
|
UpdateWhoisRecordJob.enqueue name, 'blocked'
|
||||||
|
|
||||||
Whois::Record.where(name: name).delete_all
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -499,8 +499,8 @@ class Contact < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_related_whois_records
|
def update_related_whois_records
|
||||||
ids = related_domain_descriptions.keys
|
names = related_domain_descriptions.keys
|
||||||
RegenerateWhoisRecordJob.enqueue(ids, :name) if ids.present?
|
UpdateWhoisRecordJob.enqueue(names, :domain) if names.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,7 +43,7 @@ class Domain < ActiveRecord::Base
|
||||||
has_many :dnskeys, dependent: :destroy
|
has_many :dnskeys, dependent: :destroy
|
||||||
|
|
||||||
has_many :keyrelays
|
has_many :keyrelays
|
||||||
has_one :whois_record, dependent: :destroy
|
has_one :whois_record # destroyment will be done in after_commit
|
||||||
|
|
||||||
accepts_nested_attributes_for :dnskeys, allow_destroy: true
|
accepts_nested_attributes_for :dnskeys, allow_destroy: true
|
||||||
|
|
||||||
|
@ -87,14 +87,11 @@ class Domain < ActiveRecord::Base
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
after_save :update_whois_record
|
after_commit :update_whois_record
|
||||||
|
|
||||||
after_create :update_reserved_domains
|
after_create :update_reserved_domains
|
||||||
def update_reserved_domains
|
def update_reserved_domains
|
||||||
return unless in_reserved_list?
|
ReservedDomain.new_password_for(name) if in_reserved_list?
|
||||||
rd = ReservedDomain.by_domain(name).first
|
|
||||||
rd.password = SecureRandom.hex
|
|
||||||
rd.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
validates :name_dirty, domain_name: true, uniqueness: true
|
validates :name_dirty, domain_name: true, uniqueness: true
|
||||||
|
@ -279,7 +276,7 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def in_reserved_list?
|
def in_reserved_list?
|
||||||
ReservedDomain.pw_for(name).present?
|
@in_reserved_list ||= ReservedDomain.by_domain(name).any?
|
||||||
end
|
end
|
||||||
|
|
||||||
def pending_transfer
|
def pending_transfer
|
||||||
|
@ -739,7 +736,7 @@ class Domain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_whois_record
|
def update_whois_record
|
||||||
whois_record.blank? ? create_whois_record : whois_record.save
|
UpdateWhoisRecordJob.enqueue name, 'domain'
|
||||||
end
|
end
|
||||||
|
|
||||||
def status_notes_array=(notes)
|
def status_notes_array=(notes)
|
||||||
|
|
|
@ -2,7 +2,8 @@ class ReservedDomain < ActiveRecord::Base
|
||||||
include Versions # version/reserved_domain_version.rb
|
include Versions # version/reserved_domain_version.rb
|
||||||
before_save :fill_empty_passwords
|
before_save :fill_empty_passwords
|
||||||
before_save :generate_data
|
before_save :generate_data
|
||||||
before_destroy :remove_data
|
after_destroy :remove_data
|
||||||
|
|
||||||
validates :name, domain_name: true, uniqueness: true
|
validates :name, domain_name: true, uniqueness: true
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,38 +22,40 @@ class ReservedDomain < ActiveRecord::Base
|
||||||
def any_of_domains names
|
def any_of_domains names
|
||||||
where(name: names)
|
where(name: names)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
|
def new_password_for name
|
||||||
|
record = by_domain(name).first
|
||||||
|
return unless record
|
||||||
|
|
||||||
def fill_empty_passwords
|
record.regenerate_password
|
||||||
|
record.save
|
||||||
if self.password.empty?
|
|
||||||
|
|
||||||
self.password = SecureRandom.hex
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def name= val
|
def name= val
|
||||||
super SimpleIDN.to_unicode(val)
|
super SimpleIDN.to_unicode(val)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def fill_empty_passwords
|
||||||
|
regenerate_password if self.password.blank?
|
||||||
|
end
|
||||||
|
|
||||||
|
def regenerate_password
|
||||||
|
self.password = SecureRandom.hex
|
||||||
|
end
|
||||||
|
|
||||||
def generate_data
|
def generate_data
|
||||||
return if Domain.where(name: name).any?
|
return if Domain.where(name: name).any?
|
||||||
|
|
||||||
@json = generate_json
|
|
||||||
@body = generate_body
|
|
||||||
update_whois_server
|
|
||||||
end
|
|
||||||
|
|
||||||
alias_method :update_whois_record, :generate_data
|
|
||||||
|
|
||||||
def update_whois_server
|
|
||||||
wr = Whois::Record.find_or_initialize_by(name: name)
|
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||||
wr.body = @body
|
wr.json = @json = generate_json # we need @json to bind to class
|
||||||
wr.json = @json
|
wr.body = generate_body
|
||||||
wr.save
|
wr.save
|
||||||
end
|
end
|
||||||
|
alias_method :update_whois_record, :generate_data
|
||||||
|
|
||||||
|
|
||||||
def generate_body
|
def generate_body
|
||||||
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
||||||
|
@ -67,9 +70,7 @@ class ReservedDomain < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_data
|
def remove_data
|
||||||
return if Domain.where(name: name).any?
|
UpdateWhoisRecordJob.enqueue name, 'reserved'
|
||||||
|
|
||||||
Whois::Record.where(name: name).delete_all
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
.col-md-3
|
.col-md-3
|
||||||
.col-md-2
|
.col-md-2
|
||||||
.col-md-4{class: 'text-right'}
|
.col-md-4{class: 'text-right'}
|
||||||
= t(:starting_balance) + " #{@sum.to_a.map(&:sum).sum.to_f} EUR"
|
= t(:starting_balance) + " #{@sum.to_f} EUR"
|
||||||
|
|
||||||
%hr
|
%hr
|
||||||
|
|
||||||
|
@ -66,10 +66,10 @@
|
||||||
%th{class: 'col-xs-2'}
|
%th{class: 'col-xs-2'}
|
||||||
= sort_link(@q, 'sum')
|
= sort_link(@q, 'sum')
|
||||||
%tbody
|
%tbody
|
||||||
-total = @sum.to_a.map(&:sum).sum.to_f
|
-total = @sum.to_f
|
||||||
- @account_activities.each do |x|
|
- @account_activities.each do |x|
|
||||||
%tr
|
%tr
|
||||||
%td= link_to(x.account.registrar.try(:code), admin_registrar_path(x.account.registrar))
|
%td= x.account.registrar && link_to(x.account.registrar.try(:code), admin_registrar_path(x.account.registrar))
|
||||||
%td= x.description.present? ? x.description : '-'
|
%td= x.description.present? ? x.description : '-'
|
||||||
%td= x.activity_type ? t(x.activity_type) : ''
|
%td= x.activity_type ? t(x.activity_type) : ''
|
||||||
%td= l(x.created_at)
|
%td= l(x.created_at)
|
||||||
|
|
|
@ -8,17 +8,17 @@ namespace :whois do
|
||||||
|
|
||||||
print "\n-----> Update domains whois_records"
|
print "\n-----> Update domains whois_records"
|
||||||
Domain.find_in_batches.each do |group|
|
Domain.find_in_batches.each do |group|
|
||||||
UpdateWhoisRecordJob.enqueue group.map(&:id), 'domain'
|
UpdateWhoisRecordJob.enqueue group.map(&:name), 'domain'
|
||||||
end
|
end
|
||||||
|
|
||||||
print "\n-----> Update blocked domains whois_records"
|
print "\n-----> Update blocked domains whois_records"
|
||||||
BlockedDomain.find_in_batches.each do |group|
|
BlockedDomain.find_in_batches.each do |group|
|
||||||
UpdateWhoisRecordJob.enqueue group.map(&:id), 'blocked'
|
UpdateWhoisRecordJob.enqueue group.map(&:name), 'blocked'
|
||||||
end
|
end
|
||||||
|
|
||||||
print "\n-----> Update reserved domains whois_records"
|
print "\n-----> Update reserved domains whois_records"
|
||||||
ReservedDomain.find_in_batches.each do |group|
|
ReservedDomain.find_in_batches.each do |group|
|
||||||
UpdateWhoisRecordJob.enqueue group.map(&:id), 'reserved'
|
UpdateWhoisRecordJob.enqueue group.map(&:name), 'reserved'
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,7 @@ namespace :zonefile do
|
||||||
exclude_filter := '%.%.' || i_origin;
|
exclude_filter := '%.%.' || i_origin;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
SELECT ROUND(extract(epoch from now() at time zone 'utc')) INTO serial_num;
|
SELECT (extract(epoch from now() at time zone 'utc'))::int INTO serial_num;
|
||||||
|
|
||||||
-- zonefile header
|
-- zonefile header
|
||||||
SELECT concat(
|
SELECT concat(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue