Migrate POST.AnalyticsPostCount to Sync by default (#11179)
* Migrate POST.AnalyticsPostCount to Sync by default * Fix: Query identation
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
9ec99593eb
Коммит
bd8e047458
@@ -1043,35 +1043,34 @@ func (s *SqlPostStore) AnalyticsPostCountsByDay(teamId string) (model.AnalyticsR
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
query :=
|
||||
`SELECT
|
||||
COUNT(Posts.Id) AS Value
|
||||
FROM
|
||||
Posts,
|
||||
Channels
|
||||
WHERE
|
||||
Posts.ChannelId = Channels.Id`
|
||||
func (s *SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) (int64, *model.AppError) {
|
||||
query :=
|
||||
`SELECT
|
||||
COUNT(Posts.Id) AS Value
|
||||
FROM
|
||||
Posts,
|
||||
Channels
|
||||
WHERE
|
||||
Posts.ChannelId = Channels.Id`
|
||||
|
||||
if len(teamId) > 0 {
|
||||
query += " AND Channels.TeamId = :TeamId"
|
||||
}
|
||||
if len(teamId) > 0 {
|
||||
query += " AND Channels.TeamId = :TeamId"
|
||||
}
|
||||
|
||||
if mustHaveFile {
|
||||
query += " AND (Posts.FileIds != '[]' OR Posts.Filenames != '[]')"
|
||||
}
|
||||
if mustHaveFile {
|
||||
query += " AND (Posts.FileIds != '[]' OR Posts.Filenames != '[]')"
|
||||
}
|
||||
|
||||
if mustHaveHashtag {
|
||||
query += " AND Posts.Hashtags != ''"
|
||||
}
|
||||
if mustHaveHashtag {
|
||||
query += " AND Posts.Hashtags != ''"
|
||||
}
|
||||
|
||||
if v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId}); err != nil {
|
||||
result.Err = model.NewAppError("SqlPostStore.AnalyticsPostCount", "store.sql_post.analytics_posts_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
result.Data = v
|
||||
}
|
||||
})
|
||||
v, err := s.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId})
|
||||
if err != nil {
|
||||
return 0, model.NewAppError("SqlPostStore.AnalyticsPostCount", "store.sql_post.analytics_posts_count.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
return v, nil
|
||||
}
|
||||
|
||||
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
|
||||
AnalyticsUserCountsWithPostsByDay(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()
|
||||
InvalidateLastPostTimeCache(channelId string)
|
||||
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
|
||||
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)
|
||||
|
||||
var r0 store.StoreChannel
|
||||
if rf, ok := ret.Get(0).(func(string, bool, bool) store.StoreChannel); ok {
|
||||
var r0 int64
|
||||
if rf, ok := ret.Get(0).(func(string, bool, bool) int64); ok {
|
||||
r0 = rf(teamId, mustHaveFile, mustHaveHashtag)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(store.StoreChannel)
|
||||
r0 = ret.Get(0).(int64)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -1368,10 +1368,10 @@ func testPostCountsByDay(t *testing.T, ss store.Store) {
|
||||
}
|
||||
}
|
||||
|
||||
if r1 := <-ss.Post().AnalyticsPostCount(t1.Id, false, false); r1.Err != nil {
|
||||
t.Fatal(r1.Err)
|
||||
if r1, err := ss.Post().AnalyticsPostCount(t1.Id, false, false); err != nil {
|
||||
t.Fatal(err)
|
||||
} else {
|
||||
if r1.Data.(int64) != 4 {
|
||||
if r1 != 4 {
|
||||
t.Fatal("wrong value")
|
||||
}
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user