From 59996c32b8a9239ed88b27007ee9acd5b0ead135 Mon Sep 17 00:00:00 2001 From: Alex Tharp Date: Fri, 7 Jul 2017 14:19:56 -0500 Subject: [PATCH] fix(API): ensure headers are cached and re-applied for Posts Feed --- app/api/v1/resources/posts.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/api/v1/resources/posts.rb b/app/api/v1/resources/posts.rb index f661f9220..c2f9ef86a 100644 --- a/app/api/v1/resources/posts.rb +++ b/app/api/v1/resources/posts.rb @@ -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" }