Skip to content

Commit

Permalink
fixup! Add ability to ask external caches to invalidate.
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Sep 14, 2023
1 parent b9a34af commit 96a231c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
7 changes: 0 additions & 7 deletions app/models/info_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1164,13 +1164,6 @@ def log_event(type, params, options = {})
if !last_event_time || (event.created_at > last_event_time)
update_column(:last_event_time, event.created_at)
end
if %w[comment edit_comment hide_comment].include? type
NotifyCacheJob.perform_later(Comment.find(params[:comment_id]))
elsif type == 'edit_attachment'
NotifyCacheJob.perform_later(FoiAttachment.find(params[:attachment_id]))
else
NotifyCacheJob.perform_later(self)
end
event
end

Expand Down
16 changes: 16 additions & 0 deletions app/models/info_request_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class InfoRequestEvent < ApplicationRecord
self.event_type = "hide"
end
after_create :update_request, if: :response?
after_create :invalidate_cached_pages

after_commit -> { info_request.create_or_update_request_summary },
on: [:create]
Expand Down Expand Up @@ -355,6 +356,16 @@ def update_request
info_request.update_last_public_response_at
end

def invalidate_cached_pages
if comment
NotifyCacheJob.perform_later(comment)
elsif foi_attachment
NotifyCacheJob.perform_later(foi_attachment)
else
NotifyCacheJob.perform_later(info_request)
end
end

def same_email_as_previous_send?
prev_addr = info_request.get_previous_email_sent_to(self)
curr_addr = params[:email]
Expand Down Expand Up @@ -593,4 +604,9 @@ def filetype
def request_public_body_tags
info_request.public_body.tag_array_for_search
end

def foi_attachment
return unless params[:attachment_id]
@foi_attachment ||= FoiAttachment.find(params[:attachment_id])
end
end

0 comments on commit 96a231c

Please sign in to comment.