Migrate POST.AnalyticsPostCount to Sync by default (#11179)
* Migrate POST.AnalyticsPostCount to Sync by default * Fix: Query identation
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
9ec99593eb
Коммит
bd8e047458
@@ -59,7 +59,12 @@ func (a *App) GetAnalytics(name string, teamId string) (model.AnalyticsRows, *mo
|
|||||||
|
|
||||||
var postChan store.StoreChannel
|
var postChan store.StoreChannel
|
||||||
if !skipIntensiveQueries {
|
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)
|
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 fileChan store.StoreChannel
|
||||||
var hashtagChan store.StoreChannel
|
var hashtagChan store.StoreChannel
|
||||||
|
|
||||||
if !skipIntensiveQueries {
|
if !skipIntensiveQueries {
|
||||||
fileChan = a.Srv.Store.Post().AnalyticsPostCount(teamId, true, false)
|
fileChan = make(chan store.StoreResult, 1)
|
||||||
hashtagChan = a.Srv.Store.Post().AnalyticsPostCount(teamId, false, true)
|
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 {
|
if fileChan == nil {
|
||||||
|
|||||||
@@ -191,9 +191,7 @@ func (a *App) trackActivity() {
|
|||||||
deletedPrivateChannelCount = dpccr.Data.(int64)
|
deletedPrivateChannelCount = dpccr.Data.(int64)
|
||||||
}
|
}
|
||||||
|
|
||||||
if pcr := <-a.Srv.Store.Post().AnalyticsPostCount("", false, false); pcr.Err == nil {
|
postsCount, _ = a.Srv.Store.Post().AnalyticsPostCount("", false, false)
|
||||||
postsCount = pcr.Data.(int64)
|
|
||||||
}
|
|
||||||
|
|
||||||
slashCommandsCount, _ = a.Srv.Store.Command().AnalyticsCommandCount("")
|
slashCommandsCount, _ = a.Srv.Store.Command().AnalyticsCommandCount("")
|
||||||
|
|
||||||
|
|||||||
@@ -1799,11 +1799,9 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Count the number of posts in the testing team.
|
// Count the number of posts in the testing team.
|
||||||
var initialPostCount int64
|
initialPostCount, err := th.App.Srv.Store.Post().AnalyticsPostCount(team.Id, false, false)
|
||||||
if result := <-th.App.Srv.Store.Post().AnalyticsPostCount(team.Id, false, false); result.Err != nil {
|
if err != nil {
|
||||||
t.Fatal(result.Err)
|
t.Fatal(err)
|
||||||
} else {
|
|
||||||
initialPostCount = result.Data.(int64)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try adding an invalid post in dry run mode.
|
// Try adding an invalid post in dry run mode.
|
||||||
@@ -2368,9 +2366,9 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||||||
directChannel = channel
|
directChannel = channel
|
||||||
|
|
||||||
// Get the number of posts in the system.
|
// Get the number of posts in the system.
|
||||||
result := <-th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
|
result, err := th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
initialPostCount := result.Data.(int64)
|
initialPostCount := result
|
||||||
|
|
||||||
// Try adding an invalid post in dry run mode.
|
// Try adding an invalid post in dry run mode.
|
||||||
data := &DirectPostImportData{
|
data := &DirectPostImportData{
|
||||||
@@ -2534,9 +2532,9 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||||||
groupChannel = channel
|
groupChannel = channel
|
||||||
|
|
||||||
// Get the number of posts in the system.
|
// Get the number of posts in the system.
|
||||||
result = <-th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
|
result, err = th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, err)
|
||||||
initialPostCount = result.Data.(int64)
|
initialPostCount = result
|
||||||
|
|
||||||
// Try adding an invalid post in dry run mode.
|
// Try adding an invalid post in dry run mode.
|
||||||
data = &DirectPostImportData{
|
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) {
|
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 {
|
if result, err := a.Srv.Store.Post().AnalyticsPostCount(teamName, false, false); err != nil {
|
||||||
t.Fatal(result.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if initialCount+change != result.Data.(int64) {
|
if initialCount+change != result {
|
||||||
debug.PrintStack()
|
debug.PrintStack()
|
||||||
t.Fatalf("Did not find the expected number of posts.")
|
t.Fatalf("Did not find the expected number of posts.")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1043,35 +1043,34 @@ func (s *SqlPostStore) AnalyticsPostCountsByDay(teamId string) (model.AnalyticsR
|
|||||||
return rows, nil
|
return rows, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) store.StoreChannel {
|
func (s *SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) (int64, *model.AppError) {
|
||||||
return store.Do(func(result *store.StoreResult) {
|
query :=
|
||||||
query :=
|
`SELECT
|
||||||
`SELECT
|
COUNT(Posts.Id) AS Value
|
||||||
COUNT(Posts.Id) AS Value
|
FROM
|
||||||
FROM
|
Posts,
|
||||||
Posts,
|
Channels
|
||||||
Channels
|
WHERE
|
||||||
WHERE
|
Posts.ChannelId = Channels.Id`
|
||||||
Posts.ChannelId = Channels.Id`
|
|
||||||
|
|
||||||
if len(teamId) > 0 {
|
if len(teamId) > 0 {
|
||||||
query += " AND Channels.TeamId = :TeamId"
|
query += " AND Channels.TeamId = :TeamId"
|
||||||
}
|
}
|
||||||
|
|
||||||
if mustHaveFile {
|
if mustHaveFile {
|
||||||
query += " AND (Posts.FileIds != '[]' OR Posts.Filenames != '[]')"
|
query += " AND (Posts.FileIds != '[]' OR Posts.Filenames != '[]')"
|
||||||
}
|
}
|
||||||
|
|
||||||
if mustHaveHashtag {
|
if mustHaveHashtag {
|
||||||
query += " AND Posts.Hashtags != ''"
|
query += " AND Posts.Hashtags != ''"
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId}); err != nil {
|
v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId})
|
||||||
result.Err = model.NewAppError("SqlPostStore.AnalyticsPostCount", "store.sql_post.analytics_posts_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
if err != nil {
|
||||||
} else {
|
return 0, model.NewAppError("SqlPostStore.AnalyticsPostCount", "store.sql_post.analytics_posts_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
result.Data = v
|
}
|
||||||
}
|
|
||||||
})
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SqlPostStore) GetPostsCreatedAt(channelId string, time int64) ([]*model.Post, *model.AppError) {
|
func (s *SqlPostStore) GetPostsCreatedAt(channelId string, time int64) ([]*model.Post, *model.AppError) {
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ type PostStore interface {
|
|||||||
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
|
Search(teamId string, userId string, params *model.SearchParams) StoreChannel
|
||||||
AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError)
|
AnalyticsUserCountsWithPostsByDay(teamId string) (model.AnalyticsRows, *model.AppError)
|
||||||
AnalyticsPostCountsByDay(teamId string) (model.AnalyticsRows, *model.AppError)
|
AnalyticsPostCountsByDay(teamId string) (model.AnalyticsRows, *model.AppError)
|
||||||
AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) StoreChannel
|
AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) (int64, *model.AppError)
|
||||||
ClearCaches()
|
ClearCaches()
|
||||||
InvalidateLastPostTimeCache(channelId string)
|
InvalidateLastPostTimeCache(channelId string)
|
||||||
GetPostsCreatedAt(channelId string, time int64) ([]*model.Post, *model.AppError)
|
GetPostsCreatedAt(channelId string, time int64) ([]*model.Post, *model.AppError)
|
||||||
|
|||||||
@@ -14,19 +14,26 @@ type PostStore struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsPostCount provides a mock function with given fields: teamId, mustHaveFile, mustHaveHashtag
|
// AnalyticsPostCount provides a mock function with given fields: teamId, mustHaveFile, mustHaveHashtag
|
||||||
func (_m *PostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) store.StoreChannel {
|
func (_m *PostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) (int64, *model.AppError) {
|
||||||
ret := _m.Called(teamId, mustHaveFile, mustHaveHashtag)
|
ret := _m.Called(teamId, mustHaveFile, mustHaveHashtag)
|
||||||
|
|
||||||
var r0 store.StoreChannel
|
var r0 int64
|
||||||
if rf, ok := ret.Get(0).(func(string, bool, bool) store.StoreChannel); ok {
|
if rf, ok := ret.Get(0).(func(string, bool, bool) int64); ok {
|
||||||
r0 = rf(teamId, mustHaveFile, mustHaveHashtag)
|
r0 = rf(teamId, mustHaveFile, mustHaveHashtag)
|
||||||
} else {
|
} else {
|
||||||
if ret.Get(0) != nil {
|
r0 = ret.Get(0).(int64)
|
||||||
r0 = ret.Get(0).(store.StoreChannel)
|
}
|
||||||
|
|
||||||
|
var r1 *model.AppError
|
||||||
|
if rf, ok := ret.Get(1).(func(string, bool, bool) *model.AppError); ok {
|
||||||
|
r1 = rf(teamId, mustHaveFile, mustHaveHashtag)
|
||||||
|
} else {
|
||||||
|
if ret.Get(1) != nil {
|
||||||
|
r1 = ret.Get(1).(*model.AppError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return r0
|
return r0, r1
|
||||||
}
|
}
|
||||||
|
|
||||||
// AnalyticsPostCountsByDay provides a mock function with given fields: teamId
|
// AnalyticsPostCountsByDay provides a mock function with given fields: teamId
|
||||||
|
|||||||
@@ -1368,10 +1368,10 @@ func testPostCountsByDay(t *testing.T, ss store.Store) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if r1 := <-ss.Post().AnalyticsPostCount(t1.Id, false, false); r1.Err != nil {
|
if r1, err := ss.Post().AnalyticsPostCount(t1.Id, false, false); err != nil {
|
||||||
t.Fatal(r1.Err)
|
t.Fatal(err)
|
||||||
} else {
|
} else {
|
||||||
if r1.Data.(int64) != 4 {
|
if r1 != 4 {
|
||||||
t.Fatal("wrong value")
|
t.Fatal("wrong value")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user