예제 #1
0
 /**
  * @param array $updates Array of arrays each containing two keys, 'primaryKey'
  *  and 'changes'. primaryKey must contain a map of column names to values
  *  sufficient to uniquely identify the row changes must contain a map of column
  *  names to update values to apply to the row.
  */
 public function write(array $updates)
 {
     $this->db->begin();
     foreach ($updates as $update) {
         $this->db->update($this->table, $update['changes'], $update['primaryKey'], __METHOD__);
     }
     $this->db->commit();
     wfWaitForSlaves(false, false, $this->clusterName);
 }
예제 #2
0
 /**
  * @param array $updates Array of arrays each containing two keys, 'primaryKey'
  *  and 'changes'. primaryKey must contain a map of column names to values
  *  sufficient to uniquely identify the row changes must contain a map of column
  *  names to update values to apply to the row.
  */
 public function write(array $updates)
 {
     $this->db->begin();
     foreach ($updates as $update) {
         $this->db->update($this->table, $update['changes'], $update['primaryKey'], __METHOD__);
     }
     $this->db->commit();
     wfGetLBFactory()->waitForReplication();
 }
예제 #3
0
 /**
  * @param array $updates Array of arrays each containing two keys, 'primaryKey'
  *  and 'changes'. primaryKey must contain a map of column names to values
  *  sufficient to uniquely identify the row changes must contain a map of column
  *  names to update values to apply to the row.
  */
 public function write(array $updates)
 {
     $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
     $ticket = $lbFactory->getEmptyTransactionTicket(__METHOD__);
     foreach ($updates as $update) {
         $this->db->update($this->table, $update['changes'], $update['primaryKey'], __METHOD__);
     }
     $lbFactory->commitAndWaitForReplication(__METHOD__, $ticket);
 }
예제 #4
0
 /**
  * 更新ID为$id的记录,值为$data关联数组
  * @param $id
  * @param $data
  * @param $where 指定匹配字段,默认为主键
  * @return true/false
  */
 public final function set($id, $data, $where = '')
 {
     if (empty($where)) {
         $where = $this->primary;
     }
     return $this->db->update($id, $data, $this->table, $where);
 }
예제 #5
0
 /**
  * Invalidate the cache of a list of pages from a single namespace.
  * This is intended for use by subclasses.
  *
  * @param IDatabase $dbw
  * @param int $namespace Namespace number
  * @param array $dbkeys
  */
 public static function invalidatePages(IDatabase $dbw, $namespace, array $dbkeys)
 {
     if ($dbkeys === []) {
         return;
     }
     $dbw->onTransactionIdle(function () use($dbw, $namespace, $dbkeys) {
         $services = MediaWikiServices::getInstance();
         $lbFactory = $services->getDBLoadBalancerFactory();
         // Determine which pages need to be updated.
         // This is necessary to prevent the job queue from smashing the DB with
         // large numbers of concurrent invalidations of the same page.
         $now = $dbw->timestamp();
         $ids = $dbw->selectFieldValues('page', 'page_id', ['page_namespace' => $namespace, 'page_title' => $dbkeys, 'page_touched < ' . $dbw->addQuotes($now)], __METHOD__);
         if (!$ids) {
             return;
         }
         $batchSize = $services->getMainConfig()->get('UpdateRowsPerQuery');
         $ticket = $lbFactory->getEmptyTransactionTicket(__METHOD__);
         foreach (array_chunk($ids, $batchSize) as $idBatch) {
             $dbw->update('page', ['page_touched' => $now], ['page_id' => $idBatch, 'page_touched < ' . $dbw->addQuotes($now)], __METHOD__);
             $lbFactory->commitAndWaitForReplication(__METHOD__, $ticket);
         }
     }, __METHOD__);
 }
예제 #6
0
 /**
  * Update the page record to point to a newly saved revision.
  *
  * @param IDatabase $dbw
  * @param Revision $revision For ID number, and text used to set
  *   length and redirect status fields
  * @param int $lastRevision If given, will not overwrite the page field
  *   when different from the currently set value.
  *   Giving 0 indicates the new page flag should be set on.
  * @param bool $lastRevIsRedirect If given, will optimize adding and
  *   removing rows in redirect table.
  * @return bool Success; false if the page row was missing or page_latest changed
  */
 public function updateRevisionOn($dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null)
 {
     global $wgContentHandlerUseDB;
     // Assertion to try to catch T92046
     if ((int) $revision->getId() === 0) {
         throw new InvalidArgumentException(__METHOD__ . ': Revision has ID ' . var_export($revision->getId(), 1));
     }
     $content = $revision->getContent();
     $len = $content ? $content->getSize() : 0;
     $rt = $content ? $content->getUltimateRedirectTarget() : null;
     $conditions = ['page_id' => $this->getId()];
     if (!is_null($lastRevision)) {
         // An extra check against threads stepping on each other
         $conditions['page_latest'] = $lastRevision;
     }
     $row = ['page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp($revision->getTimestamp()), 'page_is_new' => $lastRevision === 0 ? 1 : 0, 'page_is_redirect' => $rt !== null ? 1 : 0, 'page_len' => $len];
     if ($wgContentHandlerUseDB) {
         $row['page_content_model'] = $revision->getContentModel();
     }
     $dbw->update('page', $row, $conditions, __METHOD__);
     $result = $dbw->affectedRows() > 0;
     if ($result) {
         $this->updateRedirectOn($dbw, $rt, $lastRevIsRedirect);
         $this->setLastEdit($revision);
         $this->mLatest = $revision->getId();
         $this->mIsRedirect = (bool) $rt;
         // Update the LinkCache.
         LinkCache::singleton()->addGoodLinkObj($this->getId(), $this->mTitle, $len, $this->mIsRedirect, $this->mLatest, $revision->getContentModel());
     }
     return $result;
 }
예제 #7
0
 /**
  * @param IDatabase $dbw
  * @return bool|mixed
  */
 public static function cacheUpdate($dbw)
 {
     global $wgActiveUserDays;
     $dbr = wfGetDB(DB_SLAVE, 'vslow');
     # Get non-bot users than did some recent action other than making accounts.
     # If account creation is included, the number gets inflated ~20+ fold on enwiki.
     $activeUsers = $dbr->selectField('recentchanges', 'COUNT( DISTINCT rc_user_text )', array('rc_user != 0', 'rc_bot' => 0, 'rc_log_type != ' . $dbr->addQuotes('newusers') . ' OR rc_log_type IS NULL', 'rc_timestamp >= ' . $dbr->addQuotes($dbr->timestamp(wfTimestamp(TS_UNIX) - $wgActiveUserDays * 24 * 3600))), __METHOD__);
     $dbw->update('site_stats', array('ss_active_users' => intval($activeUsers)), array('ss_row_id' => 1), __METHOD__);
     return $activeUsers;
 }