Ruby on Rails - Small activerecord and view rendering time yet big response time - ruby-on-rails-4

I have a Ruby on Rails application that is working fine for most of the API requests but for some API requests it just hangs. ActiveRecord queries are made in small time and also view is rendered in small time as well but yet response time is very big.
Rails version is 4.2.5 and Ruby version is 2.2.0, Database that I am using is Postgresql. Below I am attaching my Gemfile and also production log and also the code for which this is happening.
Production.log
I, [2019-09-07T09:23:45.748270 #22745] INFO -- : Started GET "/api/v3/restaurants/1/accepted_orders?skip_search=1" for
165.228.89.233 at 2019-09-07 09:23:45 +0000
I, [2019-09-07T09:23:45.753331 #22745] INFO -- : Processing by Api::V3::Staff::OrdersController#accepted_index as JSON
I, [2019-09-07T09:23:45.753387 #22745] INFO -- : Parameters: {"skip_search"=>"1", "id"=>"1"}
D, [2019-09-07T09:23:45.756807 #22745] DEBUG -- : User Load (2.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 6]]
D, [2019-09-07T09:23:45.761643 #22745] DEBUG -- : User Load (3.9ms) SELECT "users".* FROM "users" WHERE "users"."uid" = $1 LIMIT 1 [["uid", "example#gmail.com"]]
D, [2019-09-07T09:23:45.765724 #22745] DEBUG -- : Eula Load (3.1ms) SELECT "eulas".* FROM "eulas" WHERE "eulas"."is_latest" = $1 LIMIT 1 [["is_latest", "t"]]
D, [2019-09-07T09:23:45.768793 #22745] DEBUG -- : Privacy Load (2.7ms) SELECT "privacies".* FROM "privacies" WHERE "privacies"."is_latest" = $1 LIMIT 1 [["is_latest", "t"]]
D, [2019-09-07T09:23:45.772602#22745] DEBUG -- : Restaurant Load (3.0ms) SELECT "restaurants".* FROM "restaurants" WHERE "restaurants"."id" = $1 LIMIT 1 [["id", 1]]
D, [2019-09-07T09:23:46.293350 #22745] DEBUG -- : Order Load (519.6ms) SELECT "orders".* FROM "orders" WHERE "orders"."restaurant_id" IN (1)
D, [2019-09-07T10:44:50.564263 #22745] DEBUG -- : (19.8ms) SELECT COUNT(*) FROM "orders" WHERE "orders"."status" = $1 AND "orders"."restaurant_id" = 1 AND ( DATE(orders.created_at) >= '2019-09-07 09:45:50 UTC') [["status", 1]]
D, [2019-09-07T10:44:50.577108 #22745] DEBUG -- : (11.7ms) SELECT COUNT(*) FROM "orders" WHERE "orders"."status" = $1 AND "orders"."restaurant_id" = 1 AND ( DATE(orders.created_at) >= '2019-09-07 09:45:50 UTC') [["status", 0]]
D, [2019-09-07T10:44:50.580691 #22745] DEBUG -- : User Exists (1.5ms) SELECT 1 AS one FROM "users" WHERE ("users"."email" = 'example#gmail.com' AND "users"."id" != 6) LIMIT 1
D, [2019-09-07T10:44:50.582116 #22745] DEBUG -- : User Exists (0.6ms) SELECT 1 AS one FROM "users" WHERE ("users"."username" = 'Staff 1' AND "users"."id" != 6) LIMIT 1
D, [2019-09-07T10:44:50.584594#22745] DEBUG -- : User Exists (1.8ms) SELECT 1 AS one FROM "users" WHERE ("users"."phone_number" = '+777777777' AND "users"."id" != 6) LIMIT 1
I, [2019-09-07T10:44:50.586265 #22745] INFO -- : Completed 200 OK in 4864833ms (Views: 0.3ms | ActiveRecord:
570.2ms)
Part of code having the error
api :GET, '/v3/restaurants/:id/accepted_orders', 'Returns all accepted orders of a restaurant (for staff and owners)'
param :id, String, desc: 'id of the restaurant', required: true
def accepted_index
query = " DATE(orders.created_at) >= '#{59.minutes.ago}'" if current_user.staff?
accepted = Order.where(status: Order.statuses[:accepted], restaurant: #restaurant).where(query)
pending = Order.where(status: Order.statuses[:pending], restaurant: #restaurant).where(query)
render json: {accepted_count: accepted.count, pending_count: pending.count}
end
Gemfile
source 'https://rubygems.org'
ruby '2.2.0'
gem 'rails', '4.2.5'
gem 'pg'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'jbuilder', '~> 2.0'
gem 'annotate'
gem 'activeadmin', github: 'activeadmin'
gem 'paper_trail', '~> 4.0.0'
gem 'dotenv-rails'
# MailChimp integration
gem 'gibbon'
gem 'google_directions'
gem 'geocoder'
gem 'stripe', :git => 'https://github.com/stripe/stripe-ruby'
# The push notification service.
gem 'rpush', github: 'rpush/rpush'
gem 'prawn-rails'
gem 'prawn-table'
gem 'active_admin_datetimepicker'
gem 'phony_rails'
gem 'closure_tree'
gem 'whenever', require: false
group :development, :test do
gem 'byebug'
end
group :development do
gem 'pry'
gem 'web-console', '~> 2.0'
gem 'spring'
gem 'letter_opener'
end
gem 'apipie-rails'
gem 'devise'
gem 'high_voltage'
gem 'simple_form'
gem 'rack-cors', :require => 'rack/cors'
gem 'omniauth'
gem 'devise_token_auth'
gem 'sidekiq', '~> 4.0', '>= 4.0.1'
# gem 'ckeditor', '~> 4.1', '>= 4.1.5'
gem 'socket.io-client-simple'
gem 'houston'
gem 'fancybox-rails', '~> 0.3.0'
gem 'mini_magick', '~> 4.3', '>= 4.3.6'
gem 'carrierwave', '~> 0.10.0'
gem 'fog', '~> 1.36'
gem 'chosen-rails'
gem 'twilio-ruby', '~> 4.11.1'
group :development do
gem 'better_errors'
gem 'quiet_assets'
gem 'rails_layout'
gem 'spring-commands-rspec'
gem 'capistrano', '~> 3.1.0'
gem 'capistrano-bundler', '~> 1.1.2'
gem 'capistrano-rails', '~> 1.1.1'
gem 'capistrano-rvm', github: "capistrano/rvm"
gem 'capistrano-sidekiq'
gem 'rest-client'
end
group :development, :test do
gem 'factory_girl_rails'
gem 'faker'
gem 'rspec'
gem 'fakeredis'
gem 'rspec-rails'
gem 'shoulda-matchers', '~> 3.0'
gem 'shoulda-callback-matchers', '~> 1.1.1'
gem 'redis-namespace'
end
group :test do
gem 'capybara'
gem 'database_cleaner'
gem 'launchy'
gem 'selenium-webdriver'
end
gem 'sinatra', :require => nil
On production server I am using nginx and Passenger.
Thanks

Related

Sure you're not looking for /faye ? showing on heroku for my chatt application

A simple chat demo application i have deployed on heroku but it show me 'Sure you're not looking for /faye ?' instead of running application..
I have gem structure as :
source 'https://rubygems.org'
gem "private_pub"
gem "thin"
gem 'devise'
gem 'rails', '4.2.6'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails'
gem 'therubyracer', platforms: :ruby
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
group :development, :test do
gem 'byebug'
gem 'test-unit', '~> 3.0'
end
group :development do
gem 'spring'
gem 'sqlite3'
end
group :production do
gem 'rails_12factor'
gem 'pg'
end
**
And my Procfile that i am trying to run on heroku:
web: bundle exec rackup private_pub.ru -s thin -p $PORT -E production
::::privat_pub.yml file :
development:
server: "http://localhost:9292/faye"
secret_token: "secret"
test:
server: "http://localhost:9292/faye"
secret_token: "secret"
production:
server: "http://chatmanoj.herokuapp.com/faye"
secret_token: "fa3a4537eb321521a40fce4fa4d7bb055436e1f6ba5e74a3c85ec683c5abe997"
signature_expiration: 3600 # one hour

How to deploy Rails App using private_pub to heroku

I am trying to run my app on heroku which is using private_pub gem . Here in my local server I am running it perfectly . How can I push this app in heroku and run there perfectly . Here is my gem file :
source 'https://rubygems.org'
gem 'rails', '4.2.1'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'bcrypt', '3.1.7'
gem 'mailboxer'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sdoc', '0.4.0', group: :doc
gem 'devise'
gem 'paperclip', '~> 4.1'
gem 'will_paginate', '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'faker', '1.4.2'
gem 'chosen-rails'
gem 'jquery-turbolinks'
gem 'private_pub'
gem "thin"
#gem 'puma', '2.11.1'
group :development, :test do
#gem 'sqlite3', '1.3.9'
gem 'mysql2'
#gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
gem 'byebug', '3.4.0'
end
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'puma', '2.11.1'
end
And This is my private_pub.yml file :
development:
server: "http://localhost:9292/faye"
secret_token: "secret"
test:
server: "http://localhost:9292/faye"
secret_token: "secret"
production:
server: "https://sheltered-sea-1191.herokuapp.com/faye"
secret_token: "mysecret key"
signature_expiration: 3600 # one hour
How can I push this app in heroku help me to push this on herok .
For this above question I have created a new heroku app and I put this code as it is told in this tutorial https://webprogramming29.wordpress.com/2013/02/15/setup-privatepub-or-faye-on-heroku/
And then I edited my code using the following tutorial and it is working great

cucumber click dialog remove

Checking if attribute was excluded, confirm dialog, using rails 4
Quando(/^confirmo$/) do
page.execute_script 'window.confirm = function () { return true }'
end
return error
> Capybara::Driver::Base#execute_script (Capybara::NotSupportedByDriverError)
./features/step_definitions/covenats_steps.rb:80:in `/^confirmo$/'
features/covenats.feature:48:in `E confirmo'
gems install
group :test do
gem 'cucumber-rails', :require => false
gem 'capybara', '~> 2.4'
gem 'database_cleaner', '~> 1.3'
gem 'rspec-rails', '~> 3.1.0'
end

Prawn in a Ruby on Rails app, failing on production

I am stuck on an issue with running prawn in production.
I have followed the Railscast (revised http://railscasts.com/episodes/153-pdfs-with-prawn-revised?view=asciicast) pretty much to the letter. It works great in my development environment (Mac OS X 10.9.1) but causes unicorn to falter on my server. My production server is (Redhat => Red Hat Enterprise Linux Server release 6.4 (Santiago)). I have the gem installed via Gemfile.
Gemfile:
gem 'prawn'
gem 'prawn-qrcode'
Controller: (show action)
def show
##classroom = Classroom.find(params[:id])
#classroom = find_classroom
#page_title = #classroom.location.name
#classroom_alt = #classroom.location.name + " - " + #classroom.room_number
#building = find_building(#classroom.location_id)
#owner = Owner.find(#classroom.owner_id)
#room_schedule_contact = RoomScheduleContact.find_by rmrecnbr:(#classroom.rmrecnbr)
#building_image = #building.picture.url(:medium).to_s
#building_sign_image = #building.building_sign.url(:thumb).to_s
#search = Classroom.search(params[:search])
##classroom_herprod = Building.find(params[:location_id]).building_short_code
respond_to do |format|
format.html # show.html.erb
format.png { render :qrcode => "http://rooms.lsa.umich.edu/classrooms/#{#classroom.facility_code_heprod}", :level => :l, :unit => 8 }
format.pdf do
pdf = ClassroomPdf.new(#classroom)
send_data pdf.render, type: "application/pdf",
disposition: "inline"
end
end
end
I have a pdfs directory with a classroom_pdf.rb file that includes the following.
class ClassroomPdf < Prawn::Document
def initialize(classroom)
super(top_margin: 70)
text "This is a pdf"
end
end
(This is stripped down from what I had, but it is the most basic version that works on my dev system and fails on production).
I am running the following
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]
gem 'rails', '4.0.2'
The error in the unicorn.stderr.log is as follows.
E, [2014-02-07T12:39:20.400750 #7300] ERROR -- : reaped #<Process::Status: pid 7306 exit 1> worker=1
I, [2014-02-07T12:39:20.401257 #7300] INFO -- : worker=1 spawning...
I, [2014-02-07T12:39:20.463964 #7529] INFO -- : worker=1 spawned pid=7529
I, [2014-02-07T12:39:20.521524 #7529] INFO -- : Refreshing Gem list
E, [2014-02-07T12:39:29.938423 #7326] ERROR -- : uninitialized constant Prawn (NameError)
/var/www/rooms.lsa.umich.edu/html/iris/releases/20140207173433/app/pdfs/classroom_pdf.rb:1:in `<top (required)>'
/var/www/rooms.lsa.umich.edu/html/iris/shared/bundle/ruby/2.0.0/gems/railties-4.0.1/lib/rails/engine.rb:465:in `block (2 levels) in eager_load!'
Here is the gemfile
source 'https://rubygems.org'
##gem 'rails', '3.2.14'
gem 'rails', '4.0.2'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
#gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
gem "haml"
#gem 'anjlab-bootstrap-rails', :require => 'bootstrap-rails'
gem 'bootstrap-sass', '~> 3.1.0'
#gem 'google-analytics-rails'
gem 'font-awesome-rails'
gem 'protected_attributes'
gem 'modernizr-rails'
gem "jquery-rails"
gem "devise", "3.0.3"
gem "cancan", ">= 1.6.9"
gem "rolify", ">= 3.2.0"
gem 'newrelic_rpm'
# QR-Code generation
gem 'rqrcode-rails3'
gem 'mini_magick'
gem 'prawn'
#gem 'prawn', '1.0.0.rc2'
gem 'prawn-qrcode'
#gem 'prawnto'
gem 'capistrano', '2.15.5'
#gem 'capistrano'
gem "simple_form"
gem 'will_paginate', '~> 3.0.5'
gem "therubyracer", :group => :assets, :platform => :ruby
gem 'will_paginate-bootstrap'
#gem 'kaminari'
## Used for uploading and resizing images (Need both paperclip and mini_magick)
gem "paperclip", "3.5.1"
#gem "meta_search"
gem "ransack"
gem 'annotate', ">=2.6.0"
group :production do
gem 'unicorn'
end
Any ideas?
It turns out that I needed to manually reboot unicorn for it to properly load the new gem file.

Active admin in Rails 4 throws error "Invalid option key"

Rails 4 app working just fine until Active Admin is included (from this thread) in the gemfile.
My Gemfile:
gem 'rails', '4.0.0'
gem 'rails_12factor', group: :production
gem 'pg'
gem 'sass-rails', '~> 4.0.0.rc1'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'activeadmin', github: 'gregbell/active_admin'
gem 'protected_attributes'
gem 'rails-observers'
gem 'actionpack-page_caching'
gem 'actionpack-action_caching'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
gem 'sdoc', require: false
end
The error is thrown while attempting to start the rails server after a clean bundle install.
/var/lib/gems/1.9.1/gems/actionpack-4.0.0/lib/action_controller/railtie.rb:55:in `block (3 levels) in <class:Railtie>': Invalid option key: page_cache_directory= (RuntimeError)
Any help is greatly appreciated!
Try to use:
http://blog.remarkablelabs.com/2012/12/russian-doll-caching-cache-digests-rails-4-countdown-to-2013
Or:
run bundle install and reinstall actionpack-action_caching
https://github.com/rails/actionpack-action_caching