Browse Source

pagy initializer

main
pvincent 4 weeks ago
parent
commit
142d656e4e
  1. 3
      Procfile.dev
  2. 4
      app/views/scores/index.html.erb
  3. 1
      config/environments/development.rb
  4. 6
      config/initializers/pagy.rb
  5. 20
      lib/semantic/subscribers/active_record.rb

3
Procfile.dev

@ -1,3 +1,2 @@
web: RUBY_DEBUG_OPEN=true bundle exec -- rails server --port "${RAILS_PORT:-7500}"
web: bundle exec -- rails server --port "${RAILS_PORT:-7500}"
css: bundle exec -- rails tailwindcss:watch

4
app/views/scores/index.html.erb

@ -4,8 +4,8 @@
ACTION_VIEW = <%=Live::Constants::ACTION_VIEW%><br/>
ACTIVE_RECORD = <%=Live::Constants::ACTIVE_RECORD%><br/>
<%= Score.first %>
<%= Score.first %>
<%= Score.last %>
<%= Score.last %>
<div class="m-5 flex justify-end">
<%= link_to "New score", new_score_path, class: "border rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>

1
config/environments/development.rb

@ -1,4 +1,5 @@
require 'active_support/core_ext/integer/time'
require 'debug/open_nonstop' if Rails.application.server? # opt-in for debugger
Rails.application.configure do # rubocop:disable Metrics/BlockLength
# Settings specified here will take precedence over those in config/application.rb.

6
config/initializers/pagy.rb

@ -0,0 +1,6 @@
require 'pagy/extras/overflow'
require 'pagy/extras/array'
Pagy::DEFAULT[:overflow] = :last_page
Pagy::DEFAULT[:limit] = 10 # items per page
Pagy::I18n.load({ locale: 'fr' }, { locale: 'en' })

20
lib/semantic/subscribers/active_record.rb

@ -4,20 +4,24 @@ module Semantic
class ActiveRecord < LogSubscriber
include AnsiColors
IGNORE_PAYLOAD_NAMES = %w[SCHEMA EXPLAIN].freeze
def sql(event)
name = event.payload[:name]
return if name == 'SCHEMA'
return if IGNORE_PAYLOAD_NAMES.include?(name)
sql = event.payload[:sql]
cached = event.payload[:cached]
row_count = event.payload[:row_count]
logger.debug("#{name}: #{sql} cached=#{cached} count=#{row_count}")
if name.end_with?('Load')
name = event.payload[:cached] ? "#{name} (cached)" : "#{name} (#{event.payload[:row_count]})"
end
name = colorize(name, TEXT_CYAN)
sql = colorize(event.payload[:sql], TEXT_BLUE)
logger.debug("#{name} #{sql}")
end
def instantiation(event)
class_name = event.payload[:class_name]
record_count = event.payload[:record_count]
logger.debug("instantiate #{class_name} #{record_count} times")
# class_name = event.payload[:class_name]
# record_count = event.payload[:record_count]
# logger.debug("instantiate #{class_name} #{record_count} times")
end
def strict_loading_violation(event) = any_hook event

Loading…
Cancel
Save