From ff4471a3cd1d29228a67e582bc54bed952c0a8ee Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 5 Apr 2013 19:47:12 +0300 Subject: [PATCH] Get rid of event decorator. Use event data hash instead commit objects to increase perfomance --- app/decorators/event_decorator.rb | 44 -------------------------------------------- app/helpers/events_helper.rb | 41 +++++++++++++++++++++++++++++++++++++++++ app/views/events/_event_push.atom.haml | 10 +++++----- app/views/events/event/_push.html.haml | 4 ++-- app/views/groups/show.atom.builder | 1 - app/views/teams/show.atom.builder | 1 - 6 files changed, 48 insertions(+), 53 deletions(-) delete mode 100644 app/decorators/event_decorator.rb diff --git a/app/decorators/event_decorator.rb b/app/decorators/event_decorator.rb deleted file mode 100644 index 1b0ad0d..0000000 --- a/app/decorators/event_decorator.rb +++ /dev/null @@ -1,44 +0,0 @@ -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 diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 38374e3..7155036 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -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 diff --git a/app/views/events/_event_push.atom.haml b/app/views/events/_event_push.atom.haml index d09e6e0..e44b366 100644 --- a/app/views/events/_event_push.atom.haml +++ b/app/views/events/_event_push.atom.haml @@ -1,12 +1,12 @@ -%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 diff --git a/app/views/events/event/_push.html.haml b/app/views/events/event/_push.html.haml index 119b8e8..f2b8dc4 100644 --- a/app/views/events/event/_push.html.haml +++ b/app/views/events/event/_push.html.haml @@ -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 → #{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 → #{event.commit_from[0..7]}...#{event.commit_to[0..7]} diff --git a/app/views/groups/show.atom.builder b/app/views/groups/show.atom.builder index 5f2999c..807ff5f 100644 --- a/app/views/groups/show.atom.builder +++ b/app/views/groups/show.atom.builder @@ -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 diff --git a/app/views/teams/show.atom.builder b/app/views/teams/show.atom.builder index bb0f666..1468ac1 100644 --- a/app/views/teams/show.atom.builder +++ b/app/views/teams/show.atom.builder @@ -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 -- libgit2 0.21.2