Skip to content
Snippets Groups Projects
Commit ff4471a3 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

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

parent c33d5e16
No related branches found
No related tags found
No related merge requests found
class EventDecorator < ApplicationDecorator
decorates :event
def feed_title
if self.issue?
"#{self.author_name} #{self.action_name} issue ##{self.target_id}: #{self.issue_title} at #{self.project.name}"
elsif self.merge_request?
"#{self.author_name} #{self.action_name} MR ##{self.target_id}: #{self.merge_request_title} at #{self.project.name}"
elsif self.push?
"#{self.author_name} #{self.push_action_name} #{self.ref_type} #{self.ref_name} at #{self.project.name}"
elsif self.membership_changed?
"#{self.author_name} #{self.action_name} #{self.project.name}"
else
""
end
end
def feed_url
if self.issue?
h.project_issue_url(self.project, self.issue)
elsif self.merge_request?
h.project_merge_request_url(self.project, self.merge_request)
elsif self.push?
if self.push_with_commits?
if self.commits_count > 1
h.project_compare_url(self.project, :from => self.parent_commit.id, :to => self.last_commit.id)
else
h.project_commit_url(self.project, :id => self.last_commit.id)
end
else
h.project_commits_url(self.project, self.ref_name)
end
end
end
def feed_summary
if self.issue?
h.render "events/event_issue", issue: self.issue
elsif self.push?
h.render "events/event_push", event: self
end
end
end
Loading
Loading
@@ -42,4 +42,45 @@ module EventsHelper
EventFilter.team => "icon-user",
}
end
def event_feed_title(event)
if event.issue?
"#{event.author_name} #{event.action_name} issue ##{event.target_id}: #{event.issue_title} at #{event.project.name}"
elsif event.merge_request?
"#{event.author_name} #{event.action_name} MR ##{event.target_id}: #{event.merge_request_title} at #{event.project.name}"
elsif event.push?
"#{event.author_name} #{event.push_action_name} #{event.ref_type} #{event.ref_name} at #{event.project.name}"
elsif event.membership_changed?
"#{event.author_name} #{event.action_name} #{event.project.name}"
else
""
end
end
def event_feed_url(event)
if event.issue?
project_issue_url(event.project, event.issue)
elsif event.merge_request?
project_merge_request_url(event.project, event.merge_request)
elsif event.push?
if event.push_with_commits?
if event.commits_count > 1
project_compare_url(event.project, from: event.commit_from, to: event.commit_to)
else
project_commit_url(event.project, id: event.commit_to)
end
else
project_commits_url(event.project, event.ref_name)
end
end
end
def event_feed_summary(event)
if event.issue?
render "events/event_issue", issue: event.issue
elsif event.push?
render "events/event_push", event: event
end
end
end
%div{:xmlns => "http://www.w3.org/1999/xhtml"}
%div{xmlns: "http://www.w3.org/1999/xhtml"}
- event.commits.first(15).each do |commit|
%p
%strong= commit.author_name
= link_to "(##{commit.short_id})", project_commit_path(event.project, :id => commit.id)
%strong= commit[:author][:name]
= link_to "(##{commit[:id][0...8]})", project_commit_path(event.project, id: commit[:id])
%i
at
= commit.committed_date.strftime("%Y-%m-%d %H:%M:%S")
%blockquote= simple_format(escape_once(commit.safe_message))
= commit[:timestamp].to_time.to_s(:short)
%blockquote= simple_format(escape_once(commit[:message]))
- if event.commits_count > 15
%p
%i
Loading
Loading
Loading
Loading
@@ -21,5 +21,5 @@
%li.commits-stat
- if event.commits_count > 2
%span ... and #{event.commits_count - 2} more commits.
= link_to project_compare_path(event.project, from: event.parent_commit.id, to: event.last_commit.id) do
%strong Compare &rarr; #{event.parent_commit.id[0..7]}...#{event.last_commit.id[0..7]}
= link_to project_compare_path(event.project, from: event.commit_from, to: event.commit_to) do
%strong Compare &rarr; #{event.commit_from[0..7]}...#{event.commit_to[0..7]}
Loading
Loading
@@ -8,7 +8,6 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://sear
 
@events.each do |event|
if event.proper?
event = EventDecorator.decorate(event)
xml.entry do
event_link = event.feed_url
event_title = event.feed_title
Loading
Loading
Loading
Loading
@@ -8,7 +8,6 @@ xml.feed "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:media" => "http://sear
 
@events.each do |event|
if event.proper?
event = EventDecorator.decorate(event)
xml.entry do
event_link = event.feed_url
event_title = event.feed_title
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment