From 039ccfa3af8c9f77402bf2847afbeb73b23111d8 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 23 Dec 2020 22:31:46 -0600 Subject: [PATCH] routes: optimize route order. Put the most used routes at the top of the file to optimize route performance. --- config/routes.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/config/routes.rb b/config/routes.rb index 27bb9c97d..94cd168a7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,11 @@ Rails.application.routes.draw do + resources :posts, only: [:index, :show, :update, :destroy] + resources :autocomplete, only: [:index] + + # XXX This comes *after* defining posts above because otherwise the paginator + # generates `/?page=2` instead of `/posts?page=2` on the posts#index page. + root "posts#index" + namespace :admin do resources :users, :only => [:edit, :update] resource :dashboard, :only => [:show] @@ -67,7 +74,6 @@ Rails.application.routes.draw do get :search end end - resources :autocomplete, only: [:index] resources :bans resources :bulk_update_requests do member do @@ -171,7 +177,9 @@ Rails.application.routes.draw do end resources :post_replacements, :only => [:index, :new, :create, :update] resources :post_votes, only: [:index] - resources :posts, only: [:index, :show, :update, :destroy] do + + # XXX Use `only: []` to avoid redefining post routes defined at top of file. + resources :posts, only: [] do resources :events, :only => [:index], :controller => "post_events" resources :replacements, :only => [:index, :new, :create], :controller => "post_replacements" resource :artist_commentary, :only => [:index, :show] do @@ -313,7 +321,5 @@ Rails.application.routes.draw do get "/mock/iqdbs/similar" => "mock_services#iqdbs_similar", as: "mock_iqdbs_similar" post "/mock/iqdbs/similar" => "mock_services#iqdbs_similar" - root :to => "posts#index" - get "*other", :to => "static#not_found" end