[MM-44263] Only include user posts in post count (#20250)

* Fetch users only posts

* Explicitly validate posts count before testing usage
Этот коммит содержится в:
Vishal
2022-05-31 14:18:41 +05:30
коммит произвёл GitHub
родитель 70610a9c96
Коммит 57e9aa767c
5 изменённых файлов: 30 добавлений и 5 удалений

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

@@ -2162,6 +2162,13 @@ func (s *SqlPostStore) AnalyticsPostCount(options *model.PostCountOptions) (int6
Where(sq.Eq{"c.TeamId": options.TeamId})
}
if options.UsersPostsOnly {
query = query.Where(sq.And{
sq.Eq{"p.Type": ""},
sq.Expr("p.UserId NOT IN (SELECT UserId FROM Bots)"),
})
}
if options.MustHaveFile {
query = query.Where(sq.Or{sq.NotEq{"p.FileIds": "[]"}, sq.NotEq{"p.Filenames": "[]"}})
}

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

@@ -2163,7 +2163,7 @@ func testPostCountsByDay(t *testing.T, ss store.Store) {
require.NoError(t, err)
assert.GreaterOrEqual(t, r2, int64(2))
// total across teams with hastags and files
// total across teams with hashtags and files
r2, err = ss.Post().AnalyticsPostCount(&model.PostCountOptions{MustHaveFile: true, MustHaveHashtag: true})
require.NoError(t, err)
assert.GreaterOrEqual(t, r2, int64(1))
@@ -2176,6 +2176,11 @@ func testPostCountsByDay(t *testing.T, ss store.Store) {
r2, err = ss.Post().AnalyticsPostCount(&model.PostCountOptions{TeamId: t1.Id, ExcludeDeleted: true})
require.NoError(t, err)
assert.Equal(t, int64(5), r2)
// total users only posts for single team with the deleted post excluded
r2, err = ss.Post().AnalyticsPostCount(&model.PostCountOptions{TeamId: t1.Id, ExcludeDeleted: true, UsersPostsOnly: true})
require.NoError(t, err)
assert.Equal(t, int64(3), r2)
}
func testPostStoreGetFlaggedPostsForTeam(t *testing.T, ss store.Store, s SqlStore) {