LanguageNameIndexer: Generate PHP file instead of serialized file.
Serialized format is no longer in style for data. PHP files can take advantage of AutoLoader and caching so they can even be faster than serialized files. As side bonus we can have readable diffs for updates. Only downside is that the file generation takes about ten lines of ugly string manipulation. Change-Id: If09704d1172daa13c72a308814534cac1fe9899f
This commit is contained in:
committed by
Santhosh
parent
8bb0c2f683
commit
b3ba423354
@@ -44,7 +44,34 @@ class LanguageNameIndexer extends Maintenance {
|
||||
}
|
||||
|
||||
$this->output( 'Total buckets: ' . count( $buckets ) . "\n" );
|
||||
file_put_contents( 'langnames.ser', serialize( $buckets ) );
|
||||
$this->generateFile( $buckets );
|
||||
}
|
||||
|
||||
private function generateFile( array $buckets ) {
|
||||
$template = <<<PHP
|
||||
<?php
|
||||
// This file is generated by script!
|
||||
class LanguageNameSearchData {
|
||||
public static \$buckets = ___;
|
||||
}
|
||||
|
||||
PHP;
|
||||
|
||||
// Format for short array format
|
||||
$data = var_export( $buckets, true );
|
||||
$data = str_replace( "array (", '[', $data );
|
||||
$data = str_replace( "),", '],', $data );
|
||||
// Closing of the array, add correct indendation
|
||||
$data = preg_replace( "/\)$/", "\t]", $data );
|
||||
// Remove newlines after =>s
|
||||
$data = preg_replace( '/(=>)\s+(\[)/m', '\1 \2', $data );
|
||||
// Convert spaces to tabs. Since we are not top-level need more tabs.
|
||||
$data = preg_replace( '/^ /m', "\t\t\t", $data );
|
||||
$data = preg_replace( '/^ /m', "\t\t", $data );
|
||||
|
||||
$template = str_replace( '___', $data, $template );
|
||||
|
||||
file_put_contents( __DIR__ . '/LanguageNameSearchData.php', $template );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user