r70827 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70826‎ | r70827 | r70828 >
Date:15:44, 10 August 2010
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Add a caching getAuthorCount, not used, as client side array counting will be cheaper (When we're pulling the author list normally anyway)

Add some braces
Modified paths:
  • /trunk/extensions/CodeReview/backend/CodeRepository.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CodeReview/backend/CodeRepository.php
@@ -126,7 +126,32 @@
127127 $wgMemc->set( $key, $authors, 3600 * 24 );
128128 return $authors;
129129 }
 130+
 131+ public function getAuthorCount() {
 132+ global $wgMemc;
 133+ $key = wfMemcKey( 'codereview', 'authorcount', $this->getId() );
 134+ $authorsCount = $wgMemc->get( $key );
 135+ if ( is_int( $authorsCount ) ) {
 136+ return $authorsCount;
 137+ }
 138+ $dbr = wfGetDB( DB_SLAVE );
 139+ $row = $dbr->select(
 140+ 'code_authors',
 141+ array( 'COUNT(cr_author) AS author_count' ),
 142+ array( 'cr_repo_id' => $this->getId() ),
 143+ __METHOD__
 144+ );
130145
 146+ if ( !$row ) {
 147+ throw new MWException( 'Failed to load expected author count' );
 148+ }
 149+
 150+ $authorsCount = intval( $row->author_count );
 151+
 152+ $wgMemc->set( $key, $authorsCount, 3600 * 24 );
 153+ return $authorsCount;
 154+ }
 155+
131156 public function getTagList() {
132157 global $wgMemc;
133158 $key = wfMemcKey( 'codereview', 'tags', $this->getId() );
@@ -167,8 +192,9 @@
168193 ),
169194 __METHOD__
170195 );
171 - if ( !$row )
 196+ if ( !$row ) {
172197 throw new MWException( 'Failed to load expected revision data' );
 198+ }
173199 return CodeRevision::newFromRow( $this, $row );
174200 }
175201

Follow-up revisions

RevisionCommit summaryAuthorDate
r74070Followup r70827, use count against getAuthorList, saves caching extra data, a...reedy14:48, 1 October 2010
r74074Use getAuthorCount() instead of counting authors (followup r69933, r70827)demon16:02, 1 October 2010

Comments

#Comment by 😂 (talk | contribs)   14:41, 1 October 2010

Wouldn't it make sense to just count( getAuthorList() ) since we're already caching that? Plus, if the two cached values don't expire at the same time you might get mismatched results.

Status & tagging log