summaryrefslogtreecommitdiffstats
path: root/store/sql_post_store.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2016-01-21 12:14:17 -0500
committerJoramWilander <jwawilander@gmail.com>2016-01-21 12:14:23 -0500
commit2a26d857574f2160e3ee5538ad3a84ec47082f86 (patch)
treef7a253736eb21ecc1f4f93f95741405da7fa0321 /store/sql_post_store.go
parent2fdfdaeff7a0bf29fd21eec6d4f48abe579d5048 (diff)
downloadchat-2a26d857574f2160e3ee5538ad3a84ec47082f86.tar.gz
chat-2a26d857574f2160e3ee5538ad3a84ec47082f86.tar.bz2
chat-2a26d857574f2160e3ee5538ad3a84ec47082f86.zip
Generalize analytics server functions and begin componentizing client analytics controls
Diffstat (limited to 'store/sql_post_store.go')
-rw-r--r--store/sql_post_store.go52
1 files changed, 36 insertions, 16 deletions
diff --git a/store/sql_post_store.go b/store/sql_post_store.go
index 40dca9930..e332858e4 100644
--- a/store/sql_post_store.go
+++ b/store/sql_post_store.go
@@ -805,9 +805,13 @@ func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChan
FROM
Posts, Channels
WHERE
- Posts.ChannelId = Channels.Id
- AND Channels.TeamId = :TeamId
- AND Posts.CreateAt <= :EndTime
+ Posts.ChannelId = Channels.Id`
+
+ if len(teamId) > 0 {
+ query += " AND Channels.TeamId = :TeamId"
+ }
+
+ query += ` AND Posts.CreateAt <= :EndTime
ORDER BY Name DESC) AS t1
GROUP BY Name
ORDER BY Name DESC
@@ -824,9 +828,13 @@ func (s SqlPostStore) AnalyticsUserCountsWithPostsByDay(teamId string) StoreChan
FROM
Posts, Channels
WHERE
- Posts.ChannelId = Channels.Id
- AND Channels.TeamId = :TeamId
- AND Posts.CreateAt <= :EndTime
+ Posts.ChannelId = Channels.Id`
+
+ if len(teamId) > 0 {
+ query += " AND Channels.TeamId = :TeamId"
+ }
+
+ query += ` AND Posts.CreateAt <= :EndTime
ORDER BY Name DESC) AS t1
GROUP BY Name
ORDER BY Name DESC
@@ -869,9 +877,13 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel {
FROM
Posts, Channels
WHERE
- Posts.ChannelId = Channels.Id
- AND Channels.TeamId = :TeamId
- AND Posts.CreateAt <= :EndTime
+ Posts.ChannelId = Channels.Id`
+
+ if len(teamId) > 0 {
+ query += " AND Channels.TeamId = :TeamId"
+ }
+
+ query += ` AND Posts.CreateAt <= :EndTime
AND Posts.CreateAt >= :StartTime) AS t1
GROUP BY Name
ORDER BY Name DESC
@@ -888,9 +900,13 @@ func (s SqlPostStore) AnalyticsPostCountsByDay(teamId string) StoreChannel {
FROM
Posts, Channels
WHERE
- Posts.ChannelId = Channels.Id
- AND Channels.TeamId = :TeamId
- AND Posts.CreateAt <= :EndTime
+ Posts.ChannelId = Channels.Id`
+
+ if len(teamId) > 0 {
+ query += " AND Channels.TeamId = :TeamId"
+ }
+
+ query += ` AND Posts.CreateAt <= :EndTime
AND Posts.CreateAt >= :StartTime) AS t1
GROUP BY Name
ORDER BY Name DESC
@@ -924,16 +940,20 @@ func (s SqlPostStore) AnalyticsPostCount(teamId string) StoreChannel {
go func() {
result := StoreResult{}
- v, err := s.GetReplica().SelectInt(
+ query :=
`SELECT
COUNT(Posts.Id) AS Value
FROM
Posts,
Channels
WHERE
- Posts.ChannelId = Channels.Id
- AND Channels.TeamId = :TeamId`,
- map[string]interface{}{"TeamId": teamId})
+ Posts.ChannelId = Channels.Id`
+
+ if len(teamId) > 0 {
+ query += " AND Channels.TeamId = :TeamId"
+ }
+
+ v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId})
if err != nil {
result.Err = model.NewAppError("SqlPostStore.AnalyticsPostCount", "We couldn't get post counts", err.Error())
} else {