diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-29 00:53:43 -0800 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-01-29 00:53:43 -0800 |
commit | a9288e554e55e843b95ab6f8109a4c610af64c83 (patch) | |
tree | 4076cf59b8191e318b93b4a74985053d351c7469 /lib | |
parent | 6e1f9e746cb5dc555003b5398c46113ce83fceae (diff) | |
download | gitlab-ce-a9288e554e55e843b95ab6f8109a4c610af64c83.tar.gz |
Cleanup and make contribution calendar faster
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/commits_calendar.rb | 72 |
1 files changed, 13 insertions, 59 deletions
diff --git a/lib/gitlab/commits_calendar.rb b/lib/gitlab/commits_calendar.rb index 93256187fd2..b6699c585f6 100644 --- a/lib/gitlab/commits_calendar.rb +++ b/lib/gitlab/commits_calendar.rb @@ -1,71 +1,25 @@ module Gitlab class CommitsCalendar - def self.create_timestamp(repositories, user, show_activity) - timestamps = {} - repositories.each do |raw_repository| - if raw_repository.exists? - commits_log = raw_repository.commits_log_of_user_by_date(user) + attr_reader :timestamps - populated_timestamps = - if show_activity - populate_timestamps_by_project( - commits_log, - timestamps, - raw_repository - ) - else - populate_timestamps(commits_log, timestamps) - end - timestamps.merge!(populated_timestamps) - end - end - timestamps - end + def initialize(repositories, user) + @timestamps = {} + date_timestamps = [] - def self.populate_timestamps(commits_log, timestamps) - commits_log.each do |timestamp_date, commits_count| - hash = { "#{timestamp_date}" => commits_count } - if timestamps.has_key?("#{timestamp_date}") - timestamps.merge!(hash) do |timestamp_date, commits_count, - new_commits_count| commits_count = commits_count.to_i + - new_commits_count - end - else - timestamps.merge!(hash) - end + repositories.select(&:exists?).reject(&:empty?).each do |raw_repository| + commits_log = raw_repository.commits_per_day_for_user(user) + date_timestamps << commits_log end - timestamps - end - def self.populate_timestamps_by_project(commits_log, timestamps, - project) - commits_log.each do |timestamp_date, commits_count| - if timestamps.has_key?("#{timestamp_date}") - timestamps["#{timestamp_date}"]. - merge!(project.path_with_namespace => commits_count) - else - hash = { "#{timestamp_date}" => { project.path_with_namespace => - commits_count } } - timestamps.merge!(hash) - end + date_timestamps = date_timestamps.inject do |collection, date| + collection.merge(date) { |k, old_v, new_v| old_v + new_v } end - timestamps - end - def self.latest_commit_date(timestamps) - if timestamps.nil? || timestamps.empty? - DateTime.now.to_date - else - Time.at(timestamps.keys.first.to_i).to_date + date_timestamps ||= [] + date_timestamps.each do |date, commits| + timestamp = Date.parse(date).to_time.to_i.to_s + @timestamps[timestamp] = commits end end - - def self.last_commit_date(timestamps) - latest_commit_date(timestamps).to_formatted_s(:long).to_s - end - - def self.commit_activity_match(user_activities, date) - user_activities.select { |x| Time.at(x.to_i) == Time.parse(date) } - end end end |