Skip to content

Commit f9d223b

Browse files
authored
Merge pull request #11380 from alphagov/remove-memcached-dependency
Remove broken memcached code [WHIT-3393]
2 parents 47541a6 + 6927e55 commit f9d223b

20 files changed

Lines changed: 94 additions & 353 deletions

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ gem "carrierwave"
1212
gem "carrierwave-i18n"
1313
gem "chronic"
1414
gem "content_block_tools"
15-
gem "dalli"
1615
gem "dartsass-rails"
1716
gem "diffy"
1817
gem "flipflop"

Gemfile.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,6 @@ GEM
180180
cucumber (>= 7, < 11)
181181
railties (>= 6.1, < 9)
182182
cucumber-tag-expressions (8.1.0)
183-
dalli (5.0.2)
184-
logger
185183
dartsass-rails (0.5.1)
186184
railties (>= 6.0.0)
187185
sass-embedded (~> 1.63)
@@ -1040,7 +1038,6 @@ DEPENDENCIES
10401038
content_block_tools
10411039
cucumber
10421040
cucumber-rails
1043-
dalli
10441041
dartsass-rails
10451042
database_cleaner-active_record
10461043
diffy

app/helpers/admin/taggable_content_helper.rb

Lines changed: 9 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def taggable_topical_event_documents_container(selected_ids = [])
3131
end
3232

