mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
[MM-53407] server/user_store: avoid antijoin for AnalyticsActiveCount query (#23993)
This commit is contained in:
parent
abdf4e58c3
commit
51c6e77972
@ -1359,15 +1359,17 @@ func (us SqlUserStore) AnalyticsActiveCount(timePeriod int64, options model.User
|
||||
query := us.getQueryBuilder().Select("COUNT(*)").From("Status AS s").Where("LastActivityAt > ?", time)
|
||||
|
||||
if !options.IncludeBotAccounts {
|
||||
query = query.LeftJoin("Bots ON s.UserId = Bots.UserId").Where("Bots.UserId IS NULL")
|
||||
if us.DriverName() == model.DatabaseDriverPostgres {
|
||||
query = query.LeftJoin("Bots ON s.UserId = Bots.UserId").Where("Bots.UserId IS NULL")
|
||||
} else {
|
||||
query = query.Where(sq.Expr("UserId NOT IN (SELECT UserId FROM Bots)"))
|
||||
}
|
||||
}
|
||||
|
||||
if !options.IncludeDeleted {
|
||||
query = query.LeftJoin("Users ON s.UserId = Users.Id").Where("Users.DeleteAt = 0")
|
||||
}
|
||||
|
||||
queryStr, args, err := query.ToSql()
|
||||
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "analytics_active_count_tosql")
|
||||
}
|
||||
@ -1384,7 +1386,11 @@ func (us SqlUserStore) AnalyticsActiveCountForPeriod(startTime int64, endTime in
|
||||
query := us.getQueryBuilder().Select("COUNT(*)").From("Status AS s").Where("LastActivityAt > ? AND LastActivityAt <= ?", startTime, endTime)
|
||||
|
||||
if !options.IncludeBotAccounts {
|
||||
query = query.LeftJoin("Bots ON s.UserId = Bots.UserId").Where("Bots.UserId IS NULL")
|
||||
if us.DriverName() == model.DatabaseDriverPostgres {
|
||||
query = query.LeftJoin("Bots ON s.UserId = Bots.UserId").Where("Bots.UserId IS NULL")
|
||||
} else {
|
||||
query = query.Where(sq.Expr("UserId NOT IN (SELECT UserId FROM Bots)"))
|
||||
}
|
||||
}
|
||||
|
||||
if !options.IncludeDeleted {
|
||||
@ -1392,7 +1398,6 @@ func (us SqlUserStore) AnalyticsActiveCountForPeriod(startTime int64, endTime in
|
||||
}
|
||||
|
||||
queryStr, args, err := query.ToSql()
|
||||
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "Failed to build query.")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user