Skip to content

Commit

Permalink
fix cache proposal_m
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Oct 30, 2023
1 parent fa619d6 commit aaf33f9
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# frozen_string_literal: true

module Decidim
module DecidimAwesome
module ProposalMCellOverride
extend ActiveSupport::Concern

included do
# rubocop:disable Metrics/CyclomaticComplexity
def cache_hash
hash = []
hash << I18n.locale.to_s
hash << model.cache_key_with_version
hash << model.proposal_votes_count
hash << model.weight_cache&.totals
hash << model.endorsements_count
hash << model.comments_count
hash << Digest::MD5.hexdigest(model.component.cache_key_with_version)
hash << Digest::MD5.hexdigest(resource_image_path) if resource_image_path
hash << render_space? ? 1 : 0
if current_user
hash << current_user.cache_key_with_version
hash << current_user.follows?(model) ? 1 : 0
end
hash << model.follows_count
hash << Digest::MD5.hexdigest(model.authors.map(&:cache_key_with_version).to_s)
hash << (model.must_render_translation?(model.organization) ? 1 : 0) if model.respond_to?(:must_render_translation?)
hash << model.component.participatory_space.active_step.id if model.component.participatory_space.try(:active_step)
hash << has_footer?
hash << has_actions?

hash.join(Decidim.cache_key_separator)
end
# rubocop:enable Metrics/CyclomaticComplexity
end
end
end
end
5 changes: 4 additions & 1 deletion lib/decidim/decidim_awesome/checksums.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ decidim-proposals:
decidim-0.27: f7202c37fe042cd816a6f9fd0f9e6807
/app/views/decidim/proposals/proposals/_votes_count.html.erb:
decidim-0.27: 33339aae5004361e24c4c5b009cc2888
/app/cells/decidim/proposals/proposal_m_cell.rb:
decidim-0.26: 21cc09a45efa20dbcda5c943d820c867
decidim-0.27: ce3b30cdddfee547b8fb089c0fddd8a4
/app/cells/decidim/proposals/proposal_m/footer.erb:
decidim-0.27: 7ade5bbd8412f44f1c4ed913ae1834c6
decidim-0.26: 7ade5bbd8412f44f1c4ed913ae1834c6
1 change: 1 addition & 0 deletions lib/decidim/decidim_awesome/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Engine < ::Rails::Engine
Decidim::Proposals::Proposal.include(Decidim::DecidimAwesome::HasWeightCache)
Decidim::Proposals::ProposalSerializer.include(Decidim::DecidimAwesome::ProposalSerializerOverride)
Decidim::Proposals::ProposalType.include(Decidim::DecidimAwesome::ProposalTypeOverride)
Decidim::Proposals::ProposalMCell.include(Decidim::DecidimAwesome::ProposalMCellOverride)
end

Decidim::MenuPresenter.include(Decidim::DecidimAwesome::MenuPresenterOverride)
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/system_checker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ module Decidim::DecidimAwesome
expect(subject.overrides["decidim-core"].files.length).to eq(6)
end

it "has 11 modified files in proposals" do
expect(subject.overrides["decidim-proposals"].files.length).to eq(11)
it "has 12 modified files in proposals" do
expect(subject.overrides["decidim-proposals"].files.length).to eq(12)
end

context "when file" do
Expand Down
8 changes: 7 additions & 1 deletion spec/system/three_flags_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,19 @@
]
end

it "shows the vote count" do
it "shows the vote count", :caching do
within "#proposal_#{proposal.id}" do
expect(page).to have_content("G: 1")
expect(page).to have_content("Y: 2")
expect(page).to have_content("R: 3")
expect(page).to have_content("A: 4")
expect(page).to have_link("Click to vote")
# check the cached card by maintaining the number of votes and change the weight
Decidim::DecidimAwesome::VoteWeight.find_by(weight: 3).update(weight: 1)
visit_component
expect(page).to have_content("G: 0")
expect(page).to have_content("Y: 2")
expect(page).to have_content("R: 4")
end
end

Expand Down

0 comments on commit aaf33f9

Please sign in to comment.