3333
def taggable_organisations_container(selected_ids = [])
34-
cached_taggable_organisations.map do |o|
34+
Organisation.with_translations.order("organisation_translations.name").map do |o|
3535
{
3636
text: o.select_name,
3737
value: o.id,
@@ -41,7 +41,7 @@ def taggable_organisations_container(selected_ids = [])
4141
end
4242

4343
def taggable_ministerial_role_appointments_container(selected_ids = [])
44-
cached_taggable_ministerial_role_appointments.map do |appointment|
44+
role_appointments_container_for(RoleAppointment.for_ministerial_roles).map do |appointment|
4545
{
4646
text: role_appointment_option_label(appointment),
4747
value: appointment.id,
@@ -51,7 +51,7 @@ def taggable_ministerial_role_appointments_container(selected_ids = [])
5151
end
5252

5353
def taggable_role_appointments_container(selected_ids = [])
54-
cached_taggable_role_appointments.map do |appointment|
54+
role_appointments_container_for(RoleAppointment).map do |appointment|
5555
{
5656
text: role_appointment_option_label(appointment),
5757
value: appointment.id,
@@ -61,7 +61,7 @@ def taggable_role_appointments_container(selected_ids = [])
6161
end
6262

6363
def taggable_detailed_guides_container(selected_ids = [])
64-
cached_taggable_detailed_guides.map do |d|
64+
DetailedGuide.alphabetical.latest_edition.active.map do |d|
6565
{
6666
text: d.title,
6767
value: d.id,
@@ -71,7 +71,7 @@ def taggable_detailed_guides_container(selected_ids = [])
7171
end
7272

7373
def taggable_statistical_data_sets_container(selected_ids = [])
74-
cached_taggable_statistical_data_sets.map do |data_set|
74+
StatisticalDataSet.with_translations.latest_edition.map do |data_set|
7575
{
7676
text: data_set.title,
7777
value: data_set.document_id,
@@ -81,7 +81,7 @@ def taggable_statistical_data_sets_container(selected_ids = [])
8181
end
8282

8383
def taggable_world_locations_container(selected_ids = [])
84-
cached_taggable_world_locations.map do |w|
84+
WorldLocation.ordered_by_name.where(active: true).map do |w|
8585
{
8686
text: w.name,
8787
value: w.id,
@@ -91,7 +91,7 @@ def taggable_world_locations_container(selected_ids = [])
9191
end
9292

9393
def taggable_roles_container(selected_ids = [])
94-
cached_taggable_roles.map do |w|
94+
Role.order(:name).map do |w|
9595
{
9696
text: w.name,
9797
value: w.id,
@@ -101,7 +101,7 @@ def taggable_roles_container(selected_ids = [])
101101
end
102102

103103
def taggable_alternative_format_providers_container(selected_ids = [])
104-
cached_taggable_alternative_format_providers.map do |o|
104+
Organisation.alphabetical.map do |o|
105105
{
106106
text: "#{o.name} (#{o.alternative_format_contact_email.presence || '-'})",
107107
value: o.id,
@@ -111,7 +111,7 @@ def taggable_alternative_format_providers_container(selected_ids = [])
111111
end
112112

113113
def taggable_worldwide_organisations_container(selected_ids = [])
114-
cached_taggable_worldwide_organisations.map do |wo|
114+
WorldwideOrganisation.with_translations.latest_edition.map do |wo|
115115
{
116116
text: wo.title,
117117
value: wo.document.id,
@@ -120,139 +120,8 @@ def taggable_worldwide_organisations_container(selected_ids = [])
120120
end
121121
end
122122

123-
def cached_taggable_organisations
124-
Rails.cache.fetch(taggable_organisations_cache_digest, expires_in: 1.day) do
125-
Organisation.with_translations.order("organisation_translations.name")
126-
end
127-
end
128-
129-
# Returns an MD5 digest representing the current set of taggable topical
130-
# events. This will change if any of the Topics should change or if a new
131-
# topic event is added.
132-
def taggable_topical_events_cache_digest
133-
# legacy
134-
@taggable_topical_events_cache_digest ||= calculate_digest(TopicalEvent.order(:id), "topical-events")
135-
end
136-
137-
# Returns an MD5 digest representing the current set of taggable
138-
# organisations. This will change if any of the Topics should change or if a
139-
# new organisation is added.
140-
def taggable_organisations_cache_digest
141-
@taggable_organisations_cache_digest ||= calculate_digest(Organisation.order(:id), "organisations")
142-
end
143-
144-
def cached_taggable_ministerial_role_appointments
145-
Rails.cache.fetch(taggable_ministerial_role_appointments_cache_digest, expires_in: 1.day) do
146-
role_appointments_container_for(RoleAppointment.for_ministerial_roles)
147-
end
148-
end
149-
150-
# Returns an MD5 digest representing the current set of taggable ministerial
151-
# role appointments. This will change if any role appointments are added or
152-
# changed, and also if an occupied MinisterialRole is updated.
153-
def taggable_ministerial_role_appointments_cache_digest
154-
@taggable_ministerial_role_appointments_cache_digest ||= calculate_digest(
155-
RoleAppointment
156-
.joins(:role)
157-
.where(roles: { type: "MinisterialRole" })
158-
.order("role_appointments.started_at"),
159-
"ministerial-role-appointments",
160-
)
161-
end
162-
163-
def cached_taggable_role_appointments
164-
Rails.cache.fetch(taggable_role_appointments_cache_digest, expires_in: 1.day) do
165-
role_appointments_container_for(RoleAppointment)
166-
end
167-
end
168-
169-
# Returns an MD5 digest representing the current set of taggable ministerial
170-
# role appointments. This will change if any role appointments are added or
171-
# changed, and also if an occupied Role is updated.
172-
def taggable_role_appointments_cache_digest
173-
@taggable_role_appointments_cache_digest ||= calculate_digest(RoleAppointment.order(:id), "role-appointments")
174-
end
175-
176-
def cached_taggable_detailed_guides
177-
Rails.cache.fetch(taggable_detailed_guides_cache_digest, expires_in: 1.day) do
178-
DetailedGuide.alphabetical.latest_edition.active
179-
end
180-
end
181-
182-
# Returns an MD5 digest representing all the detailed guides. This wil change
183-
# if any detailed guides are added or updated.
184-
def taggable_detailed_guides_cache_digest
185-
@taggable_detailed_guides_cache_digest ||= calculate_digest(Document.where(document_type: "DetailedGuide").order(:id), "detailed-guides")
186-
end
187-
188-
def cached_taggable_statistical_data_sets
189-
Rails.cache.fetch(taggable_statistical_data_sets_cache_digest, expires_in: 1.day) do
190-
StatisticalDataSet.with_translations.latest_edition
191-
end
192-
end
193-
194-
# Returns an MD5 digest representing the taggable statistical data sets. This
195-
# will change if any statistical data set is added or updated.
196-
def taggable_statistical_data_sets_cache_digest
197-
@taggable_statistical_data_sets_cache_digest ||= calculate_digest(Document.where(document_type: "StatisticalDataSet").order(:id), "statistical-data-sets")
198-
end
199-
200-
def cached_taggable_world_locations
201-
Rails.cache.fetch(taggable_world_locations_cache_digest, expires_in: 1.day) do
202-
WorldLocation.ordered_by_name.where(active: true)
203-
end
204-
end
205-
206-
# Returns an MD5 digest representing the taggable world locations. This will
207-
# change if any world locations are added or updated.
208-
def taggable_world_locations_cache_digest
209-
@taggable_world_locations_cache_digest ||= calculate_digest(WorldLocation.order(:id), "world-locations")
210-
end
211-
212-
def cached_taggable_roles
213-
Rails.cache.fetch(taggable_roles_cache_digest, expires_in: 1.day) do
214-
Role.order(:name)
215-
end
216-
end
217-
218-
# Returns an MD5 digest representing the taggable roles. This will
219-
# change if any world locations are added or updated.
220-
def taggable_roles_cache_digest
221-
@taggable_roles_cache_digest ||= calculate_digest(Role.order(:id), "roles")
222-
end
223-
224-
def cached_taggable_alternative_format_providers
225-
Rails.cache.fetch(taggable_alternative_format_providers_cache_digest, expires_in: 1.day) do
226-
Organisation.alphabetical
227-
end
228-
end
229-
230-
# Returns an MD5 digest representing the taggable alternative format
231-
# providers. This will change if any alternative format providers are
232-
# changed.
233-
def taggable_alternative_format_providers_cache_digest
234-
@taggable_alternative_format_providers_cache_digest ||= calculate_digest(Organisation.order(:id), "alternative-format-providers")
235-
end
236-
237-
def cached_taggable_worldwide_organisations
238-
Rails.cache.fetch(taggable_worldwide_organisations_cache_digest, expires_in: 1.day) do
239-
WorldwideOrganisation.with_translations.latest_edition
240-
end
241-
end
242-
243-
# Returns an MD5 digest representing the taggable worldwide organisations. This
244-
# will change if any worldwide organisation is added or updated.
245-
def taggable_worldwide_organisations_cache_digest
246-
@taggable_worldwide_organisations_cache_digest ||= calculate_digest(Document.where(document_type: "WorldwideOrganisation").order(:id), "worldwide-organisations")
247-
end
248-
249123
private
250124

251-
def calculate_digest(scope, digest_name)
252-
update_timestamps = scope.pluck(:updated_at).map(&:to_i).join
253-
Digest::MD5.hexdigest "taggable-#{digest_name}-#{update_timestamps}"
254-
end
255-
256125
def role_appointments_container_for(scope)
257126
scope
258127
.includes(:person)

app/models/person.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Person < ApplicationRecord
3636
translates :biography
3737

3838
before_destroy :prevent_destruction_if_appointed
39-
after_update :touch_role_appointments, :republish_past_prime_ministers_page_to_publishing_api
39+
after_update :republish_past_prime_ministers_page_to_publishing_api
4040
after_update :patch_links_ministers_index_page_to_publishing_api, :republish_how_government_works_page_to_publishing_api, if: :has_ministerial_appointments?
4141

4242
def biography_without_markup
@@ -142,13 +142,6 @@ def prevent_destruction_if_appointed
142142
throw :abort unless destroyable?
143143
end
144144

145-
# Whenever a person is updated, we want touch the updated_at timestamps of
146-
# any associated role appointments so that the cache digest for the
147-
# taggable_ministerial_role_appointments_container gets invalidated.
148-
def touch_role_appointments
149-
role_appointments.update_all updated_at: Time.zone.now
150-
end
151-
152145
def truncated_biography
153146
biography&.split(/\n/)&.first
154147
end

app/models/role.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def self.columns
5757
validates_with SafeHtmlValidator
5858

5959
before_destroy :prevent_destruction_unless_destroyable
60-
after_update :touch_role_appointments
6160
after_save :republish_associated_editions_to_publishing_api, :republish_organisations_to_publishing_api
6261

6362
accepts_nested_attributes_for :edition_roles
@@ -200,11 +199,4 @@ def prevent_destruction_unless_destroyable
200199
def default_person_name
201200
"No one is assigned to this role"
202201
end
203-
204-
# Whenever a ministerial role is updated, we want touch the updated_at
205-
# timestamps of any associated role appointments so that the cache digest for
206-
# the taggable_ministerial_role_appointments_container gets invalidated.
207-
def touch_role_appointments
208-
role_appointments.update_all updated_at: Time.zone.now
209-
end
210202
end

app/views/admin/detailed_guides/_form.html.erb

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@
1414
<%= render "organisation_fields", form: form, edition: edition %>
1515
<%= render "topical_event_fields", form: form, edition: edition %>
1616

17-
<% cache_if edition.related_detailed_guide_ids.empty?, "#{taggable_detailed_guides_cache_digest}-design-system" do %>
18-
<%= render "govuk_publishing_components/components/select_with_search", {
19-
id: "edition_related_detailed_guide_ids",
20-
name: "edition[related_detailed_guide_ids][]",
21-
error_items: errors_for(edition.errors, :related_detailed_guide_ids),
22-
include_blank: true,
23-
label: "Related guides",
24-
heading_size: "m",
25-
options: taggable_detailed_guides_container(edition.related_detailed_guide_ids),
26-
multiple: true,
27-
} %>
28-
<% end %>
17+
<%= render "govuk_publishing_components/components/select_with_search", {
18+
id: "edition_related_detailed_guide_ids",
19+
name: "edition[related_detailed_guide_ids][]",
20+
error_items: errors_for(edition.errors, :related_detailed_guide_ids),
21+
include_blank: true,
22+
label: "Related guides",
23+
heading_size: "m",
24+
options: taggable_detailed_guides_container(edition.related_detailed_guide_ids),
25+
multiple: true,
26+
} %>
2927

3028
<%= render "nation_fields", form: form, edition: edition %>
3129
</div>
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
<% cache_if edition.role_appointment_ids.empty?, "#{taggable_ministerial_role_appointments_cache_digest}-design-system" do %>
2-
<%= render "govuk_publishing_components/components/select_with_search", {
3-
id: "edition_role_appointment_ids",
4-
name: "edition[role_appointment_ids][]",
5-
include_blank: true,
6-
label: "Ministers",
7-
heading_size: "m",
8-
options: taggable_ministerial_role_appointments_container(edition.role_appointment_ids),
9-
multiple: true,
10-
} %>
11-
<% end %>
1+
<%= render "govuk_publishing_components/components/select_with_search", {
2+
id: "edition_role_appointment_ids",
3+
name: "edition[role_appointment_ids][]",
4+
include_blank: true,
5+
label: "Ministers",
6+
heading_size: "m",
7+
options: taggable_ministerial_role_appointments_container(edition.role_appointment_ids),
8+
multiple: true,
9+
} %>

app/views/admin/editions/_organisation_fields.html.erb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@
99
<div class="govuk-!-margin-bottom-6">
1010
<% 0.upto(3) do |index| %>
1111
<% lead_organisation_id = lead_organisation_id_at_index(edition, index) %>
12-
<% cache_if lead_organisation_id.nil?, "#{taggable_organisations_cache_digest}-lead" do %>
13-
<%= render "govuk_publishing_components/components/select_with_search", {
14-
id: "edition_lead_organisation_ids_#{index + 1}",
15-
name: "edition[lead_organisation_ids][]",
16-
label: "Lead organisation #{index + 1}",
17-
heading_size: "s",
18-
include_blank: true,
19-
options: taggable_organisations_container([lead_organisation_id]),
20-
} %>
21-
<% end %>
12+
<%= render "govuk_publishing_components/components/select_with_search", {
13+
id: "edition_lead_organisation_ids_#{index + 1}",
14+
name: "edition[lead_organisation_ids][]",
15+
label: "Lead organisation #{index + 1}",
16+
heading_size: "s",
17+
include_blank: true,
18+
options: taggable_organisations_container([lead_organisation_id]),
19+
} %>
2220
<% end %>
2321
</div>
2422
<% end %>
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
<% required = false unless defined?(required) %>
22
<% index = "1" unless defined?(index) %>
33

4-
<% cache_if edition.role_ids.empty?, "#{taggable_roles_cache_digest}-design-system" do %>
5-
<%= render "govuk_publishing_components/components/select_with_search", {
6-
id: "edition_roles",
7-
name: "edition[role_ids][]",
8-
error_items: errors_for(edition.errors, :roles),
9-
label: "Roles" + "#{' (required)' if required}",
10-
heading_size: "m",
11-
options: taggable_roles_container(edition.role_ids),
12-
multiple: true,
13-
} %>
14-
<% end %>
4+
<%= render "govuk_publishing_components/components/select_with_search", {
5+
id: "edition_roles",
6+
name: "edition[role_ids][]",
7+
error_items: errors_for(edition.errors, :roles),
8+
label: "Roles" + "#{' (required)' if required}",
9+
heading_size: "m",
10+
options: taggable_roles_container(edition.role_ids),
11+
multiple: true,
12+
} %>

0 commit comments

Comments
 (0)