MediaWiki  1.29.2
WANCacheReapUpdate.php
Go to the documentation of this file.
1 <?php
2 
3 use Psr\Log\LoggerInterface;
5 
26  private $db;
28  private $logger;
29 
34  public function __construct( IDatabase $db, LoggerInterface $logger ) {
35  $this->db = $db;
36  $this->logger = $logger;
37  }
38 
39  function doUpdate() {
40  $reaper = new WANObjectCacheReaper(
43  [ $this, 'getTitleChangeEvents' ],
44  [ $this, 'getEventAffectedKeys' ],
45  [
46  'channel' => 'table:recentchanges:' . $this->db->getWikiID(),
47  'logger' => $this->logger
48  ]
49  );
50 
51  $reaper->invoke( 100 );
52  }
53 
63  public function getTitleChangeEvents( $start, $id, $end, $limit ) {
64  $db = $this->db;
65  $encStart = $db->addQuotes( $db->timestamp( $start ) );
66  $encEnd = $db->addQuotes( $db->timestamp( $end ) );
67  $id = (int)$id; // cast NULL => 0 since rc_id is an integer
68 
69  $res = $db->select(
70  'recentchanges',
71  [ 'rc_namespace', 'rc_title', 'rc_timestamp', 'rc_id' ],
72  [
73  $db->makeList( [
74  "rc_timestamp > $encStart",
75  "rc_timestamp = $encStart AND rc_id > " . $db->addQuotes( $id )
76  ], LIST_OR ),
77  "rc_timestamp < $encEnd"
78  ],
79  __METHOD__,
80  [ 'ORDER BY' => 'rc_timestamp ASC, rc_id ASC', 'LIMIT' => $limit ]
81  );
82 
83  $events = [];
84  foreach ( $res as $row ) {
85  $events[] = [
86  'id' => (int)$row->rc_id,
87  'pos' => (int)wfTimestamp( TS_UNIX, $row->rc_timestamp ),
88  'item' => new TitleValue( (int)$row->rc_namespace, $row->rc_title )
89  ];
90  }
91 
92  return $events;
93  }
94 
105  $entities = [];
106 
107  $entities[] = WikiPage::factory( Title::newFromTitleValue( $t ) );
108  if ( $t->inNamespace( NS_FILE ) ) {
109  $entities[] = wfLocalFile( $t->getText() );
110  }
111  if ( $t->inNamespace( NS_USER ) ) {
112  $entities[] = User::newFromName( $t->getText(), false );
113  }
114 
115  $keys = [];
116  foreach ( $entities as $entity ) {
117  if ( $entity ) {
118  $keys = array_merge( $keys, $entity->getMutableCacheKeys( $cache ) );
119  }
120  }
121  if ( $keys ) {
122  $this->logger->debug( __CLASS__ . ': got key(s) ' . implode( ', ', $keys ) );
123  }
124 
125  return $keys;
126  }
127 }
WANCacheReapUpdate\$db
IDatabase $db
Definition: WANCacheReapUpdate.php:26
WANCacheReapUpdate\__construct
__construct(IDatabase $db, LoggerInterface $logger)
Definition: WANCacheReapUpdate.php:34
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:189
ObjectCache\getLocalClusterInstance
static getLocalClusterInstance()
Get the main cluster-local cache object.
Definition: ObjectCache.php:357
Wikimedia\Rdbms\IDatabase\makeList
makeList( $a, $mode=self::LIST_COMMA)
Makes an encoded list of strings from an array.
wfTimestamp
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
Definition: GlobalFunctions.php:1994
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
NS_FILE
const NS_FILE
Definition: Defines.php:68
WANCacheReapUpdate
Class for fixing stale WANObjectCache keys using a purge event source.
Definition: WANCacheReapUpdate.php:24
User\newFromName
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
Definition: User.php:556
$res
$res
Definition: database.txt:21
WANCacheReapUpdate\getTitleChangeEvents
getTitleChangeEvents( $start, $id, $end, $limit)
Definition: WANCacheReapUpdate.php:63
php
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:40
Wikimedia\Rdbms\IDatabase\timestamp
timestamp( $ts=0)
Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting ...
LIST_OR
const LIST_OR
Definition: Defines.php:44
WikiPage\factory
static factory(Title $title)
Create a WikiPage object of the appropriate class for the given title.
Definition: WikiPage.php:120
$limit
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist Do not use this to implement individual filters if they are compatible with the ChangesListFilter and ChangesListFilterGroup structure use sub classes of those in conjunction with the ChangesListSpecialPageStructuredFilters hook This hook can be used to implement filters that do not implement that or custom behavior that is not an individual filter e g Watchlist and Watchlist you will want to construct new ChangesListBooleanFilter or ChangesListStringOptionsFilter objects When constructing you specify which group they belong to You can reuse existing or create your you must register them with $special registerFilterGroup removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers please use GetContentModels hook to make them known to core if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
Definition: hooks.txt:1049
WANCacheReapUpdate\getEventAffectedKeys
getEventAffectedKeys(WANObjectCache $cache, TitleValue $t)
Gets a list of important cache keys associated with a title.
Definition: WANCacheReapUpdate.php:103
WANCacheReapUpdate\$logger
LoggerInterface $logger
Definition: WANCacheReapUpdate.php:28
Title\newFromTitleValue
static newFromTitleValue(TitleValue $titleValue)
Create a new Title from a TitleValue.
Definition: Title.php:228
WANObjectCache
Multi-datacenter aware caching interface.
Definition: WANObjectCache.php:81
$cache
$cache
Definition: mcc.php:33
Wikimedia\Rdbms\IDatabase\addQuotes
addQuotes( $s)
Adds quotes and backslashes.
ObjectCache\getMainWANInstance
static getMainWANInstance()
Get the main WAN cache object.
Definition: ObjectCache.php:370
WANObjectCacheReaper\invoke
invoke( $n=100)
Check and reap stale keys based on a chunk of events.
Definition: WANObjectCacheReaper.php:114
as
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$keys
$keys
Definition: testCompression.php:65
Wikimedia\Rdbms\IDatabase\select
select( $table, $vars, $conds='', $fname=__METHOD__, $options=[], $join_conds=[])
Execute a SELECT query constructed using the various parameters provided.
NS_USER
const NS_USER
Definition: Defines.php:64
WANObjectCacheReaper
Class for scanning through chronological, log-structured data or change logs and locally purging cach...
Definition: WANObjectCacheReaper.php:38
WANCacheReapUpdate\doUpdate
doUpdate()
Perform the actual work.
Definition: WANCacheReapUpdate.php:39
$t
$t
Definition: testCompression.php:67
DeferrableUpdate
Interface that deferrable updates should implement.
Definition: DeferrableUpdate.php:9
wfLocalFile
wfLocalFile( $title)
Get an object referring to a locally registered file.
Definition: GlobalFunctions.php:3112
TitleValue
Represents a page (or page fragment) title within MediaWiki.
Definition: TitleValue.php:36