@@ -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-
249123private
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 )
0 commit comments