Skip to content
Snippets Groups Projects

WIP: Use a new table for user contribution stats

Closed ido leibovich requested to merge leibo/gitlab-ce:user-contribution-table into master
4 unresolved threads
Compare and
11 files
+ 136
55
Compare changes
  • Side-by-side
  • Inline
Files
11
+ 27
0
class UserContribution < ActiveRecord::Base
belongs_to :user
def self.calculate_for(date)
UserContribution.connection.execute <<-EOF
INSERT INTO user_contributions (user_id, date, contributions)
SELECT author_id, '#{date.strftime('%Y-%m-%d')}', count(*) AS contributions
FROM events
WHERE created_at >= '#{connection.quote(date.beginning_of_day)}'
AND created_at <= '#{connection.quote(date.end_of_day)}'
AND author_id IS NOT NULL
AND (
(
target_type in ('MergeRequest', 'Issue')
AND action in (
#{Event::CREATED},
#{Event::CLOSED},
#{Event::MERGED}
)
)
OR (target_type = 'Note' AND action = #{Event::COMMENTED})
OR action = #{Event::PUSHED}
)
GROUP BY author_id
EOF
end
end
Loading