@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 README content for repositories

Summary:
Ref T11954. Especially with higher-latency file stores like S3, we can spend a lot of time reading README data and then pulling it out of file storage.

Instead, cache it.

Test Plan: Browsed a repostory with a README, saw faster pages.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11954

Differential Revision: https://secure.phabricator.com/D17002

+43 -24
+43 -24
src/applications/diffusion/controller/DiffusionController.php
··· 340 340 341 341 $drequest = $this->getDiffusionRequest(); 342 342 $viewer = $this->getViewer(); 343 + $repository = $drequest->getRepository(); 344 + $repository_phid = $repository->getPHID(); 345 + $stable_commit = $drequest->getStableCommit(); 343 346 344 - try { 345 - $result = $this->callConduitWithDiffusionRequest( 346 - 'diffusion.filecontentquery', 347 - array( 348 - 'path' => $readme_path, 349 - 'commit' => $drequest->getStableCommit(), 350 - )); 351 - } catch (Exception $ex) { 352 - return null; 353 - } 347 + $cache = PhabricatorCaches::getMutableStructureCache(); 348 + $cache_key = "diffusion". 349 + ".repository({$repository_phid})". 350 + ".commit({$stable_commit})". 351 + ".readme({$readme_path})"; 352 + 353 + $readme_cache = $cache->getKey($cache_key); 354 + if (!$readme_cache) { 355 + try { 356 + $result = $this->callConduitWithDiffusionRequest( 357 + 'diffusion.filecontentquery', 358 + array( 359 + 'path' => $readme_path, 360 + 'commit' => $drequest->getStableCommit(), 361 + )); 362 + } catch (Exception $ex) { 363 + return null; 364 + } 365 + 366 + $file_phid = $result['filePHID']; 367 + if (!$file_phid) { 368 + return null; 369 + } 370 + 371 + $file = id(new PhabricatorFileQuery()) 372 + ->setViewer($viewer) 373 + ->withPHIDs(array($file_phid)) 374 + ->executeOne(); 375 + if (!$file) { 376 + return null; 377 + } 378 + 379 + $corpus = $file->loadFileData(); 354 380 355 - $file_phid = $result['filePHID']; 356 - if (!$file_phid) { 357 - return null; 358 - } 381 + $readme_cache = array( 382 + 'corpus' => $corpus, 383 + ); 359 384 360 - $file = id(new PhabricatorFileQuery()) 361 - ->setViewer($viewer) 362 - ->withPHIDs(array($file_phid)) 363 - ->executeOne(); 364 - if (!$file) { 365 - return null; 385 + $cache->setKey($cache_key, $readme_cache); 366 386 } 367 387 368 - $corpus = $file->loadFileData(); 369 - 370 - if (!strlen($corpus)) { 388 + $readme_corpus = $readme_cache['corpus']; 389 + if (!strlen($readme_corpus)) { 371 390 return null; 372 391 } 373 392 374 393 return id(new DiffusionReadmeView()) 375 394 ->setUser($this->getViewer()) 376 395 ->setPath($readme_path) 377 - ->setContent($corpus); 396 + ->setContent($readme_corpus); 378 397 } 379 398 380 399 }