Continue cleaning up queries in the wake of changes to "%Q"

Summary: Depends on D19810. Ref T13217. Ref T13216. I mostly used `grep implode | grep OR` and `grep implode | grep AND` to find these -- not totally exhaustive but should be a big chunk of the callsites that are missing `%LO` / `%LA`.

Test Plan:
These are tricky to test exhaustively, but I made an attempt to hit most of them:

- Browsed Almanac interfaces.
- Created/browsed Calendar events.
- Enabled/disabled/showed the lock log.
- Browsed repositories.
- Loaded Facts UI.
- Poked at Multimeter.
- Used typeahead for users and projects.
- Browsed Phriction.
- Ran various fulltext searches.

Not sure these are reachable:

- All the lint stuff might be dead/unreachable/nonfunctional?

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: yelirekim

Maniphest Tasks: T13217, T13216

Differential Revision: https://secure.phabricator.com/D19814
This commit is contained in:
epriestley
2018-11-15 05:53:34 -08:00
parent 49483bdb48
commit 933462b487
15 changed files with 59 additions and 44 deletions

View File

@@ -121,7 +121,7 @@ final class AlmanacInterfaceQuery
$address->getAddress(), $address->getAddress(),
$address->getPort()); $address->getPort());
} }
$where[] = implode(' OR ', $parts); $where[] = qsprintf($conn, '%LO', $parts);
} }
return $where; return $where;

View File

@@ -444,8 +444,8 @@ final class PhabricatorCalendarEventQuery
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'%Q', '%LO',
implode(' OR ', $sql)); $sql);
} }
if ($this->isStub !== null) { if ($this->isStub !== null) {

View File

@@ -107,9 +107,9 @@ final class PhabricatorLockLogManagementWorkflow
} }
if (!$parts) { if (!$parts) {
$constraint = '1 = 1'; $constraint = qsprintf($conn, '1 = 1');
} else { } else {
$constraint = '('.implode(') AND (', $parts).')'; $constraint = qsprintf($conn, '%LA', $parts);
} }
$logs = $table->loadAllWhere( $logs = $table->loadAllWhere(

View File

@@ -229,9 +229,9 @@ final class DiffusionLintSaveRunner extends Phobject {
$this->conn, $this->conn,
'INSERT INTO %T 'INSERT INTO %T
(branchID, path, line, code, severity, name, description) (branchID, path, line, code, severity, name, description)
VALUES %Q', VALUES %LQ',
PhabricatorRepository::TABLE_LINTMESSAGE, PhabricatorRepository::TABLE_LINTMESSAGE,
implode(', ', $values)); $values);
} }
$this->conn->saveTransaction(); $this->conn->saveTransaction();
@@ -295,10 +295,10 @@ final class DiffusionLintSaveRunner extends Phobject {
} }
queryfx( queryfx(
$this->conn, $this->conn,
'UPDATE %T SET authorPHID = %s WHERE %Q', 'UPDATE %T SET authorPHID = %s WHERE %LO',
PhabricatorRepository::TABLE_LINTMESSAGE, PhabricatorRepository::TABLE_LINTMESSAGE,
$author, $author,
implode(' OR ', $where)); $where);
} }
$this->conn->saveTransaction(); $this->conn->saveTransaction();

View File

@@ -451,13 +451,13 @@ final class DiffusionBrowseQueryConduitAPIMethod
WHERE repositoryID = %d WHERE repositoryID = %d
AND parentID = %d AND parentID = %d
AND existed = 1 AND existed = 1
AND (%Q) AND (%LO)
ORDER BY pathName', ORDER BY pathName',
PhabricatorRepository::TABLE_FILESYSTEM, PhabricatorRepository::TABLE_FILESYSTEM,
PhabricatorRepository::TABLE_PATH, PhabricatorRepository::TABLE_PATH,
$repository->getID(), $repository->getID(),
$path_id, $path_id,
implode(' OR ', $sql)); $sql);
$loadable_commits = array(); $loadable_commits = array();
foreach ($browse as $key => $file) { foreach ($browse as $key => $file) {

View File

@@ -276,13 +276,13 @@ final class DiffusionLintController extends DiffusionController {
array_keys($branch), array_keys($branch),
$path->getPath()); $path->getPath());
if ($path->getExcluded()) { if ($path->getExcluded()) {
$where[] = 'NOT '.$condition; $where[] = qsprintf($conn, 'NOT %Q', $condition);
} else { } else {
$or[] = $condition; $or[] = $condition;
} }
} }
} }
$where[] = '('.implode(' OR ', $or).')'; $where[] = qsprintf($conn, '%LO', $or);
} }
return queryfx_all( return queryfx_all(
@@ -296,11 +296,11 @@ final class DiffusionLintController extends DiffusionController {
COUNT(DISTINCT path) AS files, COUNT(DISTINCT path) AS files,
COUNT(*) AS n COUNT(*) AS n
FROM %T FROM %T
WHERE %Q WHERE %LA
GROUP BY branchID, code GROUP BY branchID, code
ORDER BY n DESC', ORDER BY n DESC',
PhabricatorRepository::TABLE_LINTMESSAGE, PhabricatorRepository::TABLE_LINTMESSAGE,
implode(' AND ', $where)); $where);
} }
protected function buildActionView(DiffusionRequest $drequest) { protected function buildActionView(DiffusionRequest $drequest) {
@@ -526,10 +526,10 @@ final class DiffusionLintController extends DiffusionController {
$conn, $conn,
'SELECT * 'SELECT *
FROM %T FROM %T
WHERE %Q WHERE %LA
ORDER BY path, code, line LIMIT %d OFFSET %d', ORDER BY path, code, line LIMIT %d OFFSET %d',
PhabricatorRepository::TABLE_LINTMESSAGE, PhabricatorRepository::TABLE_LINTMESSAGE,
implode(' AND ', $where), $where,
$limit, $limit,
$offset); $offset);
} }

View File

@@ -81,10 +81,10 @@ final class DiffusionCachedResolveRefsQuery
$commits = queryfx_all( $commits = queryfx_all(
$conn_r, $conn_r,
'SELECT commitIdentifier FROM %T 'SELECT commitIdentifier FROM %T
WHERE repositoryID = %s AND %Q', WHERE repositoryID = %s AND %LO',
id(new PhabricatorRepositoryCommit())->getTableName(), id(new PhabricatorRepositoryCommit())->getTableName(),
$repository->getID(), $repository->getID(),
implode(' OR ', $prefixes)); $prefixes);
foreach ($commits as $commit) { foreach ($commits as $commit) {
$hash = $commit['commitIdentifier']; $hash = $commit['commitIdentifier'];

View File

@@ -158,7 +158,7 @@ final class PhabricatorFactDatapointQuery extends Phobject {
$this->dimensionMap); $this->dimensionMap);
} }
$where = '('.implode(') AND (', $where).')'; $where = qsprintf($conn, '%LA', $where);
if ($this->limit) { if ($this->limit) {
$limit = qsprintf( $limit = qsprintf(
@@ -166,7 +166,7 @@ final class PhabricatorFactDatapointQuery extends Phobject {
'LIMIT %d', 'LIMIT %d',
$this->limit); $this->limit);
} else { } else {
$limit = ''; $limit = qsprintf($conn, '');
} }
return queryfx_all( return queryfx_all(

View File

@@ -52,8 +52,6 @@ final class MultimeterSampleController extends MultimeterController {
} }
} }
$where = '('.implode(') AND (', $where).')';
$data = queryfx_all( $data = queryfx_all(
$conn, $conn,
'SELECT *, 'SELECT *,
@@ -61,13 +59,13 @@ final class MultimeterSampleController extends MultimeterController {
SUM(sampleRate * resourceCost) AS totalCost, SUM(sampleRate * resourceCost) AS totalCost,
SUM(sampleRate * resourceCost) / SUM(sampleRate) AS averageCost SUM(sampleRate * resourceCost) / SUM(sampleRate) AS averageCost
FROM %T FROM %T
WHERE %Q WHERE %LA
GROUP BY %Q GROUP BY %LC
ORDER BY totalCost DESC, MAX(id) DESC ORDER BY totalCost DESC, MAX(id) DESC
LIMIT 100', LIMIT 100',
$table->getTableName(), $table->getTableName(),
$where, $where,
implode(', ', array_select_keys($group_map, $group))); array_select_keys($group_map, $group));
$this->loadDimensions($data); $this->loadDimensions($data);
$phids = array(); $phids = array();

View File

@@ -32,7 +32,7 @@ abstract class PhabricatorPackagesQuery
throw new PhabricatorEmptyQueryException(); throw new PhabricatorEmptyQueryException();
} }
return implode(' OR ', $parts); return qsprintf($conn, '%LO', $parts);
} }
} }

View File

@@ -268,7 +268,7 @@ final class PhabricatorPeopleQuery
'user.username LIKE %>', 'user.username LIKE %>',
$name_prefix); $name_prefix);
} }
$where[] = '('.implode(' OR ', $parts).')'; $where[] = qsprintf($conn, '%LO', $parts);
} }
if ($this->emails !== null) { if ($this->emails !== null) {

View File

@@ -177,9 +177,9 @@ final class PhrequentUserTimeQuery
$preempting_events = queryfx_all( $preempting_events = queryfx_all(
$conn_r, $conn_r,
'SELECT * FROM %T WHERE %Q ORDER BY dateStarted ASC, id ASC', 'SELECT * FROM %T WHERE %LO ORDER BY dateStarted ASC, id ASC',
$usertime->getTableName(), $usertime->getTableName(),
implode(' OR ', $preempt)); $preempt);
$preempting_events = $usertime->loadAllFromArray($preempting_events); $preempting_events = $usertime->loadAllFromArray($preempting_events);
$preempting_events = mgroup($preempting_events, 'getUserPHID'); $preempting_events = mgroup($preempting_events, 'getUserPHID');

View File

@@ -309,10 +309,14 @@ final class PhrictionDocumentQuery
$max); $max);
} }
$path_clauses[] = '('.implode(') AND (', $parts).')'; if ($parts) {
$path_clauses[] = qsprintf($conn, '%LA', $parts);
}
} }
$where[] = '('.implode(') OR (', $path_clauses).')'; if ($path_clauses) {
$where[] = qsprintf($conn, '%LO', $path_clauses);
}
} }
return $where; return $where;

View File

@@ -514,7 +514,7 @@ final class PhabricatorProjectQuery
'name LIKE %>', 'name LIKE %>',
$name_prefix); $name_prefix);
} }
$where[] = '('.implode(' OR ', $parts).')'; $where[] = qsprintf($conn, '%LO', $parts);
} }
if ($this->icons !== null) { if ($this->icons !== null) {

View File

@@ -1440,7 +1440,11 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
$key); $key);
} }
return implode(' ', $joins); if ($joins) {
return qsprintf($conn, '%LJ', $joins);
} else {
return qsprintf($conn, '');
}
} }
/** /**
@@ -1516,7 +1520,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
} }
if ($constraint_parts) { if ($constraint_parts) {
$where[] = '('.implode(') OR (', $constraint_parts).')'; $where[] = qsprintf($conn, '%LO', $constraint_parts);
} }
break; break;
} }
@@ -1670,7 +1674,7 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
} }
if (!$this->ferretEngine) { if (!$this->ferretEngine) {
$select[] = '0 _ft_rank'; $select[] = qsprintf($conn, '0 _ft_rank');
return $select; return $select;
} }
@@ -1736,12 +1740,21 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
} }
} }
$parts[] = '0'; $parts[] = qsprintf($conn, '%d', 0);
$sum = array_shift($parts);
foreach ($parts as $part) {
$sum = qsprintf(
$conn,
'%Q + %Q',
$sum,
$part);
}
$select[] = qsprintf( $select[] = qsprintf(
$conn, $conn,
'%Q _ft_rank', '%Q _ft_rank',
implode(' + ', $parts)); $sum);
return $select; return $select;
} }
@@ -2031,20 +2044,20 @@ abstract class PhabricatorCursorPagedPolicyAwareQuery
if ($is_not) { if ($is_not) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'(%Q)', '%LA',
implode(' AND ', $term_constraints)); $term_constraints);
} else if ($is_quoted) { } else if ($is_quoted) {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'(%T.rawCorpus LIKE %~ AND (%Q))', '(%T.rawCorpus LIKE %~ AND %LO)',
$table_alias, $table_alias,
$value, $value,
implode(' OR ', $term_constraints)); $term_constraints);
} else { } else {
$where[] = qsprintf( $where[] = qsprintf(
$conn, $conn,
'(%Q)', '%LO',
implode(' OR ', $term_constraints)); $term_constraints);
} }
} }