Add metrics for mobile versions snapshots (#28191)
* Add metrics for mobile versions snapshots * Add notifications disabled and fix lint * Address feedback * Verify all references to JobTypeActiveUsers * Fix typos * Improve platform values * Add test and MySQL support
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
d45a54a8e9
Коммит
040838b056
@@ -164,6 +164,38 @@ func (me SqlSessionStore) GetSessionsWithActiveDeviceIds(userId string) ([]*mode
|
||||
return sessions, nil
|
||||
}
|
||||
|
||||
func (me SqlSessionStore) GetMobileSessionMetadata() ([]*model.MobileSessionMetadata, error) {
|
||||
versionProp := model.SessionPropMobileVersion
|
||||
notificationDisabledProp := model.SessionPropDeviceNotificationDisabled
|
||||
platformQuery := "NULLIF(SPLIT_PART(deviceid, ':', 1), '')"
|
||||
if me.DriverName() == model.DatabaseDriverMysql {
|
||||
versionProp = "$." + versionProp
|
||||
notificationDisabledProp = "$." + notificationDisabledProp
|
||||
platformQuery = "NULLIF(SUBSTRING_INDEX(deviceid, ':', 1), deviceid)"
|
||||
}
|
||||
|
||||
query, args, err := me.getQueryBuilder().
|
||||
Select(fmt.Sprintf(
|
||||
"COUNT(userid) AS Count, COALESCE(%s,'N/A') AS Platform, COALESCE(props->>'%s','N/A') AS Version, COALESCE(props->>'%s','false') as NotificationDisabled",
|
||||
platformQuery,
|
||||
versionProp,
|
||||
notificationDisabledProp,
|
||||
)).
|
||||
From("Sessions").
|
||||
GroupBy("Platform", "Version", "NotificationDisabled").
|
||||
ToSql()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "sessions_tosql")
|
||||
}
|
||||
|
||||
versions := []*model.MobileSessionMetadata{}
|
||||
err = me.GetReplicaX().Select(&versions, query, args...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed get mobile session metadata")
|
||||
}
|
||||
return versions, nil
|
||||
}
|
||||
|
||||
func (me SqlSessionStore) GetSessionsExpired(thresholdMillis int64, mobileOnly bool, unnotifiedOnly bool) ([]*model.Session, error) {
|
||||
now := model.GetMillis()
|
||||
builder := me.getQueryBuilder().
|
||||
|
||||
Ссылка в новой задаче
Block a user