[MM-43917] Cloud Freemium limits API: messages/posts (#20152)
* WIP - Add api and app funcs * Add test cases * Add utils testcases * Exclude deleted posts * Add doc for func * Move api from cloud to usage * Allow api access to authenticated users * Change int to int64 * Fix lint issue * Simplify err check Co-authored-by: Ashish Bhate <ashish.bhate@mattermost.com> Co-authored-by: Mattermod <mattermod@users.noreply.github.com> Co-authored-by: Ashish Bhate <ashish.bhate@mattermost.com>
Этот коммит содержится в:
@@ -2128,25 +2128,29 @@ func (s *SqlPostStore) AnalyticsPostCountsByDay(options *model.AnalyticsPostCoun
|
||||
return rows, nil
|
||||
}
|
||||
|
||||
func (s *SqlPostStore) AnalyticsPostCount(teamId string, mustHaveFile bool, mustHaveHashtag bool) (int64, error) {
|
||||
func (s *SqlPostStore) AnalyticsPostCount(options *model.PostCountOptions) (int64, error) {
|
||||
query := s.getQueryBuilder().
|
||||
Select("COUNT(p.Id) AS Value").
|
||||
From("Posts p")
|
||||
|
||||
if teamId != "" {
|
||||
if options.TeamId != "" {
|
||||
query = query.
|
||||
Join("Channels c ON (c.Id = p.ChannelId)").
|
||||
Where(sq.Eq{"c.TeamId": teamId})
|
||||
Where(sq.Eq{"c.TeamId": options.TeamId})
|
||||
}
|
||||
|
||||
if mustHaveFile {
|
||||
if options.MustHaveFile {
|
||||
query = query.Where(sq.Or{sq.NotEq{"p.FileIds": "[]"}, sq.NotEq{"p.Filenames": "[]"}})
|
||||
}
|
||||
|
||||
if mustHaveHashtag {
|
||||
if options.MustHaveHashtag {
|
||||
query = query.Where(sq.NotEq{"p.Hashtags": ""})
|
||||
}
|
||||
|
||||
if options.ExcludeDeleted {
|
||||
query = query.Where(sq.Eq{"p.DeleteAt": 0})
|
||||
}
|
||||
|
||||
queryString, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "post_tosql")
|
||||
|
||||
Ссылка в новой задаче
Block a user