@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+18 -9
+18 -9
src/applications/spaces/query/PhabricatorSpacesNamespaceQuery.php
··· 5 5 6 6 const KEY_ALL = 'spaces.all'; 7 7 const KEY_DEFAULT = 'spaces.default'; 8 + const KEY_VIEWER = 'spaces.viewer'; 8 9 9 10 private $ids; 10 11 private $phids; ··· 141 142 } 142 143 143 144 public static function getViewerSpaces(PhabricatorUser $viewer) { 144 - $spaces = self::getAllSpaces(); 145 + $cache = PhabricatorCaches::getRequestCache(); 146 + $cache_key = self::KEY_VIEWER.'('.$viewer->getPHID().')'; 145 147 146 - $result = array(); 147 - foreach ($spaces as $key => $space) { 148 - $can_see = PhabricatorPolicyFilter::hasCapability( 149 - $viewer, 150 - $space, 151 - PhabricatorPolicyCapability::CAN_VIEW); 152 - if ($can_see) { 153 - $result[$key] = $space; 148 + $result = $cache->getKey($cache_key); 149 + if ($result === null) { 150 + $spaces = self::getAllSpaces(); 151 + 152 + $result = array(); 153 + foreach ($spaces as $key => $space) { 154 + $can_see = PhabricatorPolicyFilter::hasCapability( 155 + $viewer, 156 + $space, 157 + PhabricatorPolicyCapability::CAN_VIEW); 158 + if ($can_see) { 159 + $result[$key] = $space; 160 + } 154 161 } 162 + 163 + $cache->setKey($cache_key, $result); 155 164 } 156 165 157 166 return $result;