summaryrefslogtreecommitdiffstats
path: root/store/sql_command_store.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2016-02-25 12:32:46 -0500
committerJoramWilander <jwawilander@gmail.com>2016-03-01 10:46:30 -0500
commit8239c68cf323e4bb20007d2b456336becead273d (patch)
tree3422ed0946afafa47d6649e09f6f09ee71692363 /store/sql_command_store.go
parent8aa4e28932ec43090ca6b481929fafbe0119a660 (diff)
downloadchat-8239c68cf323e4bb20007d2b456336becead273d.tar.gz
chat-8239c68cf323e4bb20007d2b456336becead273d.tar.bz2
chat-8239c68cf323e4bb20007d2b456336becead273d.zip
Refactor and modularize analytics on the client
Diffstat (limited to 'store/sql_command_store.go')
-rw-r--r--store/sql_command_store.go41
1 files changed, 36 insertions, 5 deletions
diff --git a/store/sql_command_store.go b/store/sql_command_store.go
index 760235e10..074a6e588 100644
--- a/store/sql_command_store.go
+++ b/store/sql_command_store.go
@@ -151,18 +151,49 @@ func (s SqlCommandStore) PermanentDeleteByUser(userId string) StoreChannel {
return storeChannel
}
-func (s SqlCommandStore) Update(hook *model.Command) StoreChannel {
+func (s SqlCommandStore) Update(cmd *model.Command) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
- hook.UpdateAt = model.GetMillis()
+ cmd.UpdateAt = model.GetMillis()
- if _, err := s.GetMaster().Update(hook); err != nil {
- result.Err = model.NewLocAppError("SqlCommandStore.Update", "store.sql_command.save.update.app_error", nil, "id="+hook.Id+", "+err.Error())
+ if _, err := s.GetMaster().Update(cmd); err != nil {
+ result.Err = model.NewLocAppError("SqlCommandStore.Update", "store.sql_command.save.update.app_error", nil, "id="+cmd.Id+", "+err.Error())
} else {
- result.Data = hook
+ result.Data = cmd
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
+func (s SqlCommandStore) AnalyticsCommandCount(teamId string) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ query :=
+ `SELECT
+ COUNT(*)
+ FROM
+ Commands
+ WHERE
+ DeleteAt = 0`
+
+ if len(teamId) > 0 {
+ query += " AND TeamId = :TeamId"
+ }
+
+ if c, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId}); err != nil {
+ result.Err = model.NewLocAppError("SqlCommandStore.AnalyticsCommandCount", "store.sql_command.analytics_command_count.app_error", nil, err.Error())
+ } else {
+ result.Data = c
}
storeChannel <- result