r61844 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r61843‎ | r61844 | r61845 >
Date:01:35, 2 February 2010
Author:pdhanda
Status:resolved (Comments)
Tags:
Comment:
replaced subselect with a select distinct
Modified paths:
  • /trunk/extensions/CodeReview/ui/CodeRevisionAuthorView.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionListView.php (modified) (history)
  • /trunk/extensions/CodeReview/ui/CodeRevisionStatusView.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/ui/CodeRevisionAuthorView.php
@@ -45,7 +45,7 @@
4646 }
4747
4848 function getSpecializedWhereClause( $dbr ) {
49 - return ' AND cr_author = ' . $dbr->addQuotes( $this->mAuthor );
 49+ return array( 'cr_author' => $this->mAuthor );
5050 }
5151
5252 }
Index: trunk/extensions/CodeReview/ui/CodeRevisionListView.php
@@ -161,28 +161,27 @@
162162 }
163163
164164 function getRevCountQuery( $dbr ) {
165 - $tables = array( $dbr->tableName( 'code_rev' ) );
166 - $selectFields = array( 'COUNT( cr_id ) AS rev_count' );
 165+ $tables = array( $dbr->tableName( 'code_rev' ) );
 166+ $selectFields = array( 'COUNT( DISTINCT cr_id ) AS rev_count' );
167167 // count if code_rev where path matches
168168 if ( $this->mPath ) {
169 - $whereCond = 'cr_id IN' .
170 - ' ( SELECT cp_rev_id FROM '. $dbr->tableName( 'code_paths' ) . ' WHERE' .
171 - ' cp_repo_id = ' . $this->mRepo->getId(). ' AND' .
172 - ' cp_path LIKE ' . $dbr->addQuotes( $this->mPath . '%' ) . ' AND' .
173 - // performance
174 - ' cp_rev_id > ' . ( $this->mRepo->getLastStoredRev() - 20000 ) .
175 - $this->getSpecializedWhereClause( $dbr ) .
176 - ' )';
 169+ $tables[] = $dbr->tableName( 'code_paths' );
 170+ $whereCond = array('cr_repo_id' => $this->mRepo->getId(),
 171+ 'cr_id = cp_rev_id',
 172+ ' cp_path LIKE ' . $dbr->addQuotes( $this->mPath . '%' ),
 173+ // performance
 174+ ' cp_rev_id > ' . ( $this->mRepo->getLastStoredRev() - 20000 )
 175+ );
177176 // No path; count of code_rev
178177 } else {
179 - $whereCond = 'cr_repo_id = ' . $this->mRepo->getId() .
180 - $this->getSpecializedWhereClause( $dbr );
 178+ $whereCond = array('cr_repo_id' => $this->mRepo->getId());
181179 }
182 - return $dbr->selectRow ($tables, $selectFields, $whereCond);
 180+ $whereCond += $this->getSpecializedWhereClause( $dbr );
 181+ return $dbr->selectRow( $tables, $selectFields, $whereCond );
183182 }
184183
185184 function getSpecializedWhereClause( $dbr ) {
186 - return '';
 185+ return array();
187186 }
188187
189188 }
Index: trunk/extensions/CodeReview/ui/CodeRevisionStatusView.php
@@ -11,7 +11,7 @@
1212 }
1313
1414 function getSpecializedWhereClause( $dbr ) {
15 - return ' AND cr_status = ' . $dbr->addQuotes( $this->mStatus );
 15+ return array( 'cr_status' => $this->mStatus );
1616 }
1717 }
1818

Follow-up revisions

RevisionCommit summaryAuthorDate
r62239Cleanup r61844: Don't need tableName(), use buildLike(), use array_merge() no...demon11:47, 10 February 2010

Comments

#Comment by Catrope (talk | contribs)   12:57, 2 February 2010
+		$tables = array( $dbr->tableName( 'code_rev' ) );

You don't have to use tableName() when using the pretty SQL generation functions, they'll handle it for you.

+							' cp_path LIKE ' . $dbr->addQuotes( $this->mPath . '%' ),

Use $dbr->buildLike(), needed for SQLite compatibility.

+		$whereCond += $this->getSpecializedWhereClause( $dbr );

Array plus doesn't work here, you need array_merge:

> $a = array( 'foo', 'bar' );

> $b = array( 'baz' );

> var_dump( $a + $b );
array(2) {
  [0]=>
  string(3) "foo"
  [1]=>
  string(3) "bar"
}

> var_dump( array_merge( $a, $b ) );
array(3) {
  [0]=>
  string(3) "foo"
  [1]=>
  string(3) "bar"
  [2]=>
  string(3) "baz"
}

>

Status & tagging log