Skip to content

Commit

Permalink
Only count users own actions for heatmap contributions (#5647) (#5655)
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Tölle <julian.toelle97@gmail.com>
  • Loading branch information
apricote authored and lafriks committed Jan 6, 2019
1 parent 652e09f commit 41a2bfe
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions models/user_heatmap.go
Expand Up @@ -32,12 +32,22 @@ func GetUserHeatmapDataByUser(user *User) ([]*UserHeatmapData, error) {
groupByName = groupBy
}

err := x.Select(groupBy+" AS timestamp, count(user_id) as contributions").
sess := x.Select(groupBy+" AS timestamp, count(user_id) as contributions").
Table("action").
Where("user_id = ?", user.ID).
And("created_unix > ?", (util.TimeStampNow() - 31536000)).
GroupBy(groupByName).
And("created_unix > ?", (util.TimeStampNow() - 31536000))

// * Heatmaps for individual users only include actions that the user themself
// did.
// * For organizations actions by all users that were made in owned
// repositories are counted.
if user.Type == UserTypeIndividual {
sess = sess.And("act_user_id = ?", user.ID)
}

err := sess.GroupBy(groupByName).
OrderBy("timestamp").
Find(&hdata)

return hdata, err
}

0 comments on commit 41a2bfe

Please sign in to comment.