Migrate POST.AnalyticsPostCount to Sync by default (#11179)

* Migrate POST.AnalyticsPostCount to Sync by default

* Fix: Query identation
Этот коммит содержится в:
Rodrigo Villablanca Vásquez
2019-06-14 11:52:17 -04:00
коммит произвёл Jesús Espino
родитель 9ec99593eb
Коммит bd8e047458
8 изменённых файлов: 74 добавлений и 55 удалений

Просмотреть файл

@@ -59,7 +59,12 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
var postChan store.StoreChannel
if !skipIntensiveQueries {
postChan = a.Srv.Store.Post().AnalyticsPostCount(teamId, false, false)
postChan = make(chan store.StoreResult, 1)
go func() {
count, err := a.Srv.Store.Post().AnalyticsPostCount(teamId, false, false)
postChan <- store.StoreResult{Data: count, Err: err}
close(postChan)
}()
}
dailyActiveChan := a.Srv.Store.User().AnalyticsActiveCount(DAY_MILLISECONDS)
@@ -212,9 +217,21 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
var fileChan store.StoreChannel
var hashtagChan store.StoreChannel
if !skipIntensiveQueries {
fileChan = a.Srv.Store.Post().AnalyticsPostCount(teamId, true, false)
hashtagChan = a.Srv.Store.Post().AnalyticsPostCount(teamId, false, true)
fileChan = make(chan store.StoreResult, 1)
go func() {
count, err := a.Srv.Store.Post().AnalyticsPostCount(teamId, true, false)
fileChan <- store.StoreResult{Data: count, Err: err}
close(fileChan)
}()
hashtagChan = make(chan store.StoreResult, 1)
go func() {
count, err := a.Srv.Store.Post().AnalyticsPostCount(teamId, false, true)
hashtagChan <- store.StoreResult{Data: count, Err: err}
close(hashtagChan)
}()
}
if fileChan == nil {

Просмотреть файл

@@ -191,9 +191,7 @@ func (a *App) trackActivity() {
deletedPrivateChannelCount = dpccr.Data.(int64)
}
if pcr := <-a.Srv.Store.Post().AnalyticsPostCount("", false, false); pcr.Err == nil {
postsCount = pcr.Data.(int64)
}
postsCount, _ = a.Srv.Store.Post().AnalyticsPostCount("", false, false)
slashCommandsCount, _ = a.Srv.Store.Command().AnalyticsCommandCount("")

Просмотреть файл

@@ -1799,11 +1799,9 @@ func TestImportImportPost(t *testing.T) {
}
// Count the number of posts in the testing team.
var initialPostCount int64
if result := <-th.App.Srv.Store.Post().AnalyticsPostCount(team.Id, false, false); result.Err != nil {
t.Fatal(result.Err)
} else {
initialPostCount = result.Data.(int64)
initialPostCount, err := th.App.Srv.Store.Post().AnalyticsPostCount(team.Id, false, false)
if err != nil {
t.Fatal(err)
}
// Try adding an invalid post in dry run mode.
@@ -2368,9 +2366,9 @@ func TestImportImportDirectPost(t *testing.T) {
directChannel = channel
// Get the number of posts in the system.
result := <-th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
require.Nil(t, result.Err)
initialPostCount := result.Data.(int64)
result, err := th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
require.Nil(t, err)
initialPostCount := result
// Try adding an invalid post in dry run mode.
data := &DirectPostImportData{
@@ -2534,9 +2532,9 @@ func TestImportImportDirectPost(t *testing.T) {
groupChannel = channel
// Get the number of posts in the system.
result = <-th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
require.Nil(t, result.Err)
initialPostCount = result.Data.(int64)
result, err = th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
require.Nil(t, err)
initialPostCount = result
// Try adding an invalid post in dry run mode.
data = &DirectPostImportData{

Просмотреть файл

@@ -81,10 +81,10 @@ func checkNoError(t *testing.T, err *model.AppError) {
}
func AssertAllPostsCount(t *testing.T, a *App, initialCount int64, change int64, teamName string) {
if result := <-a.Srv.Store.Post().AnalyticsPostCount(teamName, false, false); result.Err != nil {
t.Fatal(result.Err)
if result, err := a.Srv.Store.Post().AnalyticsPostCount(teamName, false, false); err != nil {
t.Fatal(err)
} else {
if initialCount+change != result.Data.(int64) {
if initialCount+change != result {
debug.PrintStack()
t.Fatalf("Did not find the expected number of posts.")
}