Skip to content

Commit 5e7405c

Browse files
committed
Add caching for event description and formatted date details in Event model; update event row view to utilize new methods
1 parent 3d6efcb commit 5e7405c

2 files changed

Lines changed: 27 additions & 19 deletions

File tree

app/models/event.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,19 @@ class Event < ActiveRecord::Base
99
def money_value
1010
Money.new(self.value, 'GBP')
1111
end
12+
13+
def description_html
14+
Rails.cache.fetch("event_description_#{id}_#{updated_at.to_i}") do
15+
Kramdown::Document.new(description).to_html.html_safe
16+
end
17+
end
18+
19+
def formatted_date_details
20+
Rails.cache.fetch("event_date_#{id}_#{start_at.to_i}_#{end_at.to_i}") do
21+
start_date = start_at.strftime('%a %d %^b %Y')
22+
start_time = start_at.strftime('%l:%M%P').strip
23+
end_time = end_at.strftime('%l:%M%P').strip
24+
"#{start_date}#{start_time}#{end_time}#{location}"
25+
end
26+
end
1227
end

app/views/events/_row.html.haml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
1-
.event{ id: "event-#{event.id}" }
1+
- cache event do
2+
.event{ id: "event-#{event.id}" }
3+
.event-title= link_to event.name, event.url
4+
- unless event.public?
5+
%small (Private event)
26

3-
.event-title= link_to event.name, event.url
4-
- unless event.public?
5-
%small (Private event)
7+
= link_to events_path(anchor: "event-#{event.id}", id: event.id) do
8+
.event-details= event.formatted_date_details
69

7-
= link_to events_path(anchor: "event-#{event.id}", id: event.id) do
8-
.event-details
9-
= event.start_at.strftime('%a') + " " + event.start_at.strftime('%d') + " " + event.start_at.strftime('%^b') + " " + event.start_at.strftime('%Y')
10-
11-
= event.start_at.strftime('%l:%M%P')
12-
\–
13-
= event.end_at.strftime('%l:%M%P')
14-
15-
= event.location
10+
.event-host= link_to event.organiser_name, event.organiser_url
1611

17-
.event-host= link_to event.organiser_name, event.organiser_url
12+
= event.description_html
1813

19-
= Kramdown::Document.new(event.description).to_html.html_safe
14+
= link_to "Register ↗", event.url, class: 'section-link'
2015

21-
= link_to "Register ↗", event.url, class: 'section-link'
22-
23-
- if can? :update, event
24-
.event-actions= link_to 'Edit', edit_admin_event_path(event)
16+
- if can? :update, event
17+
.event-actions= link_to 'Edit', edit_admin_event_path(event)

0 commit comments

Comments
 (0)