diff --git a/src/applications/auth/engine/PhabricatorAuthSessionEngine.php b/src/applications/auth/engine/PhabricatorAuthSessionEngine.php --- a/src/applications/auth/engine/PhabricatorAuthSessionEngine.php +++ b/src/applications/auth/engine/PhabricatorAuthSessionEngine.php @@ -163,6 +163,7 @@ $user = $user_table->loadFromArray($info); $user->attachRawCacheData($cache_raw); + $user->setAllowInlineCacheGeneration(true); switch ($session_type) { case PhabricatorAuthSession::TYPE_WEB: diff --git a/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php b/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php --- a/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php +++ b/src/applications/metamta/query/PhabricatorMetaMTAActorQuery.php @@ -59,6 +59,7 @@ $users = id(new PhabricatorPeopleQuery()) ->setViewer($this->getViewer()) ->withPHIDs($phids) + ->needUserSettings(true) ->execute(); $users = mpull($users, null, 'getPHID'); diff --git a/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php b/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php --- a/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php +++ b/src/applications/metamta/replyhandler/PhabricatorMailReplyHandler.php @@ -337,9 +337,12 @@ $all_phids = array_merge($to, $cc); if ($all_phids) { + // We need user settings here because we'll check translations later + // when generating mail. $users = id(new PhabricatorPeopleQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) ->withPHIDs($all_phids) + ->needUserSettings(true) ->execute(); $users = mpull($users, null, 'getPHID'); diff --git a/src/applications/people/query/PhabricatorPeopleQuery.php b/src/applications/people/query/PhabricatorPeopleQuery.php --- a/src/applications/people/query/PhabricatorPeopleQuery.php +++ b/src/applications/people/query/PhabricatorPeopleQuery.php @@ -528,9 +528,6 @@ $cache_data = igroup($cache_data, 'userPHID'); foreach ($user_map as $user_phid => $user) { $raw_rows = idx($cache_data, $user_phid, array()); - if (!$raw_rows) { - continue; - } $raw_data = ipull($raw_rows, 'cacheData', 'cacheKey'); foreach ($keys as $key) { diff --git a/src/applications/people/storage/PhabricatorUser.php b/src/applications/people/storage/PhabricatorUser.php --- a/src/applications/people/storage/PhabricatorUser.php +++ b/src/applications/people/storage/PhabricatorUser.php @@ -65,6 +65,7 @@ private $settingCacheKeys = array(); private $settingCache = array(); + private $allowInlineCacheGeneration; protected function readField($field) { switch ($field) { @@ -483,7 +484,11 @@ } $settings_key = PhabricatorUserPreferencesCacheType::KEY_PREFERENCES; - $settings = $this->requireCacheData($settings_key); + if ($this->getPHID()) { + $settings = $this->requireCacheData($settings_key); + } else { + $settings = array(); + } $defaults = PhabricatorSetting::getAllEnabledSettings($this); @@ -1486,6 +1491,10 @@ return $this; } + public function setAllowInlineCacheGeneration($allow_cache_generation) { + $this->allowInlineCacheGeneration = $allow_cache_generation; + return $this; + } /** * @task cache @@ -1506,6 +1515,12 @@ return $usable_value; } + // By default, we throw if a cache isn't available. This is consistent + // with the standard `needX()` + `attachX()` + `getX()` interaction. + if (!$this->allowInlineCacheGeneration) { + throw new PhabricatorDataNotAttachedException($this); + } + $usable_value = $type->getDefaultValue(); $user_phid = $this->getPHID(); diff --git a/src/infrastructure/testing/PhabricatorTestCase.php b/src/infrastructure/testing/PhabricatorTestCase.php --- a/src/infrastructure/testing/PhabricatorTestCase.php +++ b/src/infrastructure/testing/PhabricatorTestCase.php @@ -202,6 +202,14 @@ $editor->setActor($user); $editor->createNewUser($user, $email); + // When creating a new test user, we prefill their setting cache as empty. + // This is a little more efficient than doing a query to load the empty + // settings. + $user->attachRawCacheData( + array( + PhabricatorUserPreferencesCacheType::KEY_PREFERENCES => '[]', + )); + return $user; }