* feat: add a route to the async_info for display ads * feat: load the billboard asyncronously * feat: move the methods to the display_ads controller * feat: handle params better * feat: cache control headers * feat: test fastly caching headers on display ads * fix: surrogate key test * feat: use safe navigation operator to handle cases where there is no article id * fix: article id present then find the article * feat: add a response test * Fragment caching * feat: update the article decorator * feat: update cache keys for fragment * feat: remove an empty line * feat: add article id * feat: bust cache * feat: setup dropdown for billboard * chore: add chunk to same line * feat: add to safe params for caching * Update app/controllers/display_ads_controller.rb Co-authored-by: Joshua Wehner <joshua@forem.com> * feat: remove the cache deletion * feat: update the routes to follow a new scope * feat: update the cache params --------- Co-authored-by: Joshua Wehner <joshua@forem.com>
30 lines
1 KiB
Ruby
30 lines
1 KiB
Ruby
class DisplayAdsController < ApplicationController
|
|
before_action :set_cache_control_headers, only: %i[for_display], unless: -> { current_user }
|
|
CACHE_EXPIRY_FOR_DISPLAY_ADS = 15.minutes.to_i.freeze
|
|
|
|
def show
|
|
skip_authorization
|
|
set_cache_control_headers(CACHE_EXPIRY_FOR_DISPLAY_ADS) unless session_current_user_id
|
|
|
|
if params[:placement_area]
|
|
if params[:username].present? && params[:slug].present?
|
|
@article = Article.find_by(slug: params[:slug])
|
|
end
|
|
|
|
@display_ad = DisplayAd.for_display(
|
|
area: params[:placement_area],
|
|
user_signed_in: user_signed_in?,
|
|
organization_id: @article&.organization_id,
|
|
permit_adjacent_sponsors: ArticleDecorator.new(@article).permit_adjacent_sponsors?,
|
|
article_tags: @article&.decorate&.cached_tag_list_array || [],
|
|
article_id: @article&.id,
|
|
)
|
|
|
|
if @display_ad && !session_current_user_id
|
|
set_surrogate_key_header @display_ad.record_key
|
|
end
|
|
end
|
|
|
|
render layout: false
|
|
end
|
|
end
|