Display has to many association activeadmin rails not working in staging but works fine in local and development

十年热恋 提交于 2020-06-29 10:36:33

问题


I have users which can have many identities, (depending on whether they login using facebook, google, or my site). In ActiveAdmin to display the identities I had the following code.

ActiveAdmin.register User do
menu label: 'Subscribers'
ActiveAdmin.register Identity do
belongs_to :user
 end 


index do
selectable_column
column :email
column :current_sign_in_at
column :sign_in_count
column :created_at
column "Sign-up Provider", :identities do |user|
      ul do

         user.identities.collect  do |identity|
             li do 
                 if identity.provider == "gplus"
                   "Google"
                 else identity.provider == "facebook"
                  identity.provider.capitalize
                 end
            end   
          end
         "Self"
       end
 end
actions
end

form do |f|
  f.inputs 'User Details' do
  f.input :email
  f.input :password
  f.input :password_confirmation
  end
  f.actions
 end
end

It works fine in the local host, and a remote development environment. But gives 502 error when run on staging which uses the production environment. seeing the log it seems the query takes long time. Trying to figure out why does it take longer time, it appeared as if the query to fetch the identity is executed for each user again and again, which is kind of an inefficient way. We also tried using the data at the staging and importing it in the local and development enviroment to see if it is the data size that is causing error, but it still works there. I understand the query is inefficient. What is the correct way to achieve this?

And if what I have used is the correct way to go for it, please help me resolve the error. Thanks.

Surprisingly, this error does not occur if i remove the identities column.


回答1:


Well, this problem had quite unusual solution, probably not specifically related to this problem but yes

The problem was with memory. On the server, the disk space became over-exceedingly used. We freed some memory by deleting some old log files, and also, used pluck instead of collect, just to fetch only the needed "provider" instead of the whole record.



来源:https://stackoverflow.com/questions/27797234/display-has-to-many-association-activeadmin-rails-not-working-in-staging-but-wor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!