-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an organization memoizer for helpers
- Loading branch information
Ivan Vergés
authored and
Ivan Vergés
committed
Dec 2, 2024
1 parent
2286ca1
commit 8834a3b
Showing
7 changed files
with
82 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -845,7 +845,7 @@ DEPENDENCIES | |
web-console | ||
|
||
RUBY VERSION | ||
ruby 3.0.6p216 | ||
ruby 3.0.7p220 | ||
|
||
BUNDLED WITH | ||
2.4.22 |
23 changes: 23 additions & 0 deletions
23
app/cells/concerns/decidim/decidim_awesome/proposal_l_cell_override.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,23 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module DecidimAwesome | ||
module ProposalLCellOverride | ||
extend ActiveSupport::Concern | ||
|
||
included do | ||
private | ||
|
||
alias_method :decidim_original_cache_hash, :cache_hash | ||
|
||
def metadata_cell | ||
@metadata_cell ||= awesome_voting_manifest_for(resource&.component)&.proposal_metadata_cell.presence || "decidim/proposals/proposal_metadata" | ||
end | ||
|
||
def cache_hash | ||
@cache_hash ||= "#{decidim_original_cache_hash}#{Decidim.cache_key_separator}#{model.extra_fields&.vote_weight_totals}" | ||
end | ||
end | ||
end | ||
end | ||
end |
2 changes: 0 additions & 2 deletions
2
app/controllers/concerns/decidim/decidim_awesome/needs_awesome_config.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
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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
# add a global helper with awesome configuration | ||
module DecidimAwesome | ||
module OrganizationMemoizer | ||
def self.memoize(key) | ||
@memoized ||= {} | ||
@memoized[key] ||= yield | ||
end | ||
|
||
# memoize a piece of code in the class instead of the instance (helper are initialized for each view) | ||
# only works if request.env["decidim.current_organization"] is defined | ||
def memoize(key, &block) | ||
return yield unless request.env["decidim.current_organization"]&.id | ||
|
||
OrganizationMemoizer.memoize("#{request.env["decidim.current_organization"].id}-#{key}", &block) | ||
end | ||
end | ||
end | ||
end |