Skip to content

Commit

Permalink
Fixed heatmap not working in mssql (#5248)
Browse files Browse the repository at this point in the history
  • Loading branch information
kolaente authored and techknowlogick committed Nov 1, 2018
1 parent fa16562 commit 225c489
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions models/user_heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type UserHeatmapData struct {
func GetUserHeatmapDataByUser(user *User) ([]*UserHeatmapData, error) {
hdata := make([]*UserHeatmapData, 0)
var groupBy string
var groupByName = "timestamp" // We need this extra case because mssql doesn't allow grouping by alias
switch {
case setting.UseSQLite3:
groupBy = "strftime('%s', strftime('%Y-%m-%d', created_unix, 'unixepoch'))"
Expand All @@ -28,13 +29,14 @@ func GetUserHeatmapDataByUser(user *User) ([]*UserHeatmapData, error) {
groupBy = "extract(epoch from date_trunc('day', to_timestamp(created_unix)))"
case setting.UseMSSQL:
groupBy = "dateadd(DAY,0, datediff(day,0, dateadd(s, created_unix, '19700101')))"
groupByName = groupBy
}

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

0 comments on commit 225c489

Please sign in to comment.