[MediaWiki-commits] [Gerrit] added $edgSuppressNoLocalVarMsg flag; added MongoDB memcache... - change (mediawiki...ExternalData)

2013-12-31 Thread Yaron Koren (Code Review)
Yaron Koren has submitted this change and it was merged.

Change subject: added $edgSuppressNoLocalVarMsg flag; added MongoDB memcached 
support; removed deprecated MongoDB slaveOkay flag; refactored collection 
exists logic; added isset check to suppress PHP Notice in apache error log
..


added $edgSuppressNoLocalVarMsg flag; added MongoDB memcached support; removed 
deprecated MongoDB slaveOkay flag; refactored
collection exists logic; added isset check to suppress PHP Notice in apache 
error log

Change-Id: I14f019c5cec113ba2950d393e50b6df0957435ac
---
M ED_ParserFunctions.php
M ED_Utils.php
2 files changed, 25 insertions(+), 18 deletions(-)

Approvals:
  Yaron Koren: Verified; Looks good to me, approved



diff --git a/ED_ParserFunctions.php b/ED_ParserFunctions.php
index c8e09f8..550cbcc 100644
--- a/ED_ParserFunctions.php
+++ b/ED_ParserFunctions.php
@@ -265,9 +265,9 @@
 * Render the #external_value parser function
 */
static function doExternalValue( $parser, $local_var = '' ) {
-   global $edgValues;
+   global $edgValues, $edgSuppressNoLocalVarMsg;
if ( ! array_key_exists( $local_var, $edgValues ) ) {
-   return Error: no local variable \$local_var\ was 
set.;
+   return $edgSuppressNoLocalVarMsg ? '' : Error: no 
local variable \$local_var\ was set.;
} elseif ( is_array( $edgValues[$local_var] ) ) {
return $edgValues[$local_var][0];
} else {
diff --git a/ED_Utils.php b/ED_Utils.php
index 7fc0944..5cc28ec 100644
--- a/ED_Utils.php
+++ b/ED_Utils.php
@@ -286,6 +286,19 @@
 * MongoDB.
 */
static function getMongoDBData( $db_server, $db_username, $db_password, 
$db_name, $from, $columns, $where, $sqlOptions, $otherParams ) {
+   global $wgMainCacheType, $wgMemc, $edgMemCachedMongoDBSeconds;
+
+// use MEMCACHED if configured to cache mongodb queries
+if ($wgMainCacheType === CACHE_MEMCACHED   
$edgMemCachedMongoDBSeconds  0) {
+   // check if cache entry exists
+   $mckey = wfMemcKey( 'mongodb', $from, 
md5(json_encode($otherParams) . json_encode($columns) . $where . 
json_encode($sqlOptions) . $db_name . $db_server));
+   $values = $wgMemc-get( $mckey );
+
+   if ($values !== false) {
+   return $values;
+   }
+}
+
// MongoDB login is done using a single string.
// When specifying extra connect string options (e.g. 
replicasets,timeout, etc.),
// use $db_server to pass these values
@@ -308,23 +321,13 @@
} catch ( Exception $e ) {
return wfMessage( externaldata-db-could-not-connect 
)-text();
}
-   // If working against a MongoDB replica set, it's OK to go to
-   // secondary/slaves should the primary go down.
-   MongoCursor::$slaveOkay = true;
 
$db = $m-selectDB( $db_name );
 
-   // MongoDB doesn't seem to have a way to check whether either
-   // a database or a collection exists, so instead we'll use
-   // getCollectionNames() to check for both.
-   $collectionNames = $db-getCollectionNames();
-   if ( count( $collectionNames ) == 0 ) {
-   return wfMessage( externaldata-db-could-not-connect 
)-text();
-   }
-
-   if ( !in_array( $from, $collectionNames ) ) {
-   return wfMessage( externaldata-db-unknown-collection 
)-text();
-   }
+   // Check if collection exists
+   if ($db-system-namespaces-findOne(array('name'=$db_name . 
. . $from)) === null){
+return wfMessage( externaldata-db-unknown-collection:)-text() . 
 $db_name . . . $from;
+}
 
$collection = new MongoCollection( $db, $from );
 
@@ -416,7 +419,7 @@
// specified using dots (e.g., a.b.c),
// get the value that way.
$values[$column][] = 
self::getValueFromJSONArray( $doc, $column );
-   } elseif ( is_array( $doc[$column] ) ) {
+   } elseif ( isset( $doc[$column] )  is_array( 
$doc[$column] ) ) {
// If MongoDB returns an array for a 
column,
// but the exact location of the value 
wasn't specified,
// do some extra processing.
@@ -438,11 +441,15 @@
}
} else {
// It's a simple literal.
-   

[MediaWiki-commits] [Gerrit] added $edgSuppressNoLocalVarMsg flag; added MongoDB memcache... - change (mediawiki...ExternalData)

2013-12-29 Thread Jqnatividad (Code Review)
Jqnatividad has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/104472


Change subject: added $edgSuppressNoLocalVarMsg flag; added MongoDB memcached 
support; removed deprecated MongoDB slaveOkay flag; refactored collection 
exists logic; added isset check to suppress PHP Notice in apache error log
..

added $edgSuppressNoLocalVarMsg flag; added MongoDB memcached support; removed 
deprecated MongoDB slaveOkay flag; refactored
collection exists logic; added isset check to suppress PHP Notice in apache 
error log

Change-Id: I14f019c5cec113ba2950d393e50b6df0957435ac
---
M ED_ParserFunctions.php
M ED_Utils.php
2 files changed, 25 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/ExternalData 
refs/changes/72/104472/1

diff --git a/ED_ParserFunctions.php b/ED_ParserFunctions.php
index c8e09f8..550cbcc 100644
--- a/ED_ParserFunctions.php
+++ b/ED_ParserFunctions.php
@@ -265,9 +265,9 @@
 * Render the #external_value parser function
 */
static function doExternalValue( $parser, $local_var = '' ) {
-   global $edgValues;
+   global $edgValues, $edgSuppressNoLocalVarMsg;
if ( ! array_key_exists( $local_var, $edgValues ) ) {
-   return Error: no local variable \$local_var\ was 
set.;
+   return $edgSuppressNoLocalVarMsg ? '' : Error: no 
local variable \$local_var\ was set.;
} elseif ( is_array( $edgValues[$local_var] ) ) {
return $edgValues[$local_var][0];
} else {
diff --git a/ED_Utils.php b/ED_Utils.php
index 7fc0944..5cc28ec 100644
--- a/ED_Utils.php
+++ b/ED_Utils.php
@@ -286,6 +286,19 @@
 * MongoDB.
 */
static function getMongoDBData( $db_server, $db_username, $db_password, 
$db_name, $from, $columns, $where, $sqlOptions, $otherParams ) {
+   global $wgMainCacheType, $wgMemc, $edgMemCachedMongoDBSeconds;
+
+// use MEMCACHED if configured to cache mongodb queries
+if ($wgMainCacheType === CACHE_MEMCACHED   
$edgMemCachedMongoDBSeconds  0) {
+   // check if cache entry exists
+   $mckey = wfMemcKey( 'mongodb', $from, 
md5(json_encode($otherParams) . json_encode($columns) . $where . 
json_encode($sqlOptions) . $db_name . $db_server));
+   $values = $wgMemc-get( $mckey );
+
+   if ($values !== false) {
+   return $values;
+   }
+}
+
// MongoDB login is done using a single string.
// When specifying extra connect string options (e.g. 
replicasets,timeout, etc.),
// use $db_server to pass these values
@@ -308,23 +321,13 @@
} catch ( Exception $e ) {
return wfMessage( externaldata-db-could-not-connect 
)-text();
}
-   // If working against a MongoDB replica set, it's OK to go to
-   // secondary/slaves should the primary go down.
-   MongoCursor::$slaveOkay = true;
 
$db = $m-selectDB( $db_name );
 
-   // MongoDB doesn't seem to have a way to check whether either
-   // a database or a collection exists, so instead we'll use
-   // getCollectionNames() to check for both.
-   $collectionNames = $db-getCollectionNames();
-   if ( count( $collectionNames ) == 0 ) {
-   return wfMessage( externaldata-db-could-not-connect 
)-text();
-   }
-
-   if ( !in_array( $from, $collectionNames ) ) {
-   return wfMessage( externaldata-db-unknown-collection 
)-text();
-   }
+   // Check if collection exists
+   if ($db-system-namespaces-findOne(array('name'=$db_name . 
. . $from)) === null){
+return wfMessage( externaldata-db-unknown-collection:)-text() . 
 $db_name . . . $from;
+}
 
$collection = new MongoCollection( $db, $from );
 
@@ -416,7 +419,7 @@
// specified using dots (e.g., a.b.c),
// get the value that way.
$values[$column][] = 
self::getValueFromJSONArray( $doc, $column );
-   } elseif ( is_array( $doc[$column] ) ) {
+   } elseif ( isset( $doc[$column] )  is_array( 
$doc[$column] ) ) {
// If MongoDB returns an array for a 
column,
// but the exact location of the value 
wasn't specified,
// do some extra processing.
@@ -438,11 +441,15 @@
}
} else {