mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 08:42:41 +01:00
Bulk load builtin project default profile images
Summary: Depends on D19221. Ref T13106. When we fall back to default profile images for projects, bulk load them instead of doing individual queries. Test Plan: Saw local task drop from 199 queries to 151 queries with the same actual outcome. Saw custom and default profile images on the project list page. Maniphest Tasks: T13106 Differential Revision: https://secure.phabricator.com/D19222
This commit is contained in:
parent
403dd62936
commit
49e6358fce
1 changed files with 53 additions and 13 deletions
|
@ -357,29 +357,69 @@ final class PhabricatorProjectQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function didFilterPage(array $projects) {
|
protected function didFilterPage(array $projects) {
|
||||||
|
$viewer = $this->getViewer();
|
||||||
|
|
||||||
if ($this->needImages) {
|
if ($this->needImages) {
|
||||||
$file_phids = mpull($projects, 'getProfileImagePHID');
|
$need_images = $projects;
|
||||||
$file_phids = array_filter($file_phids);
|
|
||||||
|
// First, try to load custom profile images for any projects with custom
|
||||||
|
// images.
|
||||||
|
$file_phids = array();
|
||||||
|
foreach ($need_images as $key => $project) {
|
||||||
|
$image_phid = $project->getProfileImagePHID();
|
||||||
|
if ($image_phid) {
|
||||||
|
$file_phids[$key] = $image_phid;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($file_phids) {
|
if ($file_phids) {
|
||||||
$files = id(new PhabricatorFileQuery())
|
$files = id(new PhabricatorFileQuery())
|
||||||
->setParentQuery($this)
|
->setParentQuery($this)
|
||||||
->setViewer($this->getViewer())
|
->setViewer($viewer)
|
||||||
->withPHIDs($file_phids)
|
->withPHIDs($file_phids)
|
||||||
->execute();
|
->execute();
|
||||||
$files = mpull($files, null, 'getPHID');
|
$files = mpull($files, null, 'getPHID');
|
||||||
} else {
|
|
||||||
$files = array();
|
foreach ($file_phids as $key => $image_phid) {
|
||||||
|
$file = idx($files, $image_phid);
|
||||||
|
if (!$file) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$need_images[$key]->attachProfileImageFile($file);
|
||||||
|
unset($need_images[$key]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($projects as $project) {
|
// For projects with default images, or projects where the custom image
|
||||||
$file = idx($files, $project->getProfileImagePHID());
|
// failed to load, load a builtin image.
|
||||||
if (!$file) {
|
if ($need_images) {
|
||||||
$builtin = PhabricatorProjectIconSet::getIconImage(
|
$builtin_map = array();
|
||||||
$project->getIcon());
|
$builtins = array();
|
||||||
$file = PhabricatorFile::loadBuiltin($this->getViewer(),
|
foreach ($need_images as $key => $project) {
|
||||||
'projects/'.$builtin);
|
$icon = $project->getIcon();
|
||||||
|
|
||||||
|
$builtin_name = PhabricatorProjectIconSet::getIconImage($icon);
|
||||||
|
$builtin_name = 'projects/'.$builtin_name;
|
||||||
|
|
||||||
|
$builtin = id(new PhabricatorFilesOnDiskBuiltinFile())
|
||||||
|
->setName($builtin_name);
|
||||||
|
|
||||||
|
$builtin_key = $builtin->getBuiltinFileKey();
|
||||||
|
|
||||||
|
$builtins[] = $builtin;
|
||||||
|
$builtin_map[$key] = $builtin_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
$builtin_files = PhabricatorFile::loadBuiltins(
|
||||||
|
$viewer,
|
||||||
|
$builtins);
|
||||||
|
|
||||||
|
foreach ($need_images as $key => $project) {
|
||||||
|
$builtin_key = $builtin_map[$key];
|
||||||
|
$builtin_file = $builtin_files[$builtin_key];
|
||||||
|
$project->attachProfileImageFile($builtin_file);
|
||||||
}
|
}
|
||||||
$project->attachProfileImageFile($file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue