3 final class DiffusionLintCountQuery
extends PhabricatorQuery
{
9 public function withBranchIDs(array $branch_ids) {
10 $this->branchIDs
= $branch_ids;
14 public function withPaths(array $paths) {
15 $this->paths
= $paths;
19 public function withCodes(array $codes) {
20 $this->codes
= $codes;
24 public function execute() {
26 throw new PhutilInvalidStateException('withPaths');
29 if (!$this->branchIDs
) {
30 throw new PhutilInvalidStateException('withBranchIDs');
33 $conn_r = id(new PhabricatorRepositoryCommit())->establishConnection('r');
35 $this->paths
= array_unique($this->paths
);
36 list($dirs, $paths) = $this->processPaths();
39 foreach ($dirs as $dir) {
40 $parts[$dir] = qsprintf(
45 foreach ($paths as $path) {
46 $parts[$path] = qsprintf(
53 foreach ($parts as $key => $part) {
54 $queries[] = qsprintf(
56 'SELECT %s path_prefix, COUNT(*) N FROM %T %Q',
58 PhabricatorRepository
::TABLE_LINTMESSAGE
,
59 $this->buildCustomWhereClause($conn_r, $part));
62 $huge_union_query = '('.implode(') UNION ALL (', $queries).')';
69 return $this->processResults($data);
72 protected function buildCustomWhereClause(
73 AphrontDatabaseConnection
$conn,
80 if ($this->codes
!== null) {
87 if ($this->branchIDs
!== null) {
94 return $this->formatWhereClause($conn, $where);
97 private function processPaths() {
100 foreach ($this->paths
as $path) {
102 if (substr($path, -1) == '/') {
108 return array($dirs, $paths);
111 private function processResults(array $data) {
112 $data = ipull($data, 'N', 'path_prefix');
114 // Strip the leading "/" back off each path.
116 foreach ($data as $path => $count) {
117 $output[substr($path, 1)] = $count;