mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 20:40:56 +01:00
Selectively load columns for differential typeahead
Summary: Change the differential typeahead to only load columns that it needs. To do this, I also enabled partial objects for PhabricatorUser (and made necessary changes to support this). I also changed the functionality of Lisk's loadColumns to either accept columns as multiple string arguments or a single array of strings. Test Plan: With tokenizer.ondemand set to false, checked that the typeahead loaded and I can type multiple people's names. Set tokenizer.ondemand to true and tried again. In both cases, the typeahead worked. Reviewers: epriestley Reviewed By: epriestley CC: jungejason, aran, epriestley, nh Differential Revision: 990
This commit is contained in:
parent
c3709c56fc
commit
872ac17dbc
3 changed files with 30 additions and 23 deletions
|
@ -41,15 +41,25 @@ class PhabricatorUser extends PhabricatorUserDAO {
|
|||
|
||||
private $preferences = null;
|
||||
|
||||
public function getProfileImagePHID() {
|
||||
return nonempty(
|
||||
$this->profileImagePHID,
|
||||
PhabricatorEnv::getEnvConfig('user.default-profile-image-phid'));
|
||||
protected function readField($field) {
|
||||
if ($field === 'profileImagePHID') {
|
||||
return nonempty(
|
||||
$this->profileImagePHID,
|
||||
PhabricatorEnv::getEnvConfig('user.default-profile-image-phid'));
|
||||
}
|
||||
if ($field === 'timezoneIdentifier') {
|
||||
// If the user hasn't set one, guess the server's time.
|
||||
return nonempty(
|
||||
$this->timezoneIdentifier,
|
||||
date_default_timezone_get());
|
||||
}
|
||||
return parent::readField($field);
|
||||
}
|
||||
|
||||
public function getConfiguration() {
|
||||
return array(
|
||||
self::CONFIG_AUX_PHID => true,
|
||||
self::CONFIG_PARTIAL_OBJECTS => true,
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
||||
|
@ -76,8 +86,8 @@ class PhabricatorUser extends PhabricatorUserDAO {
|
|||
}
|
||||
|
||||
public function save() {
|
||||
if (!$this->conduitCertificate) {
|
||||
$this->conduitCertificate = $this->generateConduitCertificate();
|
||||
if (!$this->getConduitCertificate()) {
|
||||
$this->setConduitCertificate($this->generateConduitCertificate());
|
||||
}
|
||||
$result = parent::save();
|
||||
|
||||
|
@ -169,7 +179,7 @@ class PhabricatorUser extends PhabricatorUserDAO {
|
|||
|
||||
private function generateToken($epoch, $frequency, $key, $len) {
|
||||
$time_block = floor($epoch / $frequency);
|
||||
$vec = $this->getPHID().$this->passwordHash.$key.$time_block;
|
||||
$vec = $this->getPHID().$this->getPasswordHash().$key.$time_block;
|
||||
return substr(sha1($vec), 0, $len);
|
||||
}
|
||||
|
||||
|
@ -343,11 +353,4 @@ class PhabricatorUser extends PhabricatorUserDAO {
|
|||
return $preferences;
|
||||
}
|
||||
|
||||
public function getTimezoneIdentifier() {
|
||||
// If the user hasn't set one, guess the server's time.
|
||||
return nonempty(
|
||||
$this->timezoneIdentifier,
|
||||
date_default_timezone_get());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -73,15 +73,21 @@ class PhabricatorTypeaheadCommonDatasourceController
|
|||
}
|
||||
|
||||
if ($need_users) {
|
||||
$columns = array(
|
||||
'isSystemAgent',
|
||||
'isDisabled',
|
||||
'userName',
|
||||
'realName',
|
||||
'phid');
|
||||
if ($query) {
|
||||
// TODO: We probably need to split last names here. Workaround until
|
||||
// we get that up and running is to not enable server-side datasources.
|
||||
$users = id(new PhabricatorUser())->loadAllWhere(
|
||||
$users = id(new PhabricatorUser())->loadColumnsWhere($columns,
|
||||
'(userName LIKE %> OR realName LIKE %>)',
|
||||
$query,
|
||||
$query);
|
||||
} else {
|
||||
$users = id(new PhabricatorUser())->loadAll();
|
||||
$users = id(new PhabricatorUser())->loadColumns($columns);
|
||||
}
|
||||
foreach ($users as $user) {
|
||||
if (!$need_all_users) {
|
||||
|
|
|
@ -360,14 +360,12 @@ abstract class LiskDAO {
|
|||
/**
|
||||
* Loads all objects, but only fetches the specified columns.
|
||||
*
|
||||
* @param string Column name.
|
||||
* @param ... More column names.
|
||||
* @return dict Dictionary of all objects, keyed by ID.
|
||||
* @param array Array of canonical column names as strings
|
||||
* @return dict Dictionary of all objects, keyed by ID.
|
||||
*
|
||||
* @task load
|
||||
*/
|
||||
public function loadColumns($column1/*, $column2, ... */) {
|
||||
$columns = func_get_args();
|
||||
public function loadColumns(array $columns) {
|
||||
return $this->loadColumnsWhere($columns, '1 = 1');
|
||||
}
|
||||
|
||||
|
@ -406,7 +404,7 @@ abstract class LiskDAO {
|
|||
*
|
||||
* @task load
|
||||
*/
|
||||
public function loadColumnsWhere($columns, $pattern/*, $arg, $arg, ... */) {
|
||||
public function loadColumnsWhere(array $columns, $pattern/*, $args... */) {
|
||||
if (!$this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) {
|
||||
throw new BadMethodCallException(
|
||||
"This class does not support partial objects.");
|
||||
|
@ -452,7 +450,7 @@ abstract class LiskDAO {
|
|||
}
|
||||
|
||||
|
||||
protected function loadRawDataWhere($columns, $pattern/*, $arg, $arg ... */) {
|
||||
protected function loadRawDataWhere(array $columns, $pattern/*, $args... */) {
|
||||
$connection = $this->establishConnection('r');
|
||||
|
||||
$lock_clause = '';
|
||||
|
|
Loading…
Reference in a new issue