r114727 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114726‎ | r114727 | r114728 >
Date:00:12, 5 April 2012
Author:maxsem
Status:deferred
Tags:
Comment:
Introduced a setting to specify the number of gt_*_int's per degree, will need to be set to a higher number on WMF
Modified paths:
  • /trunk/extensions/GeoData/GeoData.body.php (modified) (history)
  • /trunk/extensions/GeoData/GeoData.php (modified) (history)
  • /trunk/extensions/GeoData/api/ApiQueryGeoSearch.php (modified) (history)
  • /trunk/extensions/GeoData/updateIndexGranularity.php (added) (history)

Diff [purge]

Index: trunk/extensions/GeoData/updateIndexGranularity.php
@@ -0,0 +1,54 @@
 2+<?php
 3+
 4+
 5+$IP = getenv( 'MW_INSTALL_PATH' );
 6+if ( $IP === false ) {
 7+ $IP = dirname( __FILE__ ) . '/../../..';
 8+}
 9+require_once( "$IP/maintenance/Maintenance.php" );
 10+
 11+class UpdateIndexGranularity extends Maintenance {
 12+ const BATCH_SIZE = 500;
 13+
 14+ public function __construct() {
 15+ parent::__construct();
 16+ $this->mDescription = 'Updates GeoData database after $wgGeoDataIndexGranularity has been changed';
 17+ }
 18+
 19+ public function execute() {
 20+ global $wgGeoDataIndexGranularity;
 21+ if ( !isset( $wgGeoDataIndexGranularity ) ) {
 22+ $this->error( 'Please install GeoData properly', true );
 23+ }
 24+ $id = 0;
 25+ $dbw = wfGetDB( DB_MASTER );
 26+ do {
 27+ $ids = array();
 28+ $dbw->begin( __METHOD__ );
 29+ $res = $dbw->select( 'geo_tags', 'gt_id',
 30+ array( "gt_id > $id" ),
 31+ __METHOD__,
 32+ array( 'LIMIT' => self::BATCH_SIZE )
 33+ );
 34+ foreach ( $res as $row ) {
 35+ $id = $row->gt_id;
 36+ $ids[] = $id;
 37+ }
 38+ $dbw->update( 'geo_tags',
 39+ array(
 40+ "gt_lat_int = ROUND(gt_lat * $wgGeoDataIndexGranularity)",
 41+ "gt_lon_int = ROUND(gt_lon * $wgGeoDataIndexGranularity)"
 42+ ),
 43+ array( 'gt_id' => $ids ),
 44+ __METHOD__
 45+ );
 46+ $dbw->commit( __METHOD__ );
 47+ $this->output( "$id\n" );
 48+ wfWaitForSlaves();
 49+ } while ( count( $ids ) === self::BATCH_SIZE );
 50+ }
 51+}
 52+
 53+$maintClass = 'UpdateIndexGranularity';
 54+require_once( DO_MAINTENANCE );
 55+
Index: trunk/extensions/GeoData/GeoData.body.php
@@ -237,12 +237,13 @@
238238 * @return Array: Associative array in format 'field' => 'value'
239239 */
240240 public function getRow( $pageId ) {
 241+ global $wgGeoDataIndexGranularity;
241242 $row = array( 'gt_page_id' => $pageId );
242243 foreach ( self::$fieldMapping as $field => $column ) {
243244 $row[$column] = $this->$field;
244245 }
245 - $row['gt_lat_int'] = round( $this->lat * 10 );
246 - $row['gt_lon_int'] = round( $this->lon * 10 );
 246+ $row['gt_lat_int'] = round( $this->lat * $wgGeoDataIndexGranularity );
 247+ $row['gt_lon_int'] = round( $this->lon * $wgGeoDataIndexGranularity );
247248 return $row;
248249 }
249250
Index: trunk/extensions/GeoData/api/ApiQueryGeoSearch.php
@@ -167,13 +167,14 @@
168168 * @return Array
169169 */
170170 public static function intRange( $start, $end ) {
171 - $start = round( $start * 10 );
172 - $end = round( $end * 10 );
 171+ global $wgGeoDataIndexGranularity;
 172+ $start = round( $start * $wgGeoDataIndexGranularity );
 173+ $end = round( $end * $wgGeoDataIndexGranularity );
173174 // @todo: works only on Earth
174175 if ( $start > $end ) {
175176 return array_merge(
176 - range( -1800, $end ),
177 - range( $start, 1800 )
 177+ range( -180 * $wgGeoDataIndexGranularity, $end ),
 178+ range( $start, 180 * $wgGeoDataIndexGranularity )
178179 );
179180 } else {
180181 return range( $start, $end );
Index: trunk/extensions/GeoData/GeoData.php
@@ -144,3 +144,9 @@
145145 'unknown globe' => 'none',
146146 'invalid region' => 'track',
147147 );
 148+
 149+/**
 150+ * How many gt_(lat|lon)_int units per degree
 151+ * Run updateIndexGranularity.php after changing this
 152+ */
 153+$wgGeoDataIndexGranularity = 10;

Status & tagging log