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)
|
||||
registered_sites = []
|
||||
if !rm.nil?
|
||||
rss = RegisteredSite.active
|
||||
rss.each do |rs|
|
||||
im = InstalledModule.where(:r_module => rm.id, :registered_site_id => rs.id)
|
||||
if im.count == 0
|
||||
registered_sites << rs
|
||||
end
|
||||
end
|
||||
active_ids = RegisteredSite.active.pluck(:id)
|
||||
already_installed_ids = InstalledModule.where(:r_module => rm.id, :registered_site_id.in => active_ids).pluck(:registered_site_id)
|
||||
registered_sites = RegisteredSite.where(:id.in=>active_ids - already_installed_ids).order_by(:id=>-1).to_a
|
||||
end
|
||||
registered_sites
|
||||
end
|
||||
|
@ -152,18 +148,16 @@ class Admin::AdminModulesController < OrbitAdminController
|
|||
registered_sites = []
|
||||
times = []
|
||||
if !rm.nil?
|
||||
rss = RegisteredSite.active
|
||||
rss.each do |rs|
|
||||
if access.nil?
|
||||
im = InstalledModule.where(:r_module => rm.id, :registered_site_id => rs.id)
|
||||
else
|
||||
im = InstalledModule.where(:r_module => rm.id, :registered_site_id => rs.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
|
||||
if access.nil?
|
||||
ims = InstalledModule.where(:r_module => rm.id, :registered_site_id.in => RegisteredSite.active.pluck(:id))
|
||||
else
|
||||
ims = InstalledModule.where(:r_module => rm.id, :registered_site_id.in => RegisteredSite.active.pluck(:id), :permission_granted => access)
|
||||
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
|
||||
[registered_sites, times]
|
||||
end
|
||||
|
|
|
@ -24,19 +24,21 @@ module RegisteredModuleHelper
|
|||
site.installed_modules << im
|
||||
site.save
|
||||
end
|
||||
restart_remote_server(site)
|
||||
end
|
||||
|
||||
|
||||
def restart_remote_server(site)
|
||||
params_to_send = {"site_token" => site.site_token}
|
||||
uri = URI.parse("http://#{site.site_domain}/")
|
||||
http = Net::HTTP.new(uri.host,uri.port)
|
||||
request = Net::HTTP::Post.new("/store/restart_server_after_install")
|
||||
request.body = params_to_send.to_query
|
||||
response = http.request(request)
|
||||
if response.code != "200"
|
||||
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|
|
||||
request = Net::HTTP::Post.new("/store/restart_server_after_install")
|
||||
request.body = params_to_send.to_query
|
||||
response = http.request(request)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue