/** Counts of membership (cat_pages, cat_subcats, cat_files) */
private $mPages = null, $mSubcats = null, $mFiles = null;
+ const LOAD_ONLY = 0;
+ const LAZY_INIT_ROW = 1;
+
private function __construct() {
}
/**
* Set up all member variables using a database query.
+ * @param integer $mode
* @throws MWException
* @return bool True on success, false on failure.
*/
- protected function initialize() {
+ protected function initialize( $mode = self::LOAD_ONLY ) {
if ( $this->mName === null && $this->mID === null ) {
throw new MWException( __METHOD__ . ' has both names and IDs null' );
} elseif ( $this->mID === null ) {
$this->mFiles = 0;
# If the title exists, call refreshCounts to add a row for it.
- if ( $this->mTitle->exists() ) {
+ if ( $mode === self::LAZY_INIT_ROW && $this->mTitle->exists() ) {
DeferredUpdates::addCallableUpdate( [ $this, 'refreshCounts' ] );
}
$this->mSubcats = max( $this->mSubcats, 0 );
$this->mFiles = max( $this->mFiles, 0 );
- DeferredUpdates::addCallableUpdate( [ $this, 'refreshCounts' ] );
+ if ( $mode === self::LAZY_INIT_ROW ) {
+ DeferredUpdates::addCallableUpdate( [ $this, 'refreshCounts' ] );
+ }
}
return true;
return $this->mTitle;
}
- if ( !$this->initialize() ) {
+ if ( !$this->initialize( self::LAZY_INIT_ROW ) ) {
return false;
}
/**
* Fetch a TitleArray of up to $limit category members, beginning after the
* category sort key $offset.
- * @param int $limit
+ * @param int|bool $limit
* @param string $offset
* @return TitleArray TitleArray object for category members.
*/
* @return bool
*/
private function getX( $key ) {
- if ( !$this->initialize() ) {
+ if ( !$this->initialize( self::LAZY_INIT_ROW ) ) {
return false;
}
return $this->{$key};
# If we have just a category name, find out whether there is an
# existing row. Or if we have just an ID, get the name, because
# that's what categorylinks uses.
- if ( !$this->initialize() ) {
+ if ( !$this->initialize( self::LOAD_ONLY ) ) {
return false;
}
$name = __METHOD__ . ':' . md5( $this->mName );
$scopedLock = $dbw->getScopedLockAndFlush( $name, __METHOD__, 1 );
if ( !$scopedLock ) {
- return;
+ return false;
}
$dbw->startAtomic( __METHOD__ );