@@ -414,17 +414,35 class Repository < ActiveRecord::Base | |||
|
414 | 414 | # Notes: |
|
415 | 415 | # - this hash honnors the users mapping defined for the repository |
|
416 | 416 | def stats_by_author |
|
417 |
commits |
|
|
418 | commits_by_author.to_a.sort! {|x, y| x.last <=> y.last} | |
|
419 | ||
|
420 | changes_by_author = Change.joins(:changeset).where("#{Changeset.table_name}.repository_id = ?", id).group(:committer).count | |
|
421 | h = changes_by_author.inject({}) {|o, i| o[i.first] = i.last; o} | |
|
417 | commits = Changeset.where("repository_id = ?", id) | |
|
418 | .select("committer, user_id, count(*) as count") | |
|
419 | .group("committer, user_id") | |
|
420 | ||
|
421 | #TODO: restore ordering ; this line probably never worked | |
|
422 | #commits.to_a.sort! {|x, y| x.last <=> y.last} | |
|
423 | ||
|
424 | changes = Change.joins(:changeset) | |
|
425 | .where("#{Changeset.table_name}.repository_id = ?", id) | |
|
426 | .select("committer, user_id, count(*) as count") | |
|
427 | .group("committer, user_id") | |
|
428 | ||
|
429 | user_ids = changesets.map(&:user_id).compact.uniq | |
|
430 | authors_names = User.where(:id => user_ids).inject({}) do |memo, user| | |
|
431 | memo[user.id] = user.to_s | |
|
432 | memo | |
|
433 | end | |
|
422 | 434 | |
|
423 |
commits |
|
|
424 |
mapped_name = |
|
|
435 | (commits + changes).inject({}) do |hash, element| | |
|
436 | mapped_name = element.committer | |
|
437 | if username = authors_names[element.user_id.to_i] | |
|
438 | mapped_name = username | |
|
439 | end | |
|
425 | 440 | hash[mapped_name] ||= { :commits_count => 0, :changes_count => 0 } |
|
426 | hash[mapped_name][:commits_count] += commits_count | |
|
427 |
hash[mapped_name][:c |
|
|
441 | if element.is_a?(Changeset) | |
|
442 | hash[mapped_name][:commits_count] += element.count.to_i | |
|
443 | else | |
|
444 | hash[mapped_name][:changes_count] += element.count.to_i | |
|
445 | end | |
|
428 | 446 | hash |
|
429 | 447 | end |
|
430 | 448 | end |
General Comments 0
You need to be logged in to leave comments.
Login now