Differential D16048 Diff 38616 src/applications/people/cache/PhabricatorUserPreferencesCacheType.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/people/cache/PhabricatorUserPreferencesCacheType.php
| Show All 18 Lines | final class PhabricatorUserPreferencesCacheType | ||||
| public function getValueFromStorage($value) { | public function getValueFromStorage($value) { | ||||
| return phutil_json_decode($value); | return phutil_json_decode($value); | ||||
| } | } | ||||
| public function newValueForUsers($key, array $users) { | public function newValueForUsers($key, array $users) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $user_phids = mpull($users, 'getPHID'); | $users = mpull($users, null, 'getPHID'); | ||||
| $user_phids = array_keys($users); | |||||
| $preferences = id(new PhabricatorUserPreferencesQuery()) | $preferences = id(new PhabricatorUserPreferencesQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withUserPHIDs($user_phids) | ->withUserPHIDs($user_phids) | ||||
| ->execute(); | ->execute(); | ||||
| $settings = mpull($preferences, 'getPreferences', 'getUserPHID'); | $all_settings = PhabricatorSetting::getAllSettings(); | ||||
| $settings = array(); | |||||
| foreach ($preferences as $preference) { | |||||
| $user_phid = $preference->getUserPHID(); | |||||
| foreach ($all_settings as $key => $setting) { | |||||
| $value = $preference->getSettingValue($key); | |||||
| // As an optimization, we omit the value from the cache if it is | |||||
| // exactly the same as the hardcoded default. | |||||
| $default_value = id(clone $setting) | |||||
| ->setViewer($users[$user_phid]) | |||||
| ->getSettingDefaultValue(); | |||||
| if ($value === $default_value) { | |||||
| continue; | |||||
| } | |||||
| $settings[$user_phid][$key] = $value; | |||||
| } | |||||
| } | |||||
| $results = array(); | $results = array(); | ||||
| foreach ($user_phids as $user_phid) { | foreach ($user_phids as $user_phid) { | ||||
| $value = idx($settings, $user_phid, array()); | $value = idx($settings, $user_phid, array()); | ||||
| $results[$user_phid] = phutil_json_encode($value); | $results[$user_phid] = phutil_json_encode($value); | ||||
| } | } | ||||
| return $results; | return $results; | ||||
| } | } | ||||
| } | } | ||||