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.