Skip to content

Commit 59996c3

Browse files
committed
fix(API): ensure headers are cached and re-applied for Posts Feed
1 parent 2f5c299 commit 59996c3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

app/api/v1/resources/posts.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ class Posts < Grape::API
3636
params_hash = Digest::MD5.hexdigest(declared(params).to_s)
3737
cache_key = "feed-#{last_updated_at}-#{current_tenant.id}-#{params_hash}"
3838

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

44-
posts_page
45+
header.merge!(posts[:headers])
46+
::V1::Entities::Post.represent posts[:records]
4547
end
4648

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

0 commit comments

Comments
 (0)