Skip to content

Commit

Permalink
Add heatmap data caching and query for user contributions
Browse files Browse the repository at this point in the history
  • Loading branch information
kcne committed Dec 17, 2024
1 parent 467ef94 commit f46796f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,23 @@ def show
if @user &&
(@user.visible? || current_user&.administrator?)
@title = @user.display_name

one_year_ago = 1.year.ago
@heatmap_data = Rails.cache.fetch("heatmap_data_user_#{@user.id}", :expires_in => 1.day) do
Changeset
.where(:user_id => @user.id)
.where(:created_at => one_year_ago..)
.where(:num_changes => 1..)
.group("date_trunc('day', created_at)")
.select("date_trunc('day', created_at) AS date, SUM(num_changes) AS total_changes")
.order("date")
.map do |changeset|
{
:date => changeset.date.to_date.to_s,
:total_changes => changeset.total_changes.to_i
}
end
end
else
render_unknown_user params[:display_name]
end
Expand Down

0 comments on commit f46796f

Please sign in to comment.