29require __DIR__ .
'/../CommandLineInc.php';
31if ( !isset(
$args[0] ) ) {
32 echo
"Usage: php testCompression.php [--type=<type>] [--start=<start-date>] " .
33 "[--limit=<num-revs>] <page-title>\n";
37$lang = MediaWikiServices::getInstance()->getLanguageFactory()->getLanguage(
'en' );
39if ( isset( $options[
'start'] ) ) {
40 $start =
wfTimestamp( TS_MW, strtotime( $options[
'start'] ) );
41 echo
"Starting from " .
$lang->timeanddate( $start ) .
"\n";
43 $start =
'19700101000000';
45if ( isset( $options[
'limit'] ) ) {
46 $limit = $options[
'limit'];
52$type = $options[
'type'] ?? ConcatenatedGzipHistoryBlob::class;
55$revStore = MediaWikiServices::getInstance()->getRevisionStore();
61 'page_namespace' =>
$title->getNamespace(),
62 'page_title' =>
$title->getDBkey(),
63 'rev_timestamp > ' .
$dbr->addQuotes(
$dbr->timestamp( $start ) ),
66 [
'LIMIT' => $limit ],
74$t = -microtime(
true );
75foreach (
$res as $row ) {
76 $revRecord =
$revStore->newRevisionFromRow( $row );
77 $text = $revRecord->getSlot( SlotRecord::MAIN, RevisionRecord::RAW )
81 $hashes[$row->rev_id] = md5( $text );
89$t += microtime(
true );
90# print_r( $blob->mDiffMap );
92printf(
"%s\nCompression ratio for %d revisions: %5.2f, %s -> %d\n",
99printf(
"Compression time: %5.2f ms\n",
$t * 1000 );
101$t = -microtime(
true );
103foreach (
$keys as $id => $key ) {
104 $text =
$blob->getItem( $key );
105 if ( md5( $text ) !=
$hashes[$id] ) {
106 echo
"Content hash mismatch for rev_id $id\n";
110$t += microtime(
true );
111printf(
"Decompression time: %5.2f ms\n",
$t * 1000 );
unserialize( $serialized)
wfGetDB( $db, $groups=[], $wiki=false)
Get a Database object.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
foreach( $res as $row) $serialized
if(!isset( $args[0])) $lang