Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed heatmap not working in mssql #5248

Merged
merged 2 commits into from
Nov 1, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed heatmap not working in mssql
  • Loading branch information
kolaente committed Nov 1, 2018
commit d4376b04c811c79ed96a20c08f15f9558b541ff3
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