-
-
Notifications
You must be signed in to change notification settings - Fork 202
perf: EventCardComponent + Solid Cache for event listings #2684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1f54e96
deps: add solid_cache for fragment caching
mroderick 5cbf102
chore: add benchmark script for event listing performance
mroderick c176ed1
feat: add EventCardComponent with fragment caching
mroderick b50294f
Merge branch 'master' into feature/event-listing-perf-clean
mroderick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -129,3 +129,5 @@ gem 'scout_apm' | |
|
|
||
| gem 'carrierwave-aws', '~> 1.6' | ||
| gem 'sitemap_generator', '~> 7.0' | ||
|
|
||
| gem "solid_cache", "~> 1.0" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| <% cache @event.cache_key_with_version do %> | ||
| <div class="card mb-4" data-test="event"> | ||
| <div class="card-body"> | ||
| <div class="d-md-flex justify-content-md-between"> | ||
| <div class="order-md-2"> | ||
| <% if @event.chapter %> | ||
| <span class="badge bg-primary mb-3 mb-md-0"> | ||
| <%= link_to @event.chapter.name, @event.chapter.slug, class: "text-light text-decoration-none" %> | ||
| </span> | ||
| <% end %> | ||
| <% if user_presenter %> | ||
| <% if user_presenter.attending?(@event) %> | ||
| <span class="badge bg-success mb-3 mb-md-0"> | ||
| <%= link_to "Attending", @event.path, class: "text-light text-decoration-none" %> | ||
| </span> | ||
| <% end %> | ||
| <% if user_presenter.organiser? && user_presenter.event_organiser?(@event) %> | ||
| <span class="badge bg-secondary mb-3 mb-md-0"> | ||
| <%= link_to "Manage", @event.admin_path, class: "text-light text-decoration-none" %> | ||
| </span> | ||
| <% end %> | ||
| <% end %> | ||
| </div> | ||
| <div class="order-md-1"> | ||
| <h3 class="h5"> | ||
| <%= link_to @event.to_s, @event.path %> | ||
| <% if @event.venue.present? %> | ||
| at | ||
| <%= link_to @event.venue.name, @event.venue.website %> | ||
| <% end %> | ||
| </h3> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div class="mt-3"> | ||
| <p class="mb-0"> | ||
| <i class="far fa-calendar"></i> | ||
| <%= @event.date %> | ||
| </p> | ||
| <p> | ||
| <i class="far fa-clock"></i> | ||
| <%= @event.time %> | ||
| </p> | ||
| </div> | ||
|
|
||
| <div class="d-md-flex justify-content-md-between align-items-md-center"> | ||
| <% if @event.organisers.any? %> | ||
| <div class="mb-3 mb-md-0"> | ||
| <% @event.organisers.each do |organiser| %> | ||
| <%= image_tag(organiser.avatar(26), class: "rounded-circle", title: organiser.full_name, alt: organiser.full_name) %> | ||
| <% end %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <% if @event.sponsors.any? %> | ||
| <div class="ms-auto"> | ||
| <% @event.sponsors.each do |sponsor| %> | ||
| <%= link_to sponsor.website, class: "d-inline-block" do %> | ||
| <%= image_tag(sponsor.avatar.thumb.url, class: "sponsor-sm mx-1", alt: sponsor.name) %> | ||
| <% end %> | ||
| <% end %> | ||
| </div> | ||
| <% end %> | ||
|
|
||
| <% if @event.is_a?(MeetingPresenter) && @event.venue.present? %> | ||
| <div class="ms-auto"> | ||
| <%= link_to @event.venue.website, class: "d-inline-block" do %> | ||
| <%= image_tag(@event.venue.avatar.url, class: "sponsor-sm", alt: @event.venue.name) %> | ||
| <% end %> | ||
| </div> | ||
| <% end %> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| <% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| class EventCardComponent < ViewComponent::Base | ||
| def initialize(event_card:, user: nil) | ||
| @event = event_card | ||
| @user = user | ||
| end | ||
|
|
||
| # Wraps raw Member in MemberPresenter; double-wrapping a presenter is a no-op. | ||
| def user_presenter | ||
| @user && MemberPresenter.new(@user) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| - grouped_events.each do |date, workshops| | ||
| - grouped_events.each do |date, events| | ||
| .row | ||
| .col-12 | ||
| %h3.h5= date | ||
| .row | ||
| .col-md-8 | ||
| = render workshops | ||
| = render EventCardComponent.with_collection(events) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| development: | ||
| store_options: | ||
| max_age: <%= 60.days.to_i %> | ||
| max_size: <%= 256.megabytes %> | ||
| namespace: <%= Rails.env %> | ||
|
|
||
| test: | ||
| store_options: | ||
| max_age: <%= 60.days.to_i %> | ||
| max_size: <%= 256.megabytes %> | ||
| namespace: <%= Rails.env %> | ||
|
|
||
| production: | ||
| store_options: | ||
| max_age: <%= 60.days.to_i %> | ||
| max_size: <%= 500.megabytes %> | ||
| namespace: <%= Rails.env %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| ActiveRecord::Schema[7.2].define(version: 1) do | ||
| create_table "solid_cache_entries", force: :cascade do |t| | ||
| t.binary "key", limit: 1024, null: false | ||
| t.binary "value", limit: 536870912, null: false | ||
| t.datetime "created_at", null: false | ||
| t.integer "key_hash", limit: 8, null: false | ||
| t.integer "byte_size", limit: 4, null: false | ||
| t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size" | ||
| t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" | ||
| t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| class CreateSolidCacheEntries < ActiveRecord::Migration[8.1] | ||
| def change | ||
| create_table "solid_cache_entries", force: :cascade do |t| | ||
| t.binary "key", limit: 1024, null: false | ||
| t.binary "value", limit: 536870912, null: false | ||
| t.datetime "created_at", null: false | ||
| t.integer "key_hash", limit: 8, null: false | ||
| t.integer "byte_size", limit: 4, null: false | ||
| t.index ["byte_size"], name: "index_solid_cache_entries_on_byte_size" | ||
| t.index ["key_hash", "byte_size"], name: "index_solid_cache_entries_on_key_hash_and_byte_size" | ||
| t.index ["key_hash"], name: "index_solid_cache_entries_on_key_hash", unique: true | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/usr/bin/env ruby | ||
| # Run: DB_NAME=codebar_dump bundle exec ruby script/benchmark_events.rb | ||
| ENV["RAILS_ENV"] ||= "development" | ||
| require_relative "../config/environment" | ||
| require "benchmark" | ||
|
|
||
| session = ActionDispatch::Integration::Session.new(Rails.application) | ||
| session.host = "localhost" | ||
|
|
||
| def measure(session, path) | ||
| qc = 0 | ||
| cb = ->(*, **) { qc += 1 } | ||
| time = nil | ||
| ActiveSupport::Notifications.subscribed(cb, "sql.active_record") do | ||
| time = Benchmark.measure { session.get(path) } | ||
| end | ||
| [time.real, qc] | ||
| end | ||
|
|
||
| puts "=== Database: #{ActiveRecord::Base.connection_db_config.database} ===\n\n" | ||
|
|
||
| %w[/events/upcoming /events/past /events/past?page=2].each do |path| | ||
| ActiveRecord::Base.connection.query_cache.clear | ||
| Rails.cache.clear if Rails.cache | ||
|
|
||
| cold_t, cold_q = measure(session, path) | ||
| warm = 3.times.map { measure(session, path).first } | ||
|
|
||
| puts "#{path}" | ||
| puts " cold: #{cold_t.round(3)}s | #{cold_q} queries" | ||
| puts " warm: #{warm.sort[1].round(3)}s (min #{warm.min.round(3)}, max #{warm.max.round(3)})" | ||
| puts | ||
| end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: In the future, we can push up logic to this component, out of the view, but the conditions are very simple at the moment. No blocker!