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
8 files
+ 104
15
Compare changes
  • Side-by-side
  • Inline
Files
8
+ 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 >= '#{date.beginning_of_day}'
AND created_at <= '#{date.end_of_day}'
AND author_id IS NOT NULL
AND (
(
target_type in ('MergeRequest', 'Issue')
AND action in (
#{Event::CREATED},
#{Event::PUSHED},
#{Event::CLOSED},
#{Event::MERGED}
)
)
OR (target_type = 'Note' AND action = #{Event::COMMENTED})
)
GROUP BY author_id
EOF
end
end
Loading