From 02e8ffca36cf933c3b699c4b2ea72c0d3b28c0c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Tue, 31 Jan 2023 19:20:36 +0100 Subject: [PATCH] Don't cache related actions in investments view We've experienced some caching issues with this code for years. We've fixed some of them in commits 9979b5399 and 3645c333a, but we're still running into other issues. In order to really cache this section, we'd need to cache: * Whether or not the investment should show the aside and vote/support buttons (we could do it by caching its budget) * Whether its budget is balloting or finished (we could do it by caching its budget) * Whether the current user is following the investment * Whether the `remove_investments_supports` feature is enabled * Whether the `community` feature is enabled * The value of the `org_name` setting * The value of the `twitter_handle` setting We weren't caching all these elements, meaning that (for instance), we didn't display the button to vote when a budget moved into the voting phase if we had already cached this section without the button. And chances are the list is incomplete. So, instead of trying to take into account every single possible factor that should make us expire the cache, we're restricting the cache so it only affects the content of the investment. This is similar to what we do in the investments index, where we cache the content of the investment but we don't cache the vote/support buttons. --- .../investments/_investment_show.html.erb | 198 +++++++++--------- 1 file changed, 97 insertions(+), 101 deletions(-) diff --git a/app/views/budgets/investments/_investment_show.html.erb b/app/views/budgets/investments/_investment_show.html.erb index d7a46cf51..aec6ec3b5 100644 --- a/app/views/budgets/investments/_investment_show.html.erb +++ b/app/views/budgets/investments/_investment_show.html.erb @@ -7,122 +7,118 @@ og_image_url: (investment.image.present? ? polymorphic_path(investment.image.variant(:thumb)) : nil) %> <% end %> -<% cache [locale_and_user_status(investment), - investment, - investment.author, - Flag.flagged?(current_user, investment), - investment.followed_by?(current_user), - feature?(:remove_investments_supports), - current_user&.voted_for?(investment)] do %> -
- -
+
+
+ <% cache [locale_and_user_status(investment), + investment, + investment.author, + Flag.flagged?(current_user, investment)] do %>
<%= back_link_to budget_investments_path(investment.budget, heading_id: investment.heading) %> <%= render "/budgets/investments/investment_detail", investment: investment %>
+ <% end %> -
-
-<% end %> + <% if current_user %> + + + + <%= render "follows/follow_button", follow: find_or_build_follow(current_user, investment) %> + <% end %> + + <%= render "communities/access_button", community: investment.community %> + + +
+