Commit ff4471a3cd1d29228a67e582bc54bed952c0a8ee

Authored by Dmitriy Zaporozhets
1 parent c33d5e16

Get rid of event decorator. Use event data hash instead commit objects to increase perfomance

app/decorators/event_decorator.rb
... ... @@ -1,44 +0,0 @@
1   -class EventDecorator < ApplicationDecorator
2   - decorates :event
3   -
4   - def feed_title
5   - if self.issue?
6   - "#{self.author_name} #{self.action_name} issue ##{self.target_id}: #{self.issue_title} at #{self.project.name}"
7   - elsif self.merge_request?
8   - "#{self.author_name} #{self.action_name} MR ##{self.target_id}: #{self.merge_request_title} at #{self.project.name}"
9   - elsif self.push?
10   - "#{self.author_name} #{self.push_action_name} #{self.ref_type} #{self.ref_name} at #{self.project.name}"
11   - elsif self.membership_changed?
12   - "#{self.author_name} #{self.action_name} #{self.project.name}"
13   - else
14   - ""
15   - end
16   - end
17   -
18   - def feed_url
19   - if self.issue?
20   - h.project_issue_url(self.project, self.issue)
21   - elsif self.merge_request?
22   - h.project_merge_request_url(self.project, self.merge_request)
23   -
24   - elsif self.push?
25   - if self.push_with_commits?
26   - if self.commits_count > 1
27   - h.project_compare_url(self.project, :from => self.parent_commit.id, :to => self.last_commit.id)
28   - else
29   - h.project_commit_url(self.project, :id => self.last_commit.id)
30   - end
31   - else
32   - h.project_commits_url(self.project, self.ref_name)
33   - end
34   - end
35   - end
36   -
37   - def feed_summary
38   - if self.issue?
39   - h.render "events/event_issue", issue: self.issue
40   - elsif self.push?
41   - h.render "events/event_push", event: self
42   - end
43   - end
44   -end
app/helpers/events_helper.rb
... ... @@ -42,4 +42,45 @@ module EventsHelper
42 42 EventFilter.team => "icon-user",
43 43 }
44 44 end
  45 +
  46 + def event_feed_title(event)
  47 + if event.issue?
  48 + "#{event.author_name} #{event.action_name} issue ##{event.target_id}: #{event.issue_title} at #{event.project.name}"
  49 + elsif event.merge_request?
  50 + "#{event.author_name} #{event.action_name} MR ##{event.target_id}: #{event.merge_request_title} at #{event.project.name}"
  51 + elsif event.push?
  52 + "#{event.author_name} #{event.push_action_name} #{event.ref_type} #{event.ref_name} at #{event.project.name}"
  53 + elsif event.membership_changed?
  54 + "#{event.author_name} #{event.action_name} #{event.project.name}"
  55 + else
  56 + ""
  57 + end
  58 + end
  59 +
  60 + def event_feed_url(event)
  61 + if event.issue?
  62 + project_issue_url(event.project, event.issue)
  63 + elsif event.merge_request?
  64 + project_merge_request_url(event.project, event.merge_request)
  65 +
  66 + elsif event.push?
  67 + if event.push_with_commits?
  68 + if event.commits_count > 1
  69 + project_compare_url(event.project, from: event.commit_from, to: event.commit_to)
  70 + else
  71 + project_commit_url(event.project, id: event.commit_to)
  72 + end
  73 + else
  74 + project_commits_url(event.project, event.ref_name)
  75 + end
  76 + end
  77 + end
  78 +
  79 + def event_feed_summary(event)
  80 + if event.issue?
  81 + render "events/event_issue", issue: event.issue
  82 + elsif event.push?
  83 + render "events/event_push", event: event
  84 + end
  85 + end
45 86 end
... ...
app/views/events/_event_push.atom.haml
1   -%div{:xmlns => "http://www.w3.org/1999/xhtml"}
  1 +%div{xmlns: "http://www.w3.org/1999/xhtml"}
2 2 - event.commits.first(15).each do |commit|
3 3 %p
4   - %strong= commit.author_name
5   - = link_to "(##{commit.short_id})", project_commit_path(event.project, :id => commit.id)
  4 + %strong= commit[:author][:name]
  5 + = link_to "(##{commit[:id][0...8]})", project_commit_path(event.project, id: commit[:id])
6 6 %i
7 7 at
8   - = commit.committed_date.strftime("%Y-%m-%d %H:%M:%S")
9   - %blockquote= simple_format(escape_once(commit.safe_message))
  8 + = commit[:timestamp].to_time.to_s(:short)
  9 + %blockquote= simple_format(escape_once(commit[:message]))
10 10 - if event.commits_count > 15
11 11 %p
12 12 %i
... ...
app/views/events/event/_push.html.haml
... ... @@ -21,5 +21,5 @@
21 21 %li.commits-stat
22 22 - if event.commits_count > 2
23 23 %span ... and #{event.commits_count - 2} more commits.
24   - = link_to project_compare_path(event.project, from: event.parent_commit.id, to: event.last_commit.id) do
25   - %strong Compare &rarr; #{event.parent_commit.id[0..7]}...#{event.last_commit.id[0..7]}
  24 + = link_to project_compare_path(event.project, from: event.commit_from, to: event.commit_to) do
  25 + %strong Compare &rarr; #{event.commit_from[0..7]}...#{event.commit_to[0..7]}
... ...
app/views/groups/show.atom.builder
... ... @@ -8,7 +8,6 @@ xml.feed &quot;xmlns&quot; =&gt; &quot;http://www.w3.org/2005/Atom&quot;, &quot;xmlns:media&quot; =&gt; &quot;http://sear
8 8  
9 9 @events.each do |event|
10 10 if event.proper?
11   - event = EventDecorator.decorate(event)
12 11 xml.entry do
13 12 event_link = event.feed_url
14 13 event_title = event.feed_title
... ...
app/views/teams/show.atom.builder
... ... @@ -8,7 +8,6 @@ xml.feed &quot;xmlns&quot; =&gt; &quot;http://www.w3.org/2005/Atom&quot;, &quot;xmlns:media&quot; =&gt; &quot;http://sear
8 8  
9 9 @events.each do |event|
10 10 if event.proper?
11   - event = EventDecorator.decorate(event)
12 11 xml.entry do
13 12 event_link = event.feed_url
14 13 event_title = event.feed_title
... ...