Skip to content

Commit

Permalink
fix n+1 queries . devise register parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
michelson committed Aug 19, 2023
1 parent 20601e8 commit 486d585
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 26 deletions.
12 changes: 6 additions & 6 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

class Users::RegistrationsController < Devise::RegistrationsController
# before_action :configure_sign_up_params, only: [:create]
# before_action :configure_account_update_params, only: [:update]
before_action :configure_sign_up_params, only: [:create]
before_action :configure_account_update_params, only: [:update]

# GET /resource/sign_up
# def new
Expand Down Expand Up @@ -42,13 +42,13 @@ class Users::RegistrationsController < Devise::RegistrationsController

# If you have extra params to permit, append them to the sanitizer.
def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
end

# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])
# end
def configure_account_update_params
devise_parameter_sanitizer.permit(:account_update, keys: [:username])
end

# The path used after sign up.
# def after_sign_up_path_for(resource)
Expand Down
8 changes: 4 additions & 4 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,16 +101,16 @@ def event_dates
def cover_url(size = nil)
url = case size
when :medium
self.cover.variant(resize_to_limit: [200, 200])&.processed&.url
self.cover.variant(resize_to_limit: [200, 200]) #&.processed&.url

when :large
self.cover.variant(resize_to_limit: [500, 500])&.processed&.url
self.cover.variant(resize_to_limit: [500, 500]) #&.processed&.url

when :small
self.cover.variant(resize_to_limit: [50, 50])&.processed&.url
self.cover.variant(resize_to_limit: [50, 50]) #&.processed&.url

else
self.cover.variant(resize_to_limit: [200, 200])&.processed&.url
self.cover.variant(resize_to_limit: [200, 200]) #&.processed&.url
end

url ? url : "daniel-schludi-mbGxz7pt0jM-unsplash-sqr-s-bn.png"
Expand Down
8 changes: 4 additions & 4 deletions app/models/playlist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ class Playlist < ApplicationRecord
def cover_url(size = nil)
url = case size
when :medium
self.cover.variant(resize_to_limit: [200, 200])&.processed&.url
self.cover.variant(resize_to_limit: [200, 200]) #&.processed&.url

when :large
self.cover.variant(resize_to_limit: [500, 500])&.processed&.url
self.cover.variant(resize_to_limit: [500, 500]) #&.processed&.url

when :small
self.cover.variant(resize_to_limit: [50, 50])&.processed&.url
self.cover.variant(resize_to_limit: [50, 50]) #&.processed&.url

else
self.cover.variant(resize_to_limit: [200, 200])&.processed&.url
self.cover.variant(resize_to_limit: [200, 200]) #&.processed&.url
end

url ? url : "daniel-schludi-mbGxz7pt0jM-unsplash-sqr-s-bn.png"
Expand Down
10 changes: 6 additions & 4 deletions app/models/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Track < ApplicationRecord
has_many :comments, as: :commentable

has_one_attached :cover

has_one_attached :audio
has_one_attached :mp3_audio
has_one_attached :zip
Expand Down Expand Up @@ -86,18 +87,19 @@ class Track < ApplicationRecord
end

def cover_url(size = nil)

url = case size
when :medium
self.cover.variant(resize_to_limit: [200, 200])&.processed&.url
self.cover.variant(resize_to_limit: [200, 200]) #&.processed&.url

when :large
self.cover.variant(resize_to_limit: [500, 500])&.processed&.url
self.cover.variant(resize_to_limit: [500, 500]) #&.processed&.url

when :small
self.cover.variant(resize_to_limit: [50, 50])&.processed&.url
self.cover.variant(resize_to_limit: [50, 50]) #&.processed&.url

else
self.cover.variant(resize_to_limit: [200, 200])&.processed&.url
self.cover.variant(resize_to_limit: [200, 200]) #&.processed&.url
end

url ? url : "daniel-schludi-mbGxz7pt0jM-unsplash-sqr-s-bn.png"
Expand Down
8 changes: 4 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ def has_invitations_left?
def avatar_url(size)
url = case size
when :medium
self.avatar.variant(resize_to_fill: [200, 200])&.processed&.url
self.avatar.variant(resize_to_fill: [200, 200]) #&.processed&.url

when :large
self.avatar.variant(resize_to_fill: [500, 500])&.processed&.url
self.avatar.variant(resize_to_fill: [500, 500]) #&.processed&.url

when :small
self.avatar.variant(resize_to_fill: [50, 50])&.processed&.url
self.avatar.variant(resize_to_fill: [50, 50]) #&.processed&.url

else
self.avatar.variant(resize_to_fill: [200, 200])&.processed&.url
self.avatar.variant(resize_to_fill: [200, 200]) #&.processed&.url
end

url ? url : "daniel-schludi-mbGxz7pt0jM-unsplash-sqr-s-bn.png"
Expand Down
4 changes: 2 additions & 2 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@
<div class="mt-6">

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= render "devise/shared/error_messages", resource: resource %>
<% #= render "devise/shared/error_messages", resource: resource %>
<div class="field">
<%= f.email_field :username %>
<%= f.text_field :username %>
</div>
<div class="field">
Expand Down
2 changes: 2 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class Application < Rails::Application
config.hosts << "chaskiq.sa.ngrok.io"
config.hosts << ENV['HOST']

config.active_storage.track_variants = true

# Configuration for the application, engines, and railties goes here.
#
# These settings can be overridden in specific environments using the files
Expand Down
2 changes: 1 addition & 1 deletion config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ default: &default
development:
prepared_statements: false
adapter: postgresql
database: <%= ENV.fetch('POSTGRES_DATABASE', 'rauversion_ror_development') %>
database: <%= ENV.fetch('POSTGRES_DATABASE', 'rauversion_ror_development_as_local') %>
username: <%= ENV.fetch('POSTGRES_USERNAME', 'postgres') %>
password: <%= ENV.fetch('POSTGRES_PASSWORD', '') %>
min_messages: warning
Expand Down
2 changes: 1 addition & 1 deletion config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
end

# Store uploaded files on the local file system (see config/storage.yml for options).
config.active_storage.service = :amazon
config.active_storage.service = :local

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
Expand Down

0 comments on commit 486d585

Please sign in to comment.