]> source.dussan.org Git - gitea.git/commitdiff
Fixed heatmap not working in mssql (#5248)
authorkolaente <konrad@kola-entertainments.de>
Thu, 1 Nov 2018 18:12:17 +0000 (19:12 +0100)
committertechknowlogick <hello@techknowlogick.com>
Thu, 1 Nov 2018 18:12:17 +0000 (14:12 -0400)
models/user_heatmap.go

index f9575ed50fc4f14121e90cbe86c0a1f171f52f86..9e603f4fe179100a99338e9053f838b205e061af 100644 (file)
@@ -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'))"
@@ -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