summaryrefslogtreecommitdiffstats
path: root/store/sql_post_store.go
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-10-26 22:46:19 -0700
committer=Corey Hulen <corey@hulen.com>2015-10-26 22:46:19 -0700
commitd53de8421421f4251cc4cff2118814246548d687 (patch)
treeb88de78f8205afd063d29d070f30270c63e79fec /store/sql_post_store.go
parent834e1a8b58496e721f086f04612658c4a22c8d7d (diff)
downloadchat-d53de8421421f4251cc4cff2118814246548d687.tar.gz
chat-d53de8421421f4251cc4cff2118814246548d687.tar.bz2
chat-d53de8421421f4251cc4cff2118814246548d687.zip
Fixing postgres
Diffstat (limited to 'store/sql_post_store.go')
-rw-r--r--store/sql_post_store.go57
1 files changed, 49 insertions, 8 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index d1f308b5a..f21bbee7a 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -610,9 +610,7 @@ func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChan
go func() {
result := StoreResult{}
- var rows model.AnalyticsRows
- _, err := s.GetReplica().Select(
- &rows,
+ query :=
`SELECT
t1.Name, COUNT(t1.UserId) AS Value
FROM
@@ -627,7 +625,31 @@ func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChan
ORDER BY Name DESC) AS t1
GROUP BY Name
ORDER BY Name DESC
- LIMIT 30`,
+ LIMIT 30`
+
+ if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
+ query =
+ `SELECT
+ t1.Name, COUNT(t1.UserId) AS Value
+ FROM
+ (SELECT DISTINCT
+ DATE(TO_TIMESTAMP(Posts.CreateAt / 1000)) AS Name,
+ Posts.UserId
+ FROM
+ Posts, Channels
+ WHERE
+ Posts.ChannelId = Channels.Id
+ AND Channels.TeamId = :TeamId
+ ORDER BY Name DESC) AS t1
+ GROUP BY Name
+ ORDER BY Name DESC
+ LIMIT 30`
+ }
+
+ var rows model.AnalyticsRows
+ _, err := s.GetReplica().Select(
+ &rows,
+ query,
map[string]interface{}{"TeamId": teamId})
if err != nil {
result.Err = model.NewAppError("SqlPostStore.AnalyticsUserCountsWithPostsByDay", "We couldn't get user counts with posts", err.Error())
@@ -648,9 +670,7 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel {
go func() {
result := StoreResult{}
- var rows model.AnalyticsRows
- _, err := s.GetReplica().Select(
- &rows,
+ query :=
`SELECT
DATE(FROM_UNIXTIME(Posts.CreateAt / 1000)) AS Name,
COUNT(Posts.Id) AS Value
@@ -662,7 +682,28 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel {
AND Channels.TeamId = :TeamId
GROUP BY Name
ORDER BY Name DESC
- LIMIT 30`,
+ LIMIT 30`
+
+ if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
+ query =
+ `SELECT
+ DATE(TO_TIMESTAMP(Posts.CreateAt / 1000)) AS Name,
+ COUNT(Posts.Id) AS Value
+ FROM
+ Posts,
+ Channels
+ WHERE
+ Posts.ChannelId = Channels.Id
+ AND Channels.TeamId = :TeamId
+ GROUP BY Name
+ ORDER BY Name DESC
+ LIMIT 30`
+ }
+
+ var rows model.AnalyticsRows
+ _, err := s.GetReplica().Select(
+ &rows,
+ query,
map[string]interface{}{"TeamId": teamId})
if err != nil {
result.Err = model.NewAppError("SqlPostStore.AnalyticsPostCountsByDay", "We couldn't get post counts by day", err.Error())