protected function getWeightScale($index, IDatabase $conn = null) { if (!$conn) { return 0.0; } $weight = 1.0; if ($this->warmCacheRatio > 0) { $res = $conn->query('SHOW STATUS', false); $s = $res ? $conn->fetchObject($res) : false; if ($s === false) { $host = $this->parent->getServerName($index); $this->replLogger->error(__METHOD__ . ": could not get status for {$host}"); } else { // http://dev.mysql.com/doc/refman/5.7/en/server-status-variables.html if ($s->Innodb_buffer_pool_pages_total > 0) { $ratio = $s->Innodb_buffer_pool_pages_data / $s->Innodb_buffer_pool_pages_total; } elseif ($s->Qcache_total_blocks > 0) { $ratio = 1.0 - $s->Qcache_free_blocks / $s->Qcache_total_blocks; } else { $ratio = 1.0; } // Stop caring once $ratio >= $this->warmCacheRatio $weight *= min($ratio / $this->warmCacheRatio, 1.0); } } return $weight; }
/** * Count the number of items on a user's watchlist * * @param IDatabase $dbr A database connection * @return int */ protected function countItems($dbr) { # Fetch the raw count $rows = $dbr->select('watchlist', array('count' => 'COUNT(*)'), array('wl_user' => $this->getUser()->getId()), __METHOD__); $row = $dbr->fetchObject($rows); $count = $row->count; return floor($count / 2); }