Skip to content

Commit

Permalink
fix(API): ensure headers are cached and re-applied for Posts Feed
Browse files Browse the repository at this point in the history
  • Loading branch information
toastercup committed Jul 7, 2017
1 parent 2f5c299 commit 59996c3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/api/v1/resources/posts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ class Posts < Grape::API
params_hash = Digest::MD5.hexdigest(declared(params).to_s)
cache_key = "feed-#{last_updated_at}-#{current_tenant.id}-#{params_hash}"

posts_page = ::Rails.cache.fetch(cache_key, expires_in: 30.minutes, race_condition_ttl: 10) do
posts = ::Rails.cache.fetch(cache_key, expires_in: 30.minutes, race_condition_ttl: 10) do
posts = ::GetPosts.call(params: declared(clean_params(params), include_missing: false), tenant: current_tenant, published: true).posts
::V1::Entities::Post.represent paginate(posts).records
paginated_posts = paginate(posts).records.to_a
{records: paginated_posts, headers: header}
end

posts_page
header.merge!(posts[:headers])
::V1::Entities::Post.represent posts[:records]
end

desc 'Show all published posts', { entity: ::V1::Entities::Post, nickname: "allPostFeed" }
Expand Down

0 comments on commit 59996c3

Please sign in to comment.