Fix bug and accelerate loading sites list.
This commit is contained in:
parent
9579179685
commit
51f809f951
|
@ -137,13 +137,9 @@ class Admin::AdminModulesController < OrbitAdminController
|
||||||
def site_list_without_module(rm)
|
def site_list_without_module(rm)
|
||||||
registered_sites = []
|
registered_sites = []
|
||||||
if !rm.nil?
|
if !rm.nil?
|
||||||
rss = RegisteredSite.active
|
active_ids = RegisteredSite.active.pluck(:id)
|
||||||
rss.each do |rs|
|
already_installed_ids = InstalledModule.where(:r_module => rm.id, :registered_site_id.in => active_ids).pluck(:registered_site_id)
|
||||||
im = InstalledModule.where(:r_module => rm.id, :registered_site_id => rs.id)
|
registered_sites = RegisteredSite.where(:id.in=>active_ids - already_installed_ids).order_by(:id=>-1).to_a
|
||||||
if im.count == 0
|
|
||||||
registered_sites << rs
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
registered_sites
|
registered_sites
|
||||||
end
|
end
|
||||||
|
@ -152,18 +148,16 @@ class Admin::AdminModulesController < OrbitAdminController
|
||||||
registered_sites = []
|
registered_sites = []
|
||||||
times = []
|
times = []
|
||||||
if !rm.nil?
|
if !rm.nil?
|
||||||
rss = RegisteredSite.active
|
|
||||||
rss.each do |rs|
|
|
||||||
if access.nil?
|
if access.nil?
|
||||||
im = InstalledModule.where(:r_module => rm.id, :registered_site_id => rs.id)
|
ims = InstalledModule.where(:r_module => rm.id, :registered_site_id.in => RegisteredSite.active.pluck(:id))
|
||||||
else
|
else
|
||||||
im = InstalledModule.where(:r_module => rm.id, :registered_site_id => rs.id,:permission_granted => access)
|
ims = InstalledModule.where(:r_module => rm.id, :registered_site_id.in => RegisteredSite.active.pluck(:id), :permission_granted => access)
|
||||||
end
|
|
||||||
if im.count > 0
|
|
||||||
registered_sites << rs
|
|
||||||
times << im.first.created_at.strftime("%Y-%m-%d %H:%M") rescue ""
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
ims_info = ims.pluck(:registered_site_id, :created_at)
|
||||||
|
ims_info.uniq!{|rs_id, created_at| rs_id}
|
||||||
|
ims_info = ims_info.to_h
|
||||||
|
registered_sites = RegisteredSite.where(:id.in=>ims_info.keys).order_by(:id=>-1).to_a
|
||||||
|
times = registered_sites.map{|rs| ims_info[rs.id].strftime("%Y-%m-%d %H:%M") rescue ""}
|
||||||
end
|
end
|
||||||
[registered_sites, times]
|
[registered_sites, times]
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,19 +24,21 @@ module RegisteredModuleHelper
|
||||||
site.installed_modules << im
|
site.installed_modules << im
|
||||||
site.save
|
site.save
|
||||||
end
|
end
|
||||||
restart_remote_server(site)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def restart_remote_server(site)
|
def restart_remote_server(site)
|
||||||
|
params_to_send = {"site_token" => site.site_token}
|
||||||
uri = URI.parse("http://#{site.site_domain}/")
|
uri = URI.parse("http://#{site.site_domain}/")
|
||||||
http = Net::HTTP.new(uri.host,uri.port)
|
http = Net::HTTP.new(uri.host,uri.port)
|
||||||
request = Net::HTTP::Post.new("/store/restart_server_after_install")
|
request = Net::HTTP::Post.new("/store/restart_server_after_install")
|
||||||
|
request.body = params_to_send.to_query
|
||||||
response = http.request(request)
|
response = http.request(request)
|
||||||
if response.code != "200"
|
if response.code != "200"
|
||||||
uri = URI.parse("https://#{site.site_domain}/")
|
uri = URI.parse("https://#{site.site_domain}/")
|
||||||
Net::HTTP.start(uri.host, uri.port,:use_ssl => true,open_timeout: 30,read_timeout: 30,verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
Net::HTTP.start(uri.host, uri.port,:use_ssl => true,open_timeout: 30,read_timeout: 30,verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
||||||
request = Net::HTTP::Post.new("/store/restart_server_after_install")
|
request = Net::HTTP::Post.new("/store/restart_server_after_install")
|
||||||
|
request.body = params_to_send.to_query
|
||||||
response = http.request(request)
|
response = http.request(request)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue