1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 21:02:41 +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:
Nicholas Harper 2011-10-07 15:03:00 -07:00
parent c3709c56fc
commit 872ac17dbc
3 changed files with 30 additions and 23 deletions

View file

@ -41,15 +41,25 @@ class PhabricatorUser extends PhabricatorUserDAO {
private $preferences = null; private $preferences = null;
public function getProfileImagePHID() { protected function readField($field) {
return nonempty( if ($field === 'profileImagePHID') {
$this->profileImagePHID, return nonempty(
PhabricatorEnv::getEnvConfig('user.default-profile-image-phid')); $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() { public function getConfiguration() {
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,
self::CONFIG_PARTIAL_OBJECTS => true,
) + parent::getConfiguration(); ) + parent::getConfiguration();
} }
@ -76,8 +86,8 @@ class PhabricatorUser extends PhabricatorUserDAO {
} }
public function save() { public function save() {
if (!$this->conduitCertificate) { if (!$this->getConduitCertificate()) {
$this->conduitCertificate = $this->generateConduitCertificate(); $this->setConduitCertificate($this->generateConduitCertificate());
} }
$result = parent::save(); $result = parent::save();
@ -169,7 +179,7 @@ class PhabricatorUser extends PhabricatorUserDAO {
private function generateToken($epoch, $frequency, $key, $len) { private function generateToken($epoch, $frequency, $key, $len) {
$time_block = floor($epoch / $frequency); $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); return substr(sha1($vec), 0, $len);
} }
@ -343,11 +353,4 @@ class PhabricatorUser extends PhabricatorUserDAO {
return $preferences; 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());
}
} }

View file

@ -73,15 +73,21 @@ class PhabricatorTypeaheadCommonDatasourceController
} }
if ($need_users) { if ($need_users) {
$columns = array(
'isSystemAgent',
'isDisabled',
'userName',
'realName',
'phid');
if ($query) { if ($query) {
// TODO: We probably need to split last names here. Workaround until // TODO: We probably need to split last names here. Workaround until
// we get that up and running is to not enable server-side datasources. // 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 %>)', '(userName LIKE %> OR realName LIKE %>)',
$query, $query,
$query); $query);
} else { } else {
$users = id(new PhabricatorUser())->loadAll(); $users = id(new PhabricatorUser())->loadColumns($columns);
} }
foreach ($users as $user) { foreach ($users as $user) {
if (!$need_all_users) { if (!$need_all_users) {

View file

@ -360,14 +360,12 @@ abstract class LiskDAO {
/** /**
* Loads all objects, but only fetches the specified columns. * Loads all objects, but only fetches the specified columns.
* *
* @param string Column name. * @param array Array of canonical column names as strings
* @param ... More column names. * @return dict Dictionary of all objects, keyed by ID.
* @return dict Dictionary of all objects, keyed by ID.
* *
* @task load * @task load
*/ */
public function loadColumns($column1/*, $column2, ... */) { public function loadColumns(array $columns) {
$columns = func_get_args();
return $this->loadColumnsWhere($columns, '1 = 1'); return $this->loadColumnsWhere($columns, '1 = 1');
} }
@ -406,7 +404,7 @@ abstract class LiskDAO {
* *
* @task load * @task load
*/ */
public function loadColumnsWhere($columns, $pattern/*, $arg, $arg, ... */) { public function loadColumnsWhere(array $columns, $pattern/*, $args... */) {
if (!$this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) { if (!$this->getConfigOption(self::CONFIG_PARTIAL_OBJECTS)) {
throw new BadMethodCallException( throw new BadMethodCallException(
"This class does not support partial objects."); "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'); $connection = $this->establishConnection('r');
$lock_clause = ''; $lock_clause = '';