MM-60415 ignore deactivated bots (#28184)
* ignore bot accounts when counting deactivated users * moved query to squirrel Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com> * set is null right * Run a different query depending on driver due to performance reasons. --------- Co-authored-by: Ben Schumacher <ben.schumacher@mattermost.com> Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9b368b9214
Коммит
dfa1d1027b
@@ -1708,7 +1708,27 @@ func (us SqlUserStore) performSearch(query sq.SelectBuilder, term string, option
|
||||
|
||||
func (us SqlUserStore) AnalyticsGetInactiveUsersCount() (int64, error) {
|
||||
var count int64
|
||||
err := us.GetReplicaX().Get(&count, "SELECT COUNT(Id) FROM Users WHERE DeleteAt > 0")
|
||||
query := us.getQueryBuilder().
|
||||
Select("COUNT(Id)").
|
||||
From("Users")
|
||||
if us.DriverName() == model.DatabaseDriverPostgres {
|
||||
query = query.LeftJoin("Bots ON Users.ID = Bots.UserId").
|
||||
Where(sq.And{
|
||||
sq.Gt{"Users.DeleteAt": 0},
|
||||
sq.Eq{"Bots.UserId": nil},
|
||||
})
|
||||
} else {
|
||||
query = query.Where(sq.And{
|
||||
sq.Expr("Users.Id NOT IN (SELECT UserId FROM Bots)"),
|
||||
sq.Gt{"Users.DeleteAt": 0},
|
||||
})
|
||||
}
|
||||
queryStr, args, err := query.ToSql()
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to create a SQL query to count inactive users")
|
||||
}
|
||||
err = us.GetReplicaX().Get(&count, queryStr, args...)
|
||||
|
||||
if err != nil {
|
||||
return int64(0), errors.Wrap(err, "failed to count inactive Users")
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user