forked from ATIX-AG/foreman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #19035 - rewrite TopbarSweeper without rails-observers
Moves from the observer object into two mixins, one on the model and one on the top-level controllers to observe creates/updates/destroys on monitored models. Replaces rails-observers as it lacks Rails 5 support.
- Loading branch information
Showing
17 changed files
with
102 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
app/controllers/concerns/foreman/controller/topbar_sweeper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Foreman | ||
module Controller | ||
module TopbarSweeper | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
around_action :set_topbar_sweeper_controller | ||
end | ||
|
||
def set_topbar_sweeper_controller | ||
::TopbarSweeper.instance.controller = self | ||
yield | ||
ensure | ||
::TopbarSweeper.instance.controller = nil | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module TopbarCacheExpiry | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
after_create :expire_topbar_cache_within_controller | ||
after_update :expire_topbar_cache_within_controller | ||
after_destroy :expire_topbar_cache_within_controller | ||
end | ||
|
||
def expire_topbar_cache_within_controller | ||
expire_topbar_cache if TopbarSweeper.instance.controller.present? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class TopbarSweeper | ||
include Singleton | ||
attr_accessor :controller | ||
|
||
def expire_cache(user = User.current) | ||
controller.expire_fragment(self.class.fragment_name(user.id)) if controller.present? && user.present? | ||
end | ||
|
||
class << self | ||
delegate :expire_cache, to: :instance | ||
|
||
def fragment_name(id = User.current.id) | ||
"tabs_and_title_records-#{id}" | ||
end | ||
|
||
def expire_cache_all_users | ||
User.unscoped.pluck(:id).each do |id| | ||
Rails.cache.delete("views/#{fragment_name(id)}") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters