summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/event.rb6
-rw-r--r--app/models/project_contributions.rb32
-rw-r--r--app/models/repository.rb35
-rw-r--r--app/models/user.rb7
4 files changed, 8 insertions, 72 deletions
diff --git a/app/models/event.rb b/app/models/event.rb
index 2103a48a71b..57f6d5cd4e0 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -55,6 +55,12 @@ class Event < ActiveRecord::Base
order('id DESC').limit(100).
update_all(updated_at: Time.now)
end
+
+ def contributions
+ where("action = ? OR (target_type in (?) AND action in (?))",
+ Event::PUSHED, ["MergeRequest", "Issue"],
+ [Event::CREATED, Event::CLOSED, Event::MERGED])
+ end
end
def proper?
diff --git a/app/models/project_contributions.rb b/app/models/project_contributions.rb
deleted file mode 100644
index bfe9928b158..00000000000
--- a/app/models/project_contributions.rb
+++ /dev/null
@@ -1,32 +0,0 @@
-class ProjectContributions
- attr_reader :project, :user
-
- def initialize(project, user)
- @project, @user = project, user
- end
-
- def commits_log
- repository = project.repository
-
- if !repository.exists? || repository.empty?
- return {}
- end
-
- Rails.cache.fetch(cache_key) do
- repository.commits_per_day_for_user(user)
- end
- end
-
- def user_commits_on_date(date)
- repository = @project.repository
-
- if !repository.exists? || repository.empty?
- return []
- end
- commits = repository.commits_by_user_on_date_log(@user, date)
- end
-
- def cache_key
- "#{Date.today.to_s}-commits-log-#{project.id}-#{user.email}"
- end
-end
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 082ad7a0c6a..77765cae1a0 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -149,41 +149,6 @@ class Repository
end
end
- def timestamps_by_user_log(user)
- author_emails = '(' + user.all_emails.map{ |e| Regexp.escape(e) }.join('|') + ')'
- args = %W(git log -E --author=#{author_emails} --since=#{(Date.today - 1.year).to_s} --branches --pretty=format:%cd --date=short)
- dates = Gitlab::Popen.popen(args, path_to_repo).first.split("\n")
-
- if dates.present?
- dates
- else
- []
- end
- end
-
- def commits_by_user_on_date_log(user, date)
- # format the date string for git
- start_date = date.strftime("%Y-%m-%d 00:00:00")
- end_date = date.strftime("%Y-%m-%d 23:59:59")
-
- author_emails = '(' + user.all_emails.map{ |e| Regexp.escape(e) }.join('|') + ')'
- args = %W(git log -E --author=#{author_emails} --after=#{start_date.to_s} --until=#{end_date.to_s} --branches --pretty=format:%h)
- commits = Gitlab::Popen.popen(args, path_to_repo).first.split("\n")
-
- commits.map! do |commit_id|
- commit(commit_id)
- end
- end
-
- def commits_per_day_for_user(user)
- timestamps_by_user_log(user).
- group_by { |commit_date| commit_date }.
- inject({}) do |hash, (timestamp_date, commits)|
- hash[timestamp_date] = commits.count
- hash
- end
- end
-
def lookup_cache
@lookup_cache ||= {}
end
diff --git a/app/models/user.rb b/app/models/user.rb
index ba325132df8..50f664a09a3 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -603,13 +603,10 @@ class User < ActiveRecord::Base
end
def contributed_projects_ids
- Event.where(author_id: self).
+ Event.contributions.where(author_id: self).
where("created_at > ?", Time.now - 1.year).
- where("action = :pushed OR (target_type = 'MergeRequest' AND action = :created)",
- pushed: Event::PUSHED, created: Event::CREATED).
reorder(project_id: :desc).
select(:project_id).
- uniq
- .map(&:project_id)
+ uniq.map(&:project_id)
end
end