Working L10N solution for Rails 3.2 - ruby-on-rails

I'm developing a multilingual (EN/RU) website and I need a solution allowing me to translate database records?
Are there any third-party plugins allowing you to maintain a multilingual website? Ideally it should work with rails_admin (or scaffolding at the worst case) and and routing-filter.
I use globalize3 now and it creates a translation via rails_admin as well. But there's no way to specify the locale. It only creates a translation for your current locale, i.e. there's no way to translate records really because it just copies the original entry. And I see no way to create english translations.
Thanks in advance!
Gemfile
source 'https://rubygems.org'
gem 'rails', '3.2.0'
gem 'sqlite3'
gem 'pg', :require => 'pg'
gem 'memcache-client'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'russian'
gem 'dynamic_form'
gem 'friendly_id', '~> 4.0.0'
gem 'routing-filter'
gem 'devise'
gem 'cancan'
gem 'paper_trail', '~> 2'
gem 'rails_admin', :git => 'git://github.com/sferik/rails_admin.git'
gem 'globalize3', '~> 0.2.0.beta6', :git => 'git://github.com/svenfuchs/globalize3.git'
# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'
# To use Jbuilder templates for JSON
# gem 'jbuilder'
gem 'unicorn'
gem 'capistrano'
# To use debugger
# gem 'ruby-debug19', :require => 'ruby-debug'
config/application.rb
config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
config.i18n.default_locale = :ru
models/page.rb
class Page < ActiveRecord::Base
translates :title, :content
validates_presence_of :title
end
Rails console output:
Loading development environment (Rails 3.2.0)
1.9.3p0 :001 > p = Page.new(:title => 'Test 1')
Page::Translation Load (0.2ms) SELECT "page_translations".* FROM "page_translations" WHERE "page_translations"."page_id" IS NULL AND "page_translations"."locale" = 'ru' LIMIT 1
=> #<Page id: nil, title: "Test 1", slug: nil, content: nil, created_at: nil, updated_at: nil>
1.9.3p0 :002 > p.save
(0.1ms) begin transaction
SQL (13.9ms) INSERT INTO "pages" ("content", "created_at", "slug", "title", "updated_at") VALUES (?, ?, ?, ?, ?) [["content", nil], ["created_at", Tue, 24 Jan 2012 14:01:28 MSK +04:00], ["slug", nil], ["title", "Test 1"], ["updated_at", Tue, 24 Jan 2012 14:01:28 MSK +04:00]]
SQL (0.5ms) INSERT INTO "page_translations" ("content", "created_at", "locale", "page_id", "title", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["content", nil], ["created_at", Tue, 24 Jan 2012 14:01:28 MSK +04:00], ["locale", "ru"], ["page_id", 5], ["title", nil], ["updated_at", Tue, 24 Jan 2012 14:01:28 MSK +04:00]]
Page::Translation Load (0.1ms) SELECT "page_translations".* FROM "page_translations" WHERE "page_translations"."page_id" = 5 AND "page_translations"."locale" = 'ru' LIMIT 1
(0.4ms) UPDATE "page_translations" SET "title" = 'Test 1', "updated_at" = '2012-01-24 10:01:28.298579' WHERE "page_translations"."id" = 5
Page::Translation Load (0.1ms) SELECT "page_translations".* FROM "page_translations" WHERE "page_translations"."id" = ? LIMIT 1 [["id", 5]]
(2.2ms) commit transaction
=> true

If you have only two languages, it's better to keep translations in the same table, e.g.:
create_table "articles" do |t|
...
t.column "title_ru", :string
t.column "title_en", :string
t.column "body_ru", :text
t.column "body_en", :text
...
end
And then extend ActiveRecord::Base class to provide method for translation:
module Translate
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def translate *columns
columns.each do |column|
class_eval <<-EOV
def #{column}
unless self.send("#{column}_#{I18n.locale}")
self.send("#{column}_#{I18n.locale}")
else
#{column}_#{I18n.default_locale}
end
end
EOV
end
end
end
end
ActiveRecord::Base.send :include, Translate
After that, call that method from your model:
class Article < ActiveRecord::Base
...
translate :title, :body
...
end
And now you can edit both title_ru and title_en entries without globalize3.

Globalize3 overrides the following methods which allows you to specify the locale when saving an attribute.
product.write_attribute(:title, 'Hows going', locale:'ua')
product.save!
The same goes to read_attribute. As this is undocumented, I am not sure if there will be any bad consequences for using this.

May be: RailsAdmin and Globalize3

Related

Heroku Production - Attribute not being saved in production but works in development

App is using a combination of Gems to create a multi-tenant application where account owners can invite users. All data shown is then scoped to the :account_id column based on the current user's :account_id value. It is using Devise for Accounts and Users. It is using Devise Invitable to allow accounts to send an invitation by email to Users to create their account and subsequently upon creation that user is assigned the :account_id of the Account id that invited them to join.
In development environment, the :account_id is being assign correctly upon InvitationsController#Create action. In production environment on Heroku it fails to save the :account_id to the User upon the same action.
Gemfile:
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby '2.7.1'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 6.0.3', '>= 6.0.3.2'
# Use postgresql as the database for Active Record
gem 'pg', '>= 0.18', '< 2.0'
# Use Puma as the app server
gem 'puma', '~> 4.1'
# Use SCSS for stylesheets
gem 'sass-rails', '>= 6'
# Transpile app-like JavaScript. Read more: https://github.com/rails/webpacker
gem 'webpacker', '~> 4.0'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.7'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Gem for Users and Account control
gem 'devise'
# Gems for making things pretty
gem 'bootstrap'
gem 'font-awesome-rails'
# Use for creating graphs and grouping data
gem 'chartkick'
gem 'groupdate'
# Pagination gem
gem 'kaminari'
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
#Use to make mulitenancy simpler
gem 'acts_as_tenant'
#For Account owners to invite their company's Users
gem 'devise_invitable'
# Reduces boot times through caching; required in config/boot.rb
gem 'bootsnap', '>= 1.4.2', require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem 'capybara', '>= 2.15'
gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
Routes.rb
Rails.application.routes.draw do
devise_for :accounts, controllers: { sessions: 'accounts/sessions', registrations: 'accounts/registrations', invitations: 'users/invitations' }
devise_for :users, controllers: { sessions: 'users/sessions', invitations: 'users/invitations' }
resources :downtimes
resources :downtime_criteria
resources :actionitems do
resources :comments
end
resources :production_runs do
resources :production_hours
end
root 'welcome#index'
end
ApplicationController
class ApplicationController < ActionController::Base
set_current_tenant_through_filter
before_action :find_current_tenant
def find_current_tenant
current_account_id = user_signed_in? ? current_user.account : nil
set_current_tenant(current_account_id)
end
def authenticate_inviter!
authenticate_account!(force: true)
end
end
/users/InvitationsController
class Users::InvitationsController < Devise::InvitationsController
before_action :configure_permitted_parameters, if: :devise_controller?
def create
super
User.invite!(:email => params[:email], :account_id => current_account.id)
User.where(email: params[:user][:email]).update_all(account_id: current_account.id)
end
protected
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:invite, keys: [:account_id])
end
end
Account.rb
class Account < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_many :users, dependent: :destroy
include DeviseInvitable::Inviter
end
User.rb
class User < ApplicationRecord
acts_as_tenant(:account)
belongs_to :account
validates :email, :account_id, presence: true
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :invitable, :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
end
/users/invitations/_new.html.erb
<h2><%= t "devise.invitations.new.header" %></h2>
<%= form_for(resource, as: #invitation, url: invitation_path(resource_name), html: { method: :post }) do |f| %>
<%= render "users/shared/error_messages", resource: resource %>
<% resource.class.invite_key_fields.each do |field| -%>
<div class="field">
<%= f.label field %><br />
<%= f.text_field field %>
</div>
<% end -%>
<div class="actions">
<%= f.submit t("devise.invitations.new.submit_button") %>
</div>
<% end %>
heroku logs --tail
2020-09-03T02:57:16.793404+00:00 heroku[router]: at=info method=POST path="/users/invitation" host=gentle-cliffs-24710.herokuapp.com request_id=cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8 fwd="108.166.134.134" dyno=web.1 connect=0ms service=646ms status=500 bytes=1827 protocol=https
2020-09-03T02:57:16.744528+00:00 app[web.1]: D, [2020-09-03T02:57:16.744380 #4] DEBUG -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] User Load (1.2ms) SELECT "users".* FROM "users" WHERE "users"."invitation_token" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["invitation_token", "f865f1a5e1e8e8f1576567e1f539ba6d9d3a1e85d5b21fa8e8fc72a0a7a1341d"], ["LIMIT", 1]]
2020-09-03T02:57:16.750905+00:00 app[web.1]: D, [2020-09-03T02:57:16.750774 #4] DEBUG -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] (3.2ms) BEGIN
2020-09-03T02:57:16.753036+00:00 app[web.1]: D, [2020-09-03T02:57:16.752895 #4] DEBUG -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] User Create (1.3ms) INSERT INTO "users" ("email", "encrypted_password", "created_at", "updated_at", "invitation_token", "invitation_created_at", "invitation_sent_at", "invited_by_type", "invited_by_id") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id" [["email", "testing12345#gmail.com"], ["encrypted_password", "$2a$11$sPBv6kzgZNZcaDhRpNORcuThcEFQQh8xqTiIJ45izWX0v3eyBtgKK"], ["created_at", "2020-09-03 02:57:16.746102"], ["updated_at", "2020-09-03 02:57:16.746102"], ["invitation_token", "f865f1a5e1e8e8f1576567e1f539ba6d9d3a1e85d5b21fa8e8fc72a0a7a1341d"], ["invitation_created_at", "2020-09-03 02:57:16.744928"], ["invitation_sent_at", "2020-09-03 02:57:16.744928"], ["invited_by_type", "Account"], ["invited_by_id", 2]]
2020-09-03T02:57:16.758183+00:00 app[web.1]: D, [2020-09-03T02:57:16.758057 #4] DEBUG -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] (4.4ms) COMMIT
2020-09-03T02:57:16.765162+00:00 app[web.1]: I, [2020-09-03T02:57:16.765033 #4] INFO -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] Rendering users/mailer/invitation_instructions.html.erb
2020-09-03T02:57:16.767966+00:00 app[web.1]: I, [2020-09-03T02:57:16.767824 #4] INFO -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] Rendered users/mailer/invitation_instructions.html.erb (Duration: 2.6ms | Allocations: 517)
2020-09-03T02:57:16.771219+00:00 app[web.1]: I, [2020-09-03T02:57:16.771101 #4] INFO -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] Rendering users/mailer/invitation_instructions.text.erb
2020-09-03T02:57:16.773629+00:00 app[web.1]: I, [2020-09-03T02:57:16.773519 #4] INFO -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] Rendered users/mailer/invitation_instructions.text.erb (Duration: 2.2ms | Allocations: 393)
2020-09-03T02:57:16.777350+00:00 app[web.1]: D, [2020-09-03T02:57:16.777199 #4] DEBUG -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] Devise::Mailer#invitation_instructions: processed outbound mail in 18.2ms
2020-09-03T02:57:16.788770+00:00 app[web.1]: I, [2020-09-03T02:57:16.788627 #4] INFO -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] Delivered mail 5f505b8cbe3f1_493944479#739a533a-af2a-474c-a8c4-7bacfd76c8ca.mail (11.2ms)
2020-09-03T02:57:16.788846+00:00 app[web.1]: D, [2020-09-03T02:57:16.788754 #4] DEBUG -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] Date: Thu, 03 Sep 2020 02:57:16 +0000
2020-09-03T02:57:16.788847+00:00 app[web.1]: From: please-change-me-at-config-initializers-devise#example.com
2020-09-03T02:57:16.788847+00:00 app[web.1]: Reply-To: please-change-me-at-config-initializers-devise#example.com
2020-09-03T02:57:16.788848+00:00 app[web.1]: To: testing12345#gmail.com
2020-09-03T02:57:16.788849+00:00 app[web.1]: Message-ID: <5f505b8cbe3f1_493944479#739a533a-af2a-474c-a8c4-7bacfd76c8ca.mail>
2020-09-03T02:57:16.788850+00:00 app[web.1]: Subject: Invitation instructions
2020-09-03T02:57:16.788850+00:00 app[web.1]: Mime-Version: 1.0
2020-09-03T02:57:16.788851+00:00 app[web.1]: Content-Type: multipart/alternative;
2020-09-03T02:57:16.788851+00:00 app[web.1]: boundary="--==_mimepart_5f505b8cbd144_493944334";
2020-09-03T02:57:16.788852+00:00 app[web.1]: charset=UTF-8
2020-09-03T02:57:16.788852+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2020-09-03T02:57:16.788853+00:00 app[web.1]:
2020-09-03T02:57:16.788853+00:00 app[web.1]:
2020-09-03T02:57:16.788853+00:00 app[web.1]: ----==_mimepart_5f505b8cbd144_493944334
2020-09-03T02:57:16.788854+00:00 app[web.1]: Content-Type: text/plain;
2020-09-03T02:57:16.788854+00:00 app[web.1]: charset=UTF-8
2020-09-03T02:57:16.788854+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2020-09-03T02:57:16.788855+00:00 app[web.1]:
2020-09-03T02:57:16.788855+00:00 app[web.1]: Hello testing12345#gmail.com
2020-09-03T02:57:16.788855+00:00 app[web.1]:
2020-09-03T02:57:16.788856+00:00 app[web.1]: Someone has invited you to https://gentle-cliffs-24710.herokuapp.com/:3000/, you can accept it through the link below.
2020-09-03T02:57:16.788856+00:00 app[web.1]:
2020-09-03T02:57:16.788857+00:00 app[web.1]: https://gentle-cliffs-24710.herokuapp.com/:3000/users/invitation/accept?invitation_token=yGi2R5_2acRXY3XJXSVN
2020-09-03T02:57:16.788857+00:00 app[web.1]:
2020-09-03T02:57:16.788857+00:00 app[web.1]:
2020-09-03T02:57:16.788858+00:00 app[web.1]: If you don't want to accept the invitation, please ignore this email. Your account won't be created until you access the link above and set your password.
2020-09-03T02:57:16.788858+00:00 app[web.1]:
2020-09-03T02:57:16.788858+00:00 app[web.1]: ----==_mimepart_5f505b8cbd144_493944334
2020-09-03T02:57:16.788859+00:00 app[web.1]: Content-Type: text/html;
2020-09-03T02:57:16.788859+00:00 app[web.1]: charset=UTF-8
2020-09-03T02:57:16.788859+00:00 app[web.1]: Content-Transfer-Encoding: 7bit
2020-09-03T02:57:16.788860+00:00 app[web.1]:
2020-09-03T02:57:16.788860+00:00 app[web.1]: <p>Hello testing12345#gmail.com</p>
2020-09-03T02:57:16.788861+00:00 app[web.1]:
2020-09-03T02:57:16.788861+00:00 app[web.1]: <p>Someone has invited you to https://gentle-cliffs-24710.herokuapp.com/:3000/, you can accept it through the link below.</p>
2020-09-03T02:57:16.788861+00:00 app[web.1]:
2020-09-03T02:57:16.788862+00:00 app[web.1]: <p>Accept invitation</p>
2020-09-03T02:57:16.788862+00:00 app[web.1]:
2020-09-03T02:57:16.788863+00:00 app[web.1]:
2020-09-03T02:57:16.788863+00:00 app[web.1]: <p>If you don't want to accept the invitation, please ignore this email. Your account won't be created until you access the link above and set your password.</p>
2020-09-03T02:57:16.788864+00:00 app[web.1]:
2020-09-03T02:57:16.788864+00:00 app[web.1]: ----==_mimepart_5f505b8cbd144_493944334--
2020-09-03T02:57:16.788865+00:00 app[web.1]:
2020-09-03T02:57:16.789171+00:00 app[web.1]: I, [2020-09-03T02:57:16.789103 #4] INFO -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] Completed 500 Internal Server Error in 586ms (ActiveRecord: 21.3ms | Allocations: 11597)
2020-09-03T02:57:16.790582+00:00 app[web.1]: F, [2020-09-03T02:57:16.790480 #4] FATAL -- : [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8]
2020-09-03T02:57:16.790584+00:00 app[web.1]: [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] Errno::ECONNREFUSED (Connection refused - connect(2) for "localhost" port 25):
2020-09-03T02:57:16.790584+00:00 app[web.1]: [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8]
2020-09-03T02:57:16.790585+00:00 app[web.1]: [cdfe6b7c-7473-47d9-9ff1-ebca721ba0e8] app/controllers/users/invitations_controller.rb:5:in `create'
heroku run rails c
irb(main):006:0> User.last
D, [2020-09-03T02:58:48.541138 #4] DEBUG -- : User Load (1.2ms) SELECT "users".* FROM "users" ORDER BY "users"."id" DESC LIMIT $1 [["LIMIT", 1]]
=> #<User id: 8, email: "testing12345#gmail.com", created_at: "2020-09-03 02:57:16", updated_at: "2020-09-03 02:57:16", ***account_id: nil***>
irb(main):007:0>
I've tried running heroku restart. Out of ideas... anyone have some insight? Thanks

Postgres create not working after updating to Rails 5.2

I updated from Rails 5.0 to 5.2 and made very few changes, but one thing quit working. repopulateResidResto is called when an address (location) or person is created or updated. It still works on the Rails 5.0 version at Heroku but not on my updated version on my computer. I can see the method is called in the server logs, but nothing is written to the database. Selected from the Heroku logs:
Year Load (3.5ms) SELECT "years".* FROM "years" ORDER BY "years"."id" ASC LIMIT $1 OFFSET $2 [["LIMIT", 1000], ["OFFSET", 206]]
Year Load (2.6ms) SELECT "years".* FROM "years" ORDER BY id OFFSET $1 [["OFFSET", 207]]
Location Load (1.2ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 62], ["LIMIT", 1]]
Location Load (1.1ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
(4.5ms) BEGIN
SQL (1.8ms) INSERT INTO "resto_resid_lines" ("person_id", "resto_date", "resid_date", "title_resto", "title_resid", "resto_name", "created_at", "updated_at", "resto_connection_id", "resid_connection_id", "resto_loc_id", "resid_loc_id", "lat_resto", "long_resto", "resto_address", "resid_address", "mid_date") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17) RETURNING "id" [["person_id", 34], ["resto_date", "1886-09-01"], ["resid_date", "1886-09-01"], ["title_resto", "Co-proprietor"], ["title_resid", "Resident"], ["resto_name", ""], ["created_at", "2019-02-20 05:10:40.148200"], ["updated_at", "2019-02-20 05:10:40.148200"], ["resto_connection_id", 259], ["resid_connection_id", 258], ["resto_loc_id", 2], ["resid_loc_id", 62], ["lat_resto", "34.052265"], ["long_resto", "-118.243408"], ["resto_address", "11 W First St"], ["resid_address", "23 Sepulveda "], ["mid_date", "1886-09-01"]]
(2.2ms) COMMIT
The log on on my Mac with Rails 5.2. I imagine the ROLLBACK is a problem, but don't understand what triggers it:
Year Load (0.3ms) SELECT "years".* FROM "years" ORDER BY "years"."id" ASC LIMIT $1 OFFSET $2 [["LIMIT", 1000], ["OFFSET", 206]]
↳ app/controllers/application_controller.rb:19
Year Load (0.4ms) SELECT "years".* FROM "years" ORDER BY id OFFSET $1 [["OFFSET", 207]]
↳ app/controllers/application_controller.rb:47
Location Load (0.4ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 62], ["LIMIT", 1]]
↳ app/controllers/application_controller.rb:58
Location Load (0.3ms) SELECT "locations".* FROM "locations" WHERE "locations"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
↳ app/controllers/application_controller.rb:64
(0.1ms) BEGIN
↳ app/controllers/application_controller.rb:53
Person Load (0.1ms) SELECT "people".* FROM "people" WHERE "people"."id" = $1 LIMIT $2 [["id", 34], ["LIMIT", 1]]
↳ app/controllers/application_controller.rb:53
(0.1ms) ROLLBACK
↳ app/controllers/application_controller.rb:53
Scoped order is ignored, it's forced to be batch order.
Year Load (0.2ms) SELECT "years".* FROM "years" ORDER BY "years"."id" ASC LIMIT $1 OFFSET $2 [["LIMIT", 1000], ["OFFSET", 208]]
↳ app/controllers/application_controller.rb:19
Line 19 is yearsBelow.find_each do |yearBelow|.
Line 47 is yearsBelow.each do |yearBelow|
Line 58 is :lat_resid => year.location.latitude.
Line 64 is :lat_resto => yearBelow.location.latitude.
Line 53 is the second RestoResidLine.create.
The controller (no changes made while upgrading to Rails 5.2):
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
include SessionsHelper
def repopulateResidResto
timeSpan = 12.months - 1.day # without 1.day pick up a year later, at least in early development
i = 1
RestoResidLine.delete_all
Year.unscope(:order).order('id').find_each do |year|
if year.resto
yearsBelow = Year.offset(i).unscope(:order).order('id') # default sort for year is date and without unscope really messes up things, could sort by lots of things, but id seems safe. Year is sorted by date, and we need that to be in the same sort
yearsBelow.find_each do |yearBelow|
foo_time =Time.parse(year.year_date.to_s)
bar_time = Time.parse(yearBelow.year_date.to_s)
avg = Time.at((foo_time.to_f + bar_time.to_f) / 2)
avg_date = Date.parse(avg.to_s) # if these dates are different use average for the lines
if (year.person_id == yearBelow.person_id) and (((yearBelow.year_date - timeSpan)..(yearBelow.year_date + timeSpan)).cover?year.year_date) and (!yearBelow.resto)
RestoResidLine.create(:person_id => year.person_id,
:resto_loc_id => year.location_id,
:resto_name => year.resto_name,
:resto_date => year.year_date,
:title_resto => year.title,
:lat_resto => year.location.latitude,
:long_resto => year.location.longitude,
:resto_address => year.location.address,
:resid_loc_id => yearBelow.location_id,
:resid_date => yearBelow.year_date,
:lat_resid => yearBelow.location.latitude,
:long_resid => yearBelow.location.longitude,
:resid_address => yearBelow.location.address,
:title_resid => yearBelow.title,
:mid_date => avg_date,
:resto_connection_id => year.id,
:resid_connection_id => yearBelow.id)
end
end
end
if year.resid
yearsBelow = Year.offset(i).unscope(:order).order('id')
yearsBelow.each do |yearBelow|
foo_time =Time.parse(year.year_date.to_s)
bar_time = Time.parse(yearBelow.year_date.to_s)
avg = Time.at((foo_time.to_f + bar_time.to_f) / 2)
avg_date = Date.parse(avg.to_s) # if these dates are different use average for the lines
if (year.person_id == yearBelow.person_id) and (((yearBelow.year_date - timeSpan)..(yearBelow.year_date + timeSpan)).cover?year.year_date) and (!yearBelow.resid)
RestoResidLine.create(:person_id => yearBelow.person_id,
:resto_loc_id => yearBelow.location_id,
:resto_name => yearBelow.resto_name,
:resto_date => yearBelow.year_date,
:title_resto => yearBelow.title,
:lat_resid => year.location.latitude,
:long_resid => year.location.longitude,
:resid_address => year.location.address,
:resid_loc_id => year.location_id,
:resid_date => year.year_date,
:title_resid => year.title,
:lat_resto => yearBelow.location.latitude,
:long_resto => yearBelow.location.longitude,
:resto_address => yearBelow.location.address,
:mid_date => avg_date,
:resto_connection_id => yearBelow.id,
:resid_connection_id => year.id)
end # if
end # yearBelow
end
i += 1
end
end
end
Gemfile:
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
ruby '2.6.1'
gem 'rails', '~> 5.2.2'
gem 'puma', '~> 3.0'
source 'https://rails-assets.org' do
gem 'rails-assets-rearmed-js'
end
gem 'pg'
gem 'bootstrap-sass', '~> 3.4.0'
gem 'sassc-rails', '>= 2.0.0'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'turbolinks', '~> 5'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bcrypt', '~> 3.1.7'
gem 'faker', '1.4.2'
gem 'mini_magick', '4.6.1'
gem 'will_paginate'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'simple_form'
gem 'fuuu'
gem 'geocoder'
gem 'activerecord-postgis-adapter'
gem 'rgeo-geojson'
gem "fog-aws"
gem 'aws-sdk-s3', '~> 1'
gem 'carrierwave', '~> 1.0', '< 2.0'
gem 'pg-eyeballs'
gem 'leaflet-rails'
gem "responders"
group :development, :test do
gem 'rspec-rails'
gem 'database_cleaner'
gem 'dotenv-rails'
gem 'awesome_print'
gem 'super_awesome_print'
end
group :development do
gem 'web-console', '>= 3.3.0'
gem "better_errors"
gem 'binding_of_caller'
gem 'byebug', platform: :mri
gem 'pry-byebug'
gem "rails-erd"
gem 'annotate'
gem 'rubocop', require: false
end
group :production do
end
group :test do
gem 'minitest-reporters', '1.1.9'
gem 'guard', '2.13.0'
gem 'guard-minitest', '2.4.4'
gem 'rails-controller-testing', '0.1.1'
gem 'simplecov', :require => false
gem 'capybara'
end
How might I go about debugging this? Or what changes might be affecting this?
The line config.load_defaults 5.0 in config/application.rb was the cause of the problem. I don't know what the line does. Presumably load Rails 5.0 defaults. Why after going to the trouble of upgrading?
To get to this I tried to upgrade several times. At first going a bit too quickly and then slower and slower and following diffs and blogs on upgrading. What I finally did was go directly from 5.0 to 5.2, because going in two steps sent me in loops about bundler versions. And from reading blogs and seeing what happened in my earlier trials I was fairly certain not much changed for me in Rails 5.1.
I finally concluded that something happened in the rake app:update step. So I accepted all the defaults except I kept the old routes.rb. Then went through the diffs a file at a time and changed back to what I had in 5.0, relaunched server and went through the steps to trigger the RestoResidLine.create step.
I had tried several times over the last few months, but in the last few days went carefully through about three upgrade trials. Left to do is put back in what got left out of the rake app:update accepting of defaults. I think they are minor. No first I need to make sure can upload to heroku.
FWIW I wanted to get to 5.2 to get ActiveStorage.

Localhost is working but heroku deploy is not working after adding searchbar for users (heroku run rake db:seed error)

I've added autocompleted searchbar for users to my app ("gem searchkick" and "elasticsearch" were used) then it is great working on localhost. I have also added "SearchBox Elasticsearch -- Starter" to my Heroku app.
After I can push my app to heroku without fail but I've an error with "heroku run db:seed". (The first user can be installed but the second user is not)
How can I fix the problem?
Error
Running rake db:seed on bloggerpoint... up, run.7859
ActiveRecord::SchemaMigration Load (1.9ms) SELECT "schema_migrations".* FROM "schema_migrations"
(12.7ms) BEGIN
User Exists (1.6ms) SELECT 1 AS one FROM "users" WHERE LOWER("users"."email") = LOWER('example#railstutorial.org') LIMIT 1
SQL (1.1ms) INSERT INTO "users" ("name", "email", "password_digest", "admin", "activated", "activated_at", "created_at", "updated_at", "activation_digest") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING "id" [["name", "Example User"], ["email", "example#railstutorial.org"], ["password_digest", "$2a$10$tU5lWI6OSivx.9gONACjI.EHDrPgdhyQ9w/5rp6MxitVRpaRilbZu"], ["admin", "t"], ["activated", "t"], ["activated_at", "2015-12-08 20:06:39.898039"], ["created_at", "2015-12-08 20:06:40.199321"], ["updated_at", "2015-12-08 20:06:40.199321"], ["activation_digest", "$2a$10$kI/gNShPNgjz387uCxKBW.XT5OpYOJvL0ayb0G9EXRt6TqxgXjzTm"]]
(2.0ms) COMMIT
User Store (5.9ms) {"id":1,"exception":["Faraday::ConnectionFailed","Connection refused - connect(2)"]}
rake aborted!
production.rb
Elasticsearch::Model.client = Elasticsearch::Client.new host: ENV['search_box_url']
I've made addition to my User model and Gemfile before heroku deploy. My searchbar is working without them on localhost.
user.rb
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
Gemfile
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'puma', '2.11.1'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'
end

Ruby On Rails callbacks don't work on Heroku, but work locally

I've been working on a school appplication using rails_admin. Everything was working fine locally but when I push to Heroku the callbacks I defined in my models are not used, not even the most simple. So I come to you asking if someone has encountered a problem like this before or could help me interpret my logs because I cannot find the reason for this.
First, this is what my Gemfile looks like:
source 'https://rubygems.org'
ruby '2.2.0'
group :development, :test do
gem 'railroady'
end
# For documenting models automatically
gem 'annotate', '~> 2.6.6'
# For styling all HTML using SASS
gem 'bourbon'
gem 'neat'
gem 'bitters'
# For using creating SQL triggers inside models
gem 'hairtrigger'
# For creating seed data files from existing data in the database
gem 'seed_dump'
# Used for translations of the mailer and account confirmations
gem 'devise-i18n'
# User permissions and login
gem 'devise'
gem 'cancancan', '~> 1.10'
gem "rolify"
gem "figaro"
gem "rails_admin"
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record on the development environment
gem 'sqlite3', group: :development
# Use PostgreSQL as the database for Active Record on the production environment
gem 'pg', group: :production
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0', group: :doc
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring', group: :development
gem 'rails_12factor', group: :production
And this is the models I'm using callbacks in:
region.rb
# == Schema Information
#
# Table name: regions
#
# id :INTEGER not null, primary key
# name :varchar
# key :varchar
# created_at :datetime not null
# updated_at :datetime not null
#
class Region < ActiveRecord::Base
has_many :events, :dependent => :destroy, :inverse_of => :region
has_and_belongs_to_many :staff_members
before_create :generate_key
rails_admin do
visible do
bindings[:controller].current_user.roles.first.name == "super_admin"
end
list do
field :id
field :name
field :key
end
edit do
field :name do
required true
help "Por favor llena este campo."
end
end
end
private
def generate_key
self.key = self.name[0..1]
end
end
team.rb
# == Schema Information
#
# Table name: teams
#
# id :INTEGER not null, primary key
# name :varchar
# key :varchar
# date_of_registration :date
# company_name :varchar
# category_id :integer
# address_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# winner :boolean
#
class Team < ActiveRecord::Base
belongs_to :category, :inverse_of => :teams
belongs_to :address, :inverse_of => :teams
has_many :evaluations, :dependent => :destroy, :inverse_of => :team
has_many :team_members, :dependent => :destroy, :inverse_of => :team
has_and_belongs_to_many :events
before_save :generate_key
def team_label_method
"#{self.key} - #{self.name}"
end
rails_admin do
object_label_method do
:team_label_method
end
list do
field :id do
column_width 40
end
field :name do
column_width 100
end
field :key do
column_width 90
end
field :company_name do
column_width 100
end
field :category do
column_width 70
end
field :events do
column_width 100
end
field :winner do
column_width 10
end
field :address do
column_width 50
end
end
edit do
field :name do
required true
help "Por favor llena este campo."
end
#field :key do
# required true
# help "Por favor llena este campo."
#end
field :company_name do
required true
help "Por favor llena este campo."
end
field :category do
required true
help "Por favor llena este campo."
end
field :winner do
default_value = false
help "Llenar sólo si este equipo es ganador del concurso nacional."
end
field :address do
required true
help "Por favor llena este campo."
end
field :team_members
field :events do
required true
help "Por favor llena este campo."
end
field :date_of_registration do
required true
help "Por favor llena este campo."
end
end
end
private
def generate_key
standing = "R"
self.events.each do |current_event|
if current_event.event_type == "Nacional"
standing = "N"
end
end
if self.winner == true
standing = "G"
end
region_key = self.events.last.region.key
year = self.date_of_registration.year
id = self.id.to_s.rjust(3, '0')
category = self.category.key
special = 0
case self.category.key
when "S1"
special = 1
when "S2"
special = 2
when "S3"
special = 3
when "S4"
special = 4
end
self.key = "#{standing}#{region_key}#{year}#{id}#{category}#{special}".upcase
end
end
This is what the logs on Heroku look like when I try to create a new Region:
2015-06-02T21:05:45.566768+00:00 heroku[router]: at=info method=GET path="/admin/region?_pjax=%5Bdata-pjax-container%5D" host=sistema-de-evaluaciones-amte.herokuapp.com request_id=887af50d-bfb8-4a96-889d-e858d980838e fwd="189.241.62.189" dyno=web.1 connect=1ms service=415ms status=200 bytes=11925
2015-06-02T21:05:45.512300+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/rails_admin/main/index.html.haml within layouts/rails_admin/pjax (296.2ms)
2015-06-02T21:05:45.548529+00:00 app[web.1]: Completed 200 OK in 360ms (Views: 321.1ms | ActiveRecord: 22.2ms)
2015-06-02T21:05:47.282570+00:00 heroku[router]: at=info method=GET path="/admin/region/new?_pjax=%5Bdata-pjax-container%5D" host=sistema-de-evaluaciones-amte.herokuapp.com request_id=d8566b9a-943a-4265-afd2-6f339c52c633 fwd="189.241.62.189" dyno=web.1 connect=2ms service=59ms status=200 bytes=3960
2015-06-02T21:05:47.224731+00:00 app[web.1]: Processing by RailsAdmin::MainController#new as HTML
2015-06-02T21:05:47.260190+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/rails_admin/main/_submit_buttons.html.haml (12.7ms)
2015-06-02T21:05:47.224784+00:00 app[web.1]: Parameters: {"_pjax"=>"[data-pjax-container]", "model_name"=>"region"}
2015-06-02T21:05:47.272787+00:00 app[web.1]: Completed 200 OK in 48ms (Views: 34.2ms | ActiveRecord: 3.7ms)
2015-06-02T21:05:47.245920+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/rails_admin/main/_form_field.html.haml (1.3ms)
2015-06-02T21:05:47.222221+00:00 app[web.1]: Started GET "/admin/region/new?_pjax=%5Bdata-pjax-container%5D" for 189.241.62.189 at 2015-06-02 21:05:47 +0000
2015-06-02T21:05:47.260810+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/rails_admin/main/new.html.haml within layouts/rails_admin/pjax (21.0ms)
2015-06-02T21:05:50.197718+00:00 app[web.1]: Started POST "/admin/region/new" for 189.241.62.189 at 2015-06-02 21:05:50 +0000
2015-06-02T21:05:50.336844+00:00 app[web.1]: Processing by RailsAdmin::MainController#index as HTML
2015-06-02T21:05:50.336854+00:00 app[web.1]: Parameters: {"model_name"=>"region"}
2015-06-02T21:05:50.447221+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/rails_admin/main/index.html.haml within layouts/rails_admin/application (96.7ms)
2015-06-02T21:05:50.199887+00:00 app[web.1]: Processing by RailsAdmin::MainController#new as HTML
2015-06-02T21:05:50.199969+00:00 app[web.1]: Parameters: {"utf8"=>"✓", "authenticity_token"=>"jajkJUlQhU2i1z0io6pmDe/NZkzB1kA2hGWL8dYauCb22TYFftstrNop57hKTF2Ye0DxS1SNbZt/WQGoHWn+6w==", "region"=>{"name"=>"Prueba"}, "return_to"=>"https://sistema-de-evaluaciones-amte.herokuapp.com/admin/region", "_save"=>"", "model_name"=>"region"}
2015-06-02T21:05:50.224054+00:00 app[web.1]: Redirected to https://sistema-de-evaluaciones-amte.herokuapp.com/admin/region
2015-06-02T21:05:50.224993+00:00 app[web.1]: Completed 302 Found in 24ms (ActiveRecord: 10.2ms)
2015-06-02T21:05:50.334556+00:00 app[web.1]: Started GET "/admin/region" for 189.241.62.189 at 2015-06-02 21:05:50 +0000
2015-06-02T21:05:50.240345+00:00 heroku[router]: at=info method=POST path="/admin/region/new" host=sistema-de-evaluaciones-amte.herokuapp.com request_id=346211ad-fcf1-4012-9239-3884d01ff0a3 fwd="189.241.62.189" dyno=web.1 connect=1ms service=42ms status=302 bytes=1218
2015-06-02T21:05:50.454815+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/layouts/rails_admin/_navigation.html.haml (5.5ms)
2015-06-02T21:05:50.454724+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/layouts/rails_admin/_secondary_navigation.html.haml (4.9ms)
2015-06-02T21:05:50.485504+00:00 app[web.1]: Rendered vendor/bundle/ruby/2.2.0/gems/rails_admin-0.6.7/app/views/layouts/rails_admin/pjax.html.haml (10.2ms)
2015-06-02T21:05:50.486076+00:00 app[web.1]: Completed 200 OK in 149ms (Views: 114.7ms | ActiveRecord: 24.4ms)
2015-06-02T21:05:50.502507+00:00 heroku[router]: at=info method=GET path="/admin/region" host=sistema-de-evaluaciones-amte.herokuapp.com request_id=e2439dad-9f8d-407b-b3c8-5229bad08b58 fwd="189.241.62.189" dyno=web.1 connect=6ms service=167ms status=200 bytes=16948
And this is what I see when I do the same in my local server, as you can see, in the POST block it is clear that the "key" element is an argument for the insert query.
Started POST "/admin/region/new" for 127.0.0.1 at 2015-06-02 16:10:18 -0500
Processing by RailsAdmin::MainController#new as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"r8fQgZOsomw4C3P/aL/byEqEIY+BnBAm0WpCdNzYPf+n0v1yENTdUlXE/AfT5JBValjfKVmFubfKIQipxSX1qw==", "region"=>{"name"=>"Prueba"}, "return_to"=>"http://localhost:3000/admin/region", "_save"=>"", "model_name"=>"region"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
Role Load (0.2ms) SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = ? AND (((roles.name = 'super_admin') AND (roles.resource_type IS NULL) AND (roles.resource_id IS NULL))) [["user_id", 1]]
Role Load (0.3ms) SELECT "roles".* FROM "roles" INNER JOIN "users_roles" ON "roles"."id" = "users_roles"."role_id" WHERE "users_roles"."user_id" = ? ORDER BY "roles"."id" ASC LIMIT 1 [["user_id", 1]]
(0.3ms) begin transaction
SQL (0.6ms) INSERT INTO "regions" ("name", "created_at", "updated_at", "key") VALUES (?, ?, ?, ?) [["name", "Prueba"], ["created_at", "2015-06-02 21:10:18.391401"], ["updated_at", "2015-06-02 21:10:18.391401"], ["key", "Pr"]]
(150.7ms) commit transaction
Redirected to http://localhost:3000/admin/region
Completed 302 Found in 175ms (ActiveRecord: 152.2ms)
I found the error! It had to do with an SQL trigger someone else on the team directly created on the PostgreSQL database on Heroku on an earlier stage of development because it was being called at the same time as the callback, once I dropped it everything started to work as intended.

Neo4j.rb version 3.0 slow performance RoR, over 1024ms for all queries

Below is the gem i am using
gem 'neo4j', github: 'andreasronge/neo4j
and Below are the model User and friend:
User.rb
class User
include Neo4j::ActiveNode
property :name, :type => String, :index => :exact
property :mood, :type => String
property :status, :type => String
property :dob, :type => DateTime, :index => :exact
property :uid, :type => String, :index => :exact, :unique => true
property :username, :type => String
property :email, :type => String, :index => :exact
property :gender, :type => String, :index => :exact
property :remember_token, :type => String, :index => :exact
property :fb_access_token, :type => String, :index => :exact
scope :gender_filter, ->(g){ where(gender: g)}
property :friends_list
serialize :friends_list
#before_save :create_remember_token
validates :email, :uniqueness => true
has_many :both, :friends, model_class: User, rel_class: Friend
has_many :both, :friend_girls, model_class: User, rel_class: Friend_girl
has_many :both, :friend_boys, model_class: User, rel_class: Friend_boy
has_many :both, :places, model_class: Location, rel_class: Place
private
def create_remember_token
self.remember_token = SecureRandom.urlsafe_base64
end
end
Friend.rb
class Friend
include Neo4j::ActiveRel
property :provider, :type => String
from_class User
to_class User
type 'friends'
end
Below is the console logs for query exectution:
CYPHER 1022ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1
User#friend_boys 1077ms MATCH (user0:`User`), (result:`User`), user0-[rel0:`friend_boys` {_classname: "Friend_boy"}]-(result:`User`) WHERE ID(user0) = 0 RETURN resu
lt LIMIT 8
Rendered users/_list.html.erb (7425.9ms)
Rendered users/friends.html.erb within layouts/application (7456.0ms)
Rendered layouts/_shim.html.erb (1.0ms)
User#places 1063ms MATCH (user0:`User`), (result:`Location`), user0-[rel0:`places` {_classname: "Place"}]-(result:`Location`) WHERE ID(user0) = 0 RETURN result
Rendered layouts/_header.html.erb (25855.1ms)
Rendered layouts/_sidebar.html.erb (3.0ms)
Completed 200 OK in 36067ms (Views: 33981.5ms)
But the same individual queries take around 350ms in Neo4j admin console.
I am using neo4j-commnunity edition '2.1.3'
Please help me with the performance, as this is too slow compared to other databases
Update 1:
As suggested I wiped out the data directory and re-installed neo4j-community (2.1.3) but nothing changed, performace was still slow so, I decided to install new version neo4j-community (2.1.5) keeping the existing data directory in-place, again same results. Then I removed data directory and again installed neo4j-community (2.1.5), this time I got better performance for some of the queries in my rails app, against over 1000ms for all queries in my pervious setup.
Below are the logs:
Instance 1:
CYPHER 2025ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"dZGEOm0aKxDYkIQ5PfGjnw"}
CYPHER 16ms MATCH (result:`User`) WHERE result.email = {result_email} AND NOT ID(result) = {record_neo_id} RETURN COUNT(result) AS count | {:record_neo_id=>171, :result_email=>"achal.rvce#gmail.com"}
Instance 2:
CYPHER 15ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"dZGEOm0aKxDYkIQ5PfGjnw"}
User#friend_girls 25ms MATCH (user171:`User`), (result:`User`), user171-[rel0:`friend_girls`]-(result:`User`) WHERE ID(user171) = {ID_user171_} RETURN result LIMIT 8 | {:ID_user171_=>171}
At instance 1:
As you can see for the second query, it just took 16ms compared to my previous setup attempts, which would always take more than 1000ms.
But for the first query, the performance is too slow, its over 2 sec.
At instance 2:
The same query which took over 2 sec, now took 15ms (probably query is cached). but this is not consistent, for consecutive execution of same query, sometimes it takes over 2 sec and sometimes less than 20ms.
At instance 3:
CYPHER 1033ms MATCH (n:`Location`) WHERE n.address = {n_address} RETURN n LIMIT 1 | {:n_address=>"Vijayanagar, Karnataka, India"}
CYPHER 14ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"dZGEOm0aKxDYkIQ5PfGjnw"}
CYPHER 90ms START start = node(171), end = node(173) CREATE start-[rel0:`places` {_classname: "Place"}]->end
CYPHER 16ms MATCH (result:`User`) WHERE result.email = {result_email} AND NOT ID(result) = {record_neo_id} RETURN COUNT(result) AS count | {:record_neo_id=>171, :result_email=>"achal.rvce#gmail.com"}
User#places 59ms MATCH (user171:`User`), (result:`Location`), user171-[rel0:`places`]-(result:`Location`) WHERE ID(user171) = {ID_user171_} RETURN count(result) AS count | {:ID_user171_=>171}
User#places 14ms MATCH (user171:`User`), (result:`Location`), user171-[rel0:`places`]-(result:`Location`) WHERE ID(user171) = {ID_user171_} RETURN result | {:ID_user171_=>171}
At instance 3 we can notice that only the first query is slow all other queries are fast.
Update 2:
Below is the log after bundle update
Started GET "/" for 127.0.0.1 at 2014-10-28 08:14:26 +0530
Processing by StaticPagesController#home as HTML
CYPHER 1030ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"xqbwLZFzaULDZUKihEql5Q"}
Rendered users/_default_pic.html.erb (3.0ms)
Rendered users/_pics_grid.html.erb (4.0ms)
User#places 5ms MATCH (user184:`User`), (result:`Location`), user184-[rel0:`places`]-(result:`Location`) WHERE ID(user184) = {ID_user184_} RETURN count(result) AS c
ount | {:ID_user184_=>184}
Rendered users/_places.html.erb (17.0ms)
Rendered users/_my_badges.html.erb (1.0ms)
Rendered users/_profile_pics.html.erb (0.0ms)
Rendered users/_show.html.erb (200.1ms)
Rendered static_pages/home.html.erb within layouts/application (204.2ms)
Rendered layouts/_shim.html.erb (0.0ms)
User#places 0ms MATCH (user184:`User`), (result:`Location`), user184-[rel0:`places`]-(result:`Location`) WHERE ID(user184) = {ID_user184_} RETURN result | {:ID_user
184_=>184}
Rendered layouts/_header.html.erb (499.6ms)
Rendered layouts/_sidebar.html.erb (3.0ms)
Completed 200 OK in 2100ms (Views: 1064.7ms)
Started GET "/" for 127.0.0.1 at 2014-10-28 08:14:35 +0530
Processing by StaticPagesController#home as HTML
CYPHER 2036ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"xqbwLZFzaULDZUKihEql5Q"}
Rendered users/_default_pic.html.erb (2.0ms)
Rendered users/_pics_grid.html.erb (0.0ms)
User#places 5ms MATCH (user184:`User`), (result:`Location`), user184-[rel0:`places`]-(result:`Location`) WHERE ID(user184) = {ID_user184_} RETURN count(result) AS c
ount | {:ID_user184_=>184}
Rendered users/_places.html.erb (14.0ms)
Rendered users/_my_badges.html.erb (0.0ms)
Rendered users/_profile_pics.html.erb (17.9ms)
Rendered users/_show.html.erb (221.0ms)
Rendered static_pages/home.html.erb within layouts/application (226.1ms)
Rendered layouts/_shim.html.erb (0.0ms)
User#places 5ms MATCH (user184:`User`), (result:`Location`), user184-[rel0:`places`]-(result:`Location`) WHERE ID(user184) = {ID_user184_} RETURN result | {:ID_user
184_=>184}
Rendered layouts/_header.html.erb (474.4ms)
Rendered layouts/_sidebar.html.erb (1.0ms)
Completed 200 OK in 3094ms (Views: 1053.2ms)
Started GET "/assets/xeditable/img/loading.gif" for 127.0.0.1 at 2014-10-28 08:15:57 +0530
Started POST "/users/de30de56-7898-4d6b-8be4-c18a0c4915d6/update_status" for 127.0.0.1 at 2014-10-28 08:16:15 +0530
Processing by UsersController#update_status as JSON
Parameters: {"name"=>"xe_status", "value"=>"i am doing good", "pk"=>"1", "id"=>"de30de56-7898-4d6b-8be4-c18a0c4915d6"}
CYPHER 1016ms MATCH (n:`User`) WHERE n.remember_token = {n_remember_token} RETURN n LIMIT 1 | {:n_remember_token=>"xqbwLZFzaULDZUKihEql5Q"}
CYPHER 26ms MATCH (result:`User`) WHERE result.email = {result_email} AND NOT ID(result) = {record_neo_id} RETURN COUNT(result) AS count | {:record_neo_id=>184, :re
sult_email=>"achal.rvce#gmail.com"}
Completed 200 OK in 1305ms (Views: 1.0ms)
Gemfile
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
gem "will_paginate"
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data'
gem 'omniauth-facebook'
gem "geocoder"
gem 'rails4-autocomplete'
gem "font-awesome-rails"
gem 'koala'
gem 'newrelic_rpm'
gem 'jquery-turbolinks'
group :production do
gem 'rails_12factor'
end
gem 'jquery-ui-rails'
gem "string-urlize" # for making the title the primary key and work as an URL, see Neo4j.rb id_property
platforms :jruby do
gem 'neo4j-community', '~> 2.0.0'
end
gem 'sidekiq'
gem 'sinatra', require: false
gem 'slim'
gem 'neo4j'
gem 'cloudinary'
group :development do
gem 'spring'
gem 'os'
gem 'better_errors'
gem 'binding_of_caller'
gem 'meta_request'
gem 'debugger'
gem 'foreman'
end
Ruby version is 2.0.0 and Rails version is 4.0.2

Resources