/
[optimization] Reduce DB queries to "UserPersistentSessionData" table [5.2.2-B2]
[optimization] Reduce DB queries to "UserPersistentSessionData" table [5.2.2-B2]
There are 3 types of user setting storage in In-Portal:
Place | Duration | Pros | Cons |
---|---|---|---|
user record in "Users" table | infinity |
|
|
records in "UserSessionData" | session (1 hour usually) |
| |
records in "UserPersistentSessionData" | infinity |
|
The "UserPersistentSessionData" table could be used an extension for "Users" table for a particular user, where unlimited number of records could be added.
The "UserPersistentSessionData" table is used mostly for storing Admin Console grid settings (per page, column sorting, filters). Thanks to "fallback to default user setting" feature administrator can configure all Admin Console settings for default user (usually "root", but can be specified in the "User ID for Default Persistent Settings" setting from "Configuration > Users > General" section) and all new administrators then will inherit these settings automatically.
The setting inheritance has 2 issues in it's implementation:
- when default user is logged-in it inherits missing settings from himself, which basically performs extra database query with no useful result
- when non-default user is logged-in and default user doesn't have setting for fallback, then we perform single database query for each setting
Solution
- add protected "\SessionStorage::$defaultPersistentVars" property of "array" type
- in the "\SessionStorage::LoadPersistentVars" method:
- get "DefaultSettingsUserId" system setting value with fallback to "USER_ROOT" constant value
- if default user isn't the same as current user, then store persistent settings of above retrieved user in the "\SessionStorage::$defaultPersistentVars" property
- in the "\SessionStorage::RecallPersistentVar" method, when handling "$default == ALLOW_DEFAULT_SETTINGS" logic branch:
- if "$var_name" key exists in "\SessionStorage::$defaultPersistentVars" array, then store it's value under current user using "\SessionStorage::StorePersistentVar" call
- otherwise set "false" into "$this->PersistentVars[$var_name]" and "return false"
- confirm, that these cases work & no more, than 2 SELECT happens from "UserPersistentSessionData" table:
- non-root user has a persistent setting
- non-root user doesn't have a persistent setting
- root user has a persistent setting
- root user doesn't have a persistent setting