mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-19 20:10:55 +01:00
Cache viewer spaces
Summary: Ref T8575. Although we cache spaces as a whole, we don't cache viewer spaces. This can still do a lot of work if they have complex policies. Instead, cache them in the request cache. Test Plan: Saw this account for 37% of a page in produciton (303ms on on 835ms). Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8575 Differential Revision: https://secure.phabricator.com/D13324
This commit is contained in:
parent
af8ad58e6b
commit
984976ce20
1 changed files with 18 additions and 9 deletions
|
@ -5,6 +5,7 @@ final class PhabricatorSpacesNamespaceQuery
|
|||
|
||||
const KEY_ALL = 'spaces.all';
|
||||
const KEY_DEFAULT = 'spaces.default';
|
||||
const KEY_VIEWER = 'spaces.viewer';
|
||||
|
||||
private $ids;
|
||||
private $phids;
|
||||
|
@ -141,17 +142,25 @@ final class PhabricatorSpacesNamespaceQuery
|
|||
}
|
||||
|
||||
public static function getViewerSpaces(PhabricatorUser $viewer) {
|
||||
$spaces = self::getAllSpaces();
|
||||
$cache = PhabricatorCaches::getRequestCache();
|
||||
$cache_key = self::KEY_VIEWER.'('.$viewer->getPHID().')';
|
||||
|
||||
$result = array();
|
||||
foreach ($spaces as $key => $space) {
|
||||
$can_see = PhabricatorPolicyFilter::hasCapability(
|
||||
$viewer,
|
||||
$space,
|
||||
PhabricatorPolicyCapability::CAN_VIEW);
|
||||
if ($can_see) {
|
||||
$result[$key] = $space;
|
||||
$result = $cache->getKey($cache_key);
|
||||
if ($result === null) {
|
||||
$spaces = self::getAllSpaces();
|
||||
|
||||
$result = array();
|
||||
foreach ($spaces as $key => $space) {
|
||||
$can_see = PhabricatorPolicyFilter::hasCapability(
|
||||
$viewer,
|
||||
$space,
|
||||
PhabricatorPolicyCapability::CAN_VIEW);
|
||||
if ($can_see) {
|
||||
$result[$key] = $space;
|
||||
}
|
||||
}
|
||||
|
||||
$cache->setKey($cache_key, $result);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
|
Loading…
Reference in a new issue