Skip to content

Commit

Permalink
Improve caching
Browse files Browse the repository at this point in the history
  • Loading branch information
jcraigk committed Nov 5, 2024
1 parent 614f252 commit d229f44
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
4 changes: 3 additions & 1 deletion app/api/api_v2/playlists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ class ApiV2::Playlists < ApiV2::Base

helpers do
def page_of_playlists
Rails.cache.fetch("api/v2/playlists?#{params.to_query}") do
cache_key = "api/v2/playlists?#{params.to_query}"
cache_key += "/#{current_user.id}" if params[:filter] == "liked" && current_user
Rails.cache.fetch(cache_key) do
playlists = Playlist.includes(:user)
.then { |p| apply_filter(p) }
.then { |p| apply_sort(p, :name, :asc) }
Expand Down
8 changes: 6 additions & 2 deletions app/api/api_v2/shows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ class ApiV2::Shows < ApiV2::Base

helpers do
def page_of_shows
Rails.cache.fetch("api/v2/shows?#{params.to_query}") do
cache_key = "api/v2/shows?#{params.to_query}"
cache_key += "/#{current_user.id}" if params[:liked_by_user] && current_user
Rails.cache.fetch(cache_key) do
shows = Show.published
.includes(
:venue,
Expand Down Expand Up @@ -186,7 +188,9 @@ def fetch_liked_track_ids(show)
end

def show_by_date
Rails.cache.fetch("api/v2/shows/#{params[:date]}") do
cache_key = "api/v2/shows/#{params[:date]}"
cache_key += "/#{current_user.id}" if params[:liked_by_user] && current_user
Rails.cache.fetch(cache_key) do
Show.published
.includes(
:venue,
Expand Down
6 changes: 4 additions & 2 deletions app/api/api_v2/tracks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ApiV2::Tracks < ApiV2::Base

helpers do
def page_of_tracks
Rails.cache.fetch("api/v2/tracks?#{params.to_query}") do
Rails.cache.fetch("api/v2/tracks?#{params.to_query}/#{current_user&.id}") do
tracks = Track.includes(
:mp3_audio_attachment,
:png_waveform_attachment,
Expand Down Expand Up @@ -98,7 +98,9 @@ def page_of_tracks
end

def track_by_id
Rails.cache.fetch("api/v2/tracks/#{params[:id]}") do
cache_key = "api/v2/tracks/#{params[:id]}"
cache_key += "/#{current_user.id}" if params[:liked_by_user] && current_user
Rails.cache.fetch(cache_key) do
Track.includes(
:show,
:songs,
Expand Down
9 changes: 5 additions & 4 deletions app/javascript/stylesheets/content.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,9 @@ main {

.date-link {
font-size: 0.9rem;
position: relative;
top: -3px;
margin-right: 0.1rem;
display: inline-block;
margin-right: 0.5rem;
display: inline-flex;
align-items: center;
width: 3.8rem;

&:hover {
Expand Down Expand Up @@ -270,6 +269,8 @@ main {
min-width: 1rem;
max-width: 60%;
padding-right: 1rem;
display: flex;
align-items: center;

.cover-art {
background-color: transparent;
Expand Down
13 changes: 3 additions & 10 deletions app/javascript/stylesheets/map.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
font-family: 'Open Sans Condensed', sans-serif;
font-size: 1.2rem;
background-color: $text-gray;
margin-right: 0.5rem;
margin-bottom: 0.5rem;
border-radius: $radius;
margin-right: 0.3rem;
margin-bottom: 0.3rem;
border-radius: 3px;
padding: 0.1rem 0.3rem;
color: white;
display: inline-block;
Expand All @@ -26,13 +26,6 @@
&:hover {
background-color: $control-gray;
color: $text-gray;

.date-link {
color: $text-gray;
}
}
.date-link {
color: white;
}
}

Expand Down

0 comments on commit d229f44

Please sign in to comment.