From 8239c68cf323e4bb20007d2b456336becead273d Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Thu, 25 Feb 2016 12:32:46 -0500 Subject: Refactor and modularize analytics on the client --- store/sql_command_store.go | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'store/sql_command_store.go') 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 -- cgit v1.2.3-1-g7c22