Skip to content

Instantly share code, notes, and snippets.

View hayesr's full-sized avatar

Eric Hayes hayesr

View GitHub Profile
@hayesr
hayesr / finding-indexes.md
Created January 23, 2019 03:06
A tip for finding tables that need indexes

Finding which tables need extra indexes

pg_stat_user_tables is a fantastic system view that can show us invaluable information about the tables in our databases and can be used in diagnosing performance issues. Vacuum statistics like last_autovacuum and n_dead_tup will show if there are tables that aren’t being vacuumed efficiently and n_tup_hot_upd if you aren't performing HOT updates.

One of the things to look for first, though, is if there are tables that need new indexes as this can have a significant impact

# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
tracks_with_date = [
["6GZeeRql1kto2a7koIve9i", "2018-11-13 05:02:50 UTC"],
["6pXJV9kSdjyAcDsM32ftLK", "2018-11-13 05:02:50 UTC"],
["5x9jMerOQr7oTF1GO4STRY", "2018-11-13 05:02:50 UTC"],
["2hLTFcVb0k2xpHXZblhu7Y", "2018-11-13 05:02:50 UTC"],
["77L5jfCpmpkDma5lXjG6oX", "2018-11-13 05:02:50 UTC"],
["6rux2bYOCSr2woxnQsoUE3", "2018-11-13 05:02:50 UTC"],
["0gjknY5vRTKbzMos2hhfN7", "2018-11-13 05:02:50 UTC"],
["0ZHn1GiKfyLgpvEks2wBcn", "2018-11-13 05:02:50 UTC"],
["25EmPX0QaVUOzi2sG3fZEp", "2018-11-13 05:02:50 UTC"],
@hayesr
hayesr / component_presenter.rb
Created May 9, 2025 17:45
A simple component class for Rails
# Your component classes can inherit from this
class ComponentPresenter
# A 'macro' to define the partial path at the top of the class like:
# partial_path: 'components/popover'
# Or just define your own partial_path method
#
def self.partial_path(path)
define_method(:partial_path) do
path
end