aboutsummaryrefslogtreecommitdiffstats
path: root/models/user_heatmap.go
diff options
context:
space:
mode:
authorsiddweiker <siddweiker@users.noreply.github.com>2021-06-25 12:59:25 -0400
committerGitHub <noreply@github.com>2021-06-25 12:59:25 -0400
commitf573e93ed429d1d1dd0a7be8a3b0042f0817cc00 (patch)
treed71db3d42e18da8dd0910ac1e2db04ab841e0e9b /models/user_heatmap.go
parent3ef23d5411732b4b714d6fc9739bc5dac75aadd4 (diff)
downloadgitea-f573e93ed429d1d1dd0a7be8a3b0042f0817cc00.tar.gz
gitea-f573e93ed429d1d1dd0a7be8a3b0042f0817cc00.zip
Fix heatmap activity (#15252)
* Group heatmap actions by 15 minute intervals Signed-off-by: Sidd Weiker <siddweiker@gmail.com> * Add multi-contribution test for user heatmap Signed-off-by: Sidd Weiker <siddweiker@gmail.com> * Add timezone aware summation for activity heatmap Signed-off-by: Sidd Weiker <siddweiker@gmail.com> * Fix api user heatmap test Signed-off-by: Sidd Weiker <siddweiker@gmail.com> * Update variable declaration style Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models/user_heatmap.go')
-rw-r--r--models/user_heatmap.go11
1 files changed, 4 insertions, 7 deletions
diff --git a/models/user_heatmap.go b/models/user_heatmap.go
index 0e2767212e..306bd1819b 100644
--- a/models/user_heatmap.go
+++ b/models/user_heatmap.go
@@ -32,17 +32,14 @@ func getUserHeatmapData(user *User, team *Team, doer *User) ([]*UserHeatmapData,
return hdata, nil
}
- var groupBy string
+ // Group by 15 minute intervals which will allow the client to accurately shift the timestamp to their timezone.
+ // The interval is based on the fact that there are timezones such as UTC +5:30 and UTC +12:45.
+ groupBy := "created_unix / 900 * 900"
groupByName := "timestamp" // We need this extra case because mssql doesn't allow grouping by alias
switch {
- case setting.Database.UseSQLite3:
- groupBy = "strftime('%s', strftime('%Y-%m-%d', created_unix, 'unixepoch'))"
case setting.Database.UseMySQL:
- groupBy = "UNIX_TIMESTAMP(DATE(FROM_UNIXTIME(created_unix)))"
- case setting.Database.UsePostgreSQL:
- groupBy = "extract(epoch from date_trunc('day', to_timestamp(created_unix)))"
+ groupBy = "created_unix DIV 900 * 900"
case setting.Database.UseMSSQL:
- groupBy = "datediff(SECOND, '19700101', dateadd(DAY, 0, datediff(day, 0, dateadd(s, created_unix, '19700101'))))"
groupByName = groupBy
}