mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 07:12:41 +01:00
Simplify user cache management of data forms
Summary: Ref T4103. Ref T10078. We currently have separate "usable" and "raw" values, but can simplify this by making `newValueForUsers()` return the raw value. Test Plan: Ran unit tests; browsed around; dropped caches and browsed around. Reviewers: chad Reviewed By: chad Maniphest Tasks: T4103, T10078 Differential Revision: https://secure.phabricator.com/D16043
This commit is contained in:
parent
c1331bcb7b
commit
5ba7938d54
7 changed files with 19 additions and 23 deletions
|
@ -27,11 +27,7 @@ abstract class PhabricatorUserCacheType extends Phobject {
|
|||
}
|
||||
|
||||
public function getValueFromStorage($value) {
|
||||
return phutil_json_decode($value);
|
||||
}
|
||||
|
||||
public function getValueForStorage($value) {
|
||||
return phutil_json_encode($value);
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function newValueForUsers($key, array $users) {
|
||||
|
|
|
@ -21,10 +21,6 @@ final class PhabricatorUserMessageCountCacheType
|
|||
return (int)$value;
|
||||
}
|
||||
|
||||
public function getValueForStorage($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function newValueForUsers($key, array $users) {
|
||||
if (!$users) {
|
||||
return array();
|
||||
|
|
|
@ -21,10 +21,6 @@ final class PhabricatorUserNotificationCountCacheType
|
|||
return (int)$value;
|
||||
}
|
||||
|
||||
public function getValueForStorage($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function newValueForUsers($key, array $users) {
|
||||
if (!$users) {
|
||||
return array();
|
||||
|
|
|
@ -17,6 +17,10 @@ final class PhabricatorUserPreferencesCacheType
|
|||
return ($key === self::KEY_PREFERENCES);
|
||||
}
|
||||
|
||||
public function getValueFromStorage($value) {
|
||||
return phutil_json_decode($value);
|
||||
}
|
||||
|
||||
public function newValueForUsers($key, array $users) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
|
@ -27,9 +31,15 @@ final class PhabricatorUserPreferencesCacheType
|
|||
->withUserPHIDs($user_phids)
|
||||
->execute();
|
||||
|
||||
$empty = array_fill_keys($user_phids, array());
|
||||
$settings = mpull($preferences, 'getPreferences', 'getUserPHID');
|
||||
|
||||
return mpull($preferences, 'getPreferences', 'getUserPHID') + $empty;
|
||||
$results = array();
|
||||
foreach ($user_phids as $user_phid) {
|
||||
$value = idx($settings, $user_phid, array());
|
||||
$results[$user_phid] = phutil_json_encode($value);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,6 +17,10 @@ final class PhabricatorUserProfileImageCacheType
|
|||
return ($key === self::KEY_URI);
|
||||
}
|
||||
|
||||
public function getDefaultValue() {
|
||||
return PhabricatorUser::getDefaultProfileImageURI();
|
||||
}
|
||||
|
||||
public function newValueForUsers($key, array $users) {
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
|
@ -55,10 +59,6 @@ final class PhabricatorUserProfileImageCacheType
|
|||
return end($parts);
|
||||
}
|
||||
|
||||
public function getValueForStorage($value) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function shouldValidateRawCacheData() {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -544,8 +544,7 @@ final class PhabricatorPeopleQuery
|
|||
|
||||
$data = $type->newValueForUsers($cache_key, $need_users);
|
||||
|
||||
foreach ($data as $user_phid => $value) {
|
||||
$raw_value = $type->getValueForStorage($value);
|
||||
foreach ($data as $user_phid => $raw_value) {
|
||||
$data[$user_phid] = $raw_value;
|
||||
$writes[] = array(
|
||||
'userPHID' => $user_phid,
|
||||
|
|
|
@ -1463,8 +1463,7 @@ final class PhabricatorUser
|
|||
if ($user_phid) {
|
||||
$map = $type->newValueForUsers($key, array($this));
|
||||
if (array_key_exists($user_phid, $map)) {
|
||||
$usable_value = $map[$user_phid];
|
||||
$raw_value = $type->getValueForStorage($usable_value);
|
||||
$raw_value = $map[$user_phid];
|
||||
$usable_value = $type->getValueFromStorage($raw_value);
|
||||
|
||||
$this->rawCacheData[$key] = $raw_value;
|
||||
|
|
Loading…
Reference in a new issue