@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.

Consolidate User Profile loading

Summary:
Introduce `PhabricatorUserQuery::attachProfilesForUsers()` for batch attachment of user profiles (for a future diff)
Introduce `PhabricatorUser::loadUserProfile()` to load attached user profiles (or load them on their own, if no one is attached).

USed them in code

Test Plan:
verified that use sites did not break

- Uploaded user profile image for bots
- changed my own profile image and blurb
- looked a lot at my own profile

Reviewers: epriestley, btrahan, chad

Reviewed By: epriestley

CC: aran, Korvin

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

authored by

Anh Nhan Nguyen and committed by
epriestley
b0e9371a 1a48c7ac

+92 -21
+48
src/applications/people/PhabricatorPeopleQuery.php
··· 8 8 private $ids; 9 9 10 10 private $needPrimaryEmail; 11 + private $needProfile; 12 + private $needProfileImage; 11 13 12 14 public function withIds(array $ids) { 13 15 $this->ids = $ids; ··· 32 34 33 35 public function needPrimaryEmail($need) { 34 36 $this->needPrimaryEmail = $need; 37 + return $this; 38 + } 39 + 40 + public function needProfile($need) { 41 + $this->needProfile = $need; 42 + return $this; 43 + } 44 + 45 + public function needProfileImage($need) { 46 + $this->needProfileImage = $need; 35 47 return $this; 36 48 } 37 49 ··· 56 68 } 57 69 58 70 $users = $table->loadAllFromArray($data); 71 + 72 + if ($this->needProfile) { 73 + $user_list = mpull($users, null, 'getPHID'); 74 + $profiles = new PhabricatorUserProfile(); 75 + $profiles = $profiles->loadAllWhere('userPHID IN (%Ls)', 76 + array_keys($user_list)); 77 + 78 + $profiles = mpull($profiles, null, 'getUserPHID'); 79 + foreach ($user_list as $user_phid => $user) { 80 + $profile = idx($profiles, $user_phid); 81 + if (!$profile) { 82 + $profile = new PhabricatorUserProfile(); 83 + $profile->setUserPHID($user_phid); 84 + } 85 + 86 + $user->attachUserProfile($profile); 87 + } 88 + } 89 + 90 + if ($this->needProfileImage) { 91 + // Change this once we migrate this to CursorPagedPolicyAwareQuery 92 + $files = id(new PhabricatorFile()) 93 + ->loadAllWhere('phid IN (%Ls)', mpull($users, 'getProfileImagePHID')); 94 + $files = mpull($files, null, 'getPHID'); 95 + foreach ($users as $user) { 96 + $image_phid = $user->getProfileImagePHID(); 97 + if (isset($files[$image_phid])) { 98 + $profile_image_uri = $files[$image_phid]->getBestURI(); 99 + } else { 100 + $profile_image_uri = PhabricatorUser::getDefaultProfileImageURI(); 101 + } 102 + $user->attachProfileImageURI($profile_image_uri); 103 + } 104 + } 105 + 59 106 return $users; 60 107 } 61 108 ··· 105 152 106 153 return $this->formatWhereClause($where); 107 154 } 155 + 108 156 }
+2 -6
src/applications/people/controller/PhabricatorPeopleEditController.php
··· 715 715 $request = $this->getRequest(); 716 716 $admin = $request->getUser(); 717 717 718 - $profile = id(new PhabricatorUserProfile())->loadOneWhere( 719 - 'userPHID = %s', 720 - $user->getPHID()); 721 - if (!$profile) { 722 - $profile = new PhabricatorUserProfile(); 723 - $profile->setUserPHID($user->getPHID()); 718 + $profile = $user->loadUserProfile(); 719 + if (!$profile->getID()) { 724 720 $profile->setTitle(''); 725 721 $profile->setBlurb(''); 726 722 }
+1 -6
src/applications/people/controller/PhabricatorPeopleProfileController.php
··· 52 52 53 53 require_celerity_resource('phabricator-profile-css'); 54 54 55 - $profile = id(new PhabricatorUserProfile())->loadOneWhere( 56 - 'userPHID = %s', 57 - $user->getPHID()); 58 - if (!$profile) { 59 - $profile = new PhabricatorUserProfile(); 60 - } 55 + $profile = $user->loadUserProfile(); 61 56 $username = phutil_escape_uri($user->getUserName()); 62 57 63 58 $menu = new PhabricatorMenuView();
+40 -2
src/applications/people/storage/PhabricatorUser.php
··· 25 25 protected $isAdmin = 0; 26 26 protected $isDisabled = 0; 27 27 28 + private $profileImage = null; 29 + private $profile = null; 30 + private $status = null; 28 31 private $preferences = null; 29 32 private $omnipotent = false; 30 33 ··· 409 412 return $uri->alter('email', $email->getAddress()); 410 413 } 411 414 415 + public function attachUserProfile(PhabricatorUserProfile $profile) { 416 + $this->profile = $profile; 417 + return $this; 418 + } 419 + 420 + public function loadUserProfile() { 421 + if ($this->profile) { 422 + return $this->profile; 423 + } 424 + 425 + $profile_dao = new PhabricatorUserProfile(); 426 + $this->profile = $profile_dao->loadOneWhere('userPHID = %s', 427 + $this->getPHID()); 428 + 429 + if (!$this->profile) { 430 + $profile_dao->setUserPHID($this->getPHID()); 431 + $this->profile = $profile_dao; 432 + } 433 + 434 + return $this->profile; 435 + } 436 + 412 437 public function loadPrimaryEmailAddress() { 413 438 $email = $this->loadPrimaryEmail(); 414 439 if (!$email) { ··· 629 654 return celerity_get_resource_uri('/rsrc/image/avatar.png'); 630 655 } 631 656 657 + public function attachProfileImageURI($uri) { 658 + $this->profileImage = $uri; 659 + return $this; 660 + } 661 + 632 662 public function loadProfileImageURI() { 663 + if ($this->profileImage) { 664 + return $this->profileImage; 665 + } 666 + 633 667 $src_phid = $this->getProfileImagePHID(); 634 668 635 669 if ($src_phid) { 636 670 $file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid); 637 671 if ($file) { 638 - return $file->getBestURI(); 672 + $this->profileImage = $file->getBestURI(); 639 673 } 640 674 } 641 675 642 - return self::getDefaultProfileImageURI(); 676 + if (!$this->profileImage) { 677 + $this->profileImage = self::getDefaultProfileImageURI(); 678 + } 679 + 680 + return $this->profileImage; 643 681 } 644 682 645 683 public function getFullName() {
+1 -7
src/applications/settings/panel/PhabricatorSettingsPanelProfile.php
··· 18 18 public function processRequest(AphrontRequest $request) { 19 19 $user = $request->getUser(); 20 20 21 - $profile = id(new PhabricatorUserProfile())->loadOneWhere( 22 - 'userPHID = %s', 23 - $user->getPHID()); 24 - if (!$profile) { 25 - $profile = new PhabricatorUserProfile(); 26 - $profile->setUserPHID($user->getPHID()); 27 - } 21 + $profile = $user->loadUserProfile(); 28 22 29 23 $supported_formats = PhabricatorFile::getTransformableImageFormats(); 30 24