Class: Renalware::Events::SummaryPart
- Inherits:
-
SummaryPart
- Object
- SummaryPart
- Renalware::Events::SummaryPart
- Defined in:
- app/presenters/renalware/events/summary_part.rb
Constant Summary
Constants inherited from SummaryPart
Instance Method Summary collapse
-
#cache_key ⇒ Object
AR::Relation#cache_key here will issue: SELECT COUNT(*) AS “size”, MAX(“events”.“updated_at”) AS timestamp FROM “events” WHERE “events”.“patient_id” = 1 and use size and timestamp in the cache key.
- #recent_events ⇒ Object
- #recent_events_count ⇒ Object
- #to_partial_path ⇒ Object
Methods inherited from SummaryPart
Instance Method Details
#cache_key ⇒ Object
AR::Relation#cache_key here will issue:
SELECT COUNT(*) AS "size", MAX("events"."updated_at") AS timestamp
FROM "events" WHERE "events"."patient_id" = 1
and use size and timestamp in the cache key. We purposefully don’t use the recent_events relation here as it has includes and a limit and apart from being slower, using LIMIT in cache_key sql has been known to produce inconsistent results. We need to include the patient.cache_key otherwise if there are no events, the key will be the same for other patients with no events.
33 34 35 |
# File 'app/presenters/renalware/events/summary_part.rb', line 33 def cache_key [patient.cache_key, Events::Event.for_patient(patient).cache_key].join("~") end |
#recent_events ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'app/presenters/renalware/events/summary_part.rb', line 8 def recent_events @recent_events ||= begin Events::Event.includes([:created_by, :event_type]) .for_patient(patient) .limit(Renalware.config.clinical_summary_max_events_to_display) .ordered end end |
#recent_events_count ⇒ Object
17 18 19 20 21 22 |
# File 'app/presenters/renalware/events/summary_part.rb', line 17 def recent_events_count title_friendly_collection_count( actual: recent_events.size, total: patient.summary.events_count ) end |
#to_partial_path ⇒ Object
37 38 39 |
# File 'app/presenters/renalware/events/summary_part.rb', line 37 def to_partial_path "renalware/events/events/summary_part" end |