Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions arclight/app/controllers/static_finding_aid_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,24 +238,23 @@ class StaticFindingAidController < ApplicationController
end

def show
document = search_service.fetch(::RSolr.solr_escape(params[:id]))
unless document
@document = search_service.fetch(::RSolr.solr_escape(params[:id]))
unless @document
redirect_to "/findaid/#{params[:id]}"
return
end

# Check S3 cache
s3_bucket = ENV["S3_BUCKET"]
if s3_bucket.present? && !Rails.application.config.disable_static_findaid_cache
s3 = Aws::S3::Resource.new
bucket = s3.bucket(s3_bucket)

# First try oac5 path with validation
s3_content = fetch_from_s3("oac5/#{params[:id]}.html", method(:cache_is_valid?))
if !s3_content
s3_content = fetch_from_s3("static_findaids/#{params[:id]}.html")
if s3_content
@main_content = fragment
return
end

s3_content = fetch_from_s3("static_findaids/#{params[:id]}.html")
if s3_content
render html: s3_content.html_safe
return
Expand All @@ -269,18 +268,15 @@ def show
@document = @doc_tree.document

# Render to string instead of responding
html_content = render_to_string(
layout: "static_catalog_result",
@main_content = render_to_string(
partial: "static_finding_aid/show_main_content",
formats: [ :html ]
)

# Upload to S3 if bucket is configured
if s3_bucket.present?
upload_to_s3(params[:id], html_content, document)
upload_to_s3(params[:id], @main_content, @document)
end

# Serve the rendered content
render html: html_content.html_safe
end

private
Expand Down Expand Up @@ -311,7 +307,7 @@ def fetch_from_s3(path, cache_check_fn = nil)
head = obj.head

if cache_check_fn.respond_to?(:call)
if cache_check_fn.call(head.metadata, document)
if cache_check_fn.call(head.metadata, @document)
Rails.logger.info("S3 cache valid for #{path}, serving cached content")
# Fetch and render cached content from S3
obj.get.body.read
Expand Down
2 changes: 1 addition & 1 deletion arclight/app/views/static_finding_aid/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
</div>
</div>
<% end %>
<%= render 'show_main_content' %>
<%= @main_content.html_safe %>
Loading