Page MenuHomePhabricator

D16112.diff
No OneTemporary

D16112.diff

diff --git a/src/applications/people/cache/PhabricatorUserPreferencesCacheType.php b/src/applications/people/cache/PhabricatorUserPreferencesCacheType.php
--- a/src/applications/people/cache/PhabricatorUserPreferencesCacheType.php
+++ b/src/applications/people/cache/PhabricatorUserPreferencesCacheType.php
@@ -31,19 +31,39 @@
->setViewer($viewer)
->withUserPHIDs($user_phids)
->execute();
+ $preferences = mpull($preferences, null, 'getUserPHID');
+
+ // If some users don't have settings of their own yet, we need to load
+ // the global default settings to generate caches for them.
+ if (count($preferences) < count($user_phids)) {
+ $global = id(new PhabricatorUserPreferencesQuery())
+ ->setViewer($viewer)
+ ->withBuiltinKeys(
+ array(
+ PhabricatorUserPreferences::BUILTIN_GLOBAL_DEFAULT,
+ ))
+ ->executeOne();
+ } else {
+ $global = null;
+ }
$all_settings = PhabricatorSetting::getAllSettings();
$settings = array();
- foreach ($preferences as $preference) {
- $user_phid = $preference->getUserPHID();
+ foreach ($users as $user_phid => $user) {
+ $preference = idx($preferences, $user_phid, $global);
+
+ if (!$preference) {
+ continue;
+ }
+
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])
+ ->setViewer($user)
->getSettingDefaultValue();
if ($value === $default_value) {
continue;
diff --git a/src/applications/settings/storage/PhabricatorUserPreferences.php b/src/applications/settings/storage/PhabricatorUserPreferences.php
--- a/src/applications/settings/storage/PhabricatorUserPreferences.php
+++ b/src/applications/settings/storage/PhabricatorUserPreferences.php
@@ -130,9 +130,23 @@
return $preferences;
}
- return id(new self())
+ $preferences = id(new self())
->setUserPHID($user->getPHID())
->attachUser($user);
+
+ $global = id(new PhabricatorUserPreferencesQuery())
+ ->setViewer($user)
+ ->withBuiltinKeys(
+ array(
+ self::BUILTIN_GLOBAL_DEFAULT,
+ ))
+ ->executeOne();
+
+ if ($global) {
+ $preferences->attachDefaultSettings($global);
+ }
+
+ return $preferences;
}
public function newTransaction($key, $value) {

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 9:20 AM (20 h, 17 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6910063
Default Alt Text
D16112.diff (2 KB)

Event Timeline