As seen from issue #1542150, we need abstraction in the bs queries to support no sql databases.

Need help in headstart to convert static queries into abstracted codebase.

Thanks

Comments

denny84’s picture

Correction:

* DB queries

not bs queries

pribeh’s picture

This would make a lot of sense since mongodb works with json. subscribe.

Anonymous’s picture

no, i'm not really interested in doing this.

however, i'd consider allowing modules to provide their own tokens.

michee.lengronne’s picture

I think it would be a good idea for a huge performance system to allow the nodejs server to query directly in mongodb.

It can be a common module dev between that module and the http://drupal.org/project/mongodb ?

Anonymous’s picture

Status: Active » Closed (won't fix)

nope.

Anonymous’s picture

Issue summary: View changes

It's a shame the maintainer has no interest in this; it would be an excellent feature. As it is I am at the moment faced with the dilemma of either abandoning the Redis cache backend I am using for sessions (by means of the Session Proxy module) or forgoing the use of this module.

Supposing I want to get this to work. This was mentioned: 'however, i'd consider allowing modules to provide their own tokens.' What would that entail, roughly?

Anonymous’s picture

For anyone wanting to use a NoSQL session backend with this module, here's how I did it.

I had to abandon Redis for session storage since it stores sessions in a manner very different from Drupal's core sessions. However, the MongoDB module's session backend is feasible, although I had to make a small patch to it.

The incompatibility of the nodejs module with other session backends lies in this function from nodejs.module, since it's a hard-coded db_query:

function nodejs_auth_check_callback($auth_token) {
  $sql = "SELECT uid FROM {sessions} WHERE MD5(sid) = :auth_key OR MD5(ssid) = :auth_key";
  return db_query($sql, array(':auth_key' => $auth_token))->fetchField();
}

This can be changed to a PHP MongoDB driver query to a MongoDB session storage collection. However, I couldn't find a Mongo equivalent to the MD5 in MySQL, so I had to do the md5 checksums in the MongoDB module & store them in the session documents instead. Here are the necessary changes to the mongodb_session.inc in the MongoDB module:

function _drupal_session_write($sid, $value) {
//...
$fields = array(
    'uid' => (int) $user->uid,
    'cache' => isset($user->cache) ? (int) $user->cache : 0,
    'hostname' => ip_address(),
    'session' => $value,
    'timestamp' => REQUEST_TIME,
    //Hacked by H.
    'sidmd5' => md5($sid),
    'ssidmd5' => md5($sid),
    //End hacked by H.
  );
//...
}

Finally, the new function in nodejs.module:

function nodejs_auth_check_callback($auth_token) {
  $session_backend = variable_get('cache_session');
  if (isset($session_backend) && $session_backend == 'DrupalMongoDBCache') {
    $collection = mongodb_collection(variable_get('mongodb_session', 'session'));
    $sess_scheme = variable_get('nodejs_server_scheme');
    if ($sess_scheme == 'https') {
      $session = $collection->findOne(array('ssidmd5' => $auth_token), array('uid'));
    }
    else {
      $session = $collection->findOne(array('sidmd5' => $auth_token), array('uid'));
    }
    $uid = $session['uid'];
    return $uid;
  }
  else {
    $sql = "SELECT uid FROM {sessions} WHERE MD5(sid) = :auth_key OR MD5(ssid) = :auth_key";
    return db_query($sql, array(':auth_key' => $auth_token))->fetchField();
  }
}

I know this won't be added to either module, but thought I'd share a useful hack with future visitors to this issue.

Anonymous’s picture

Status: Closed (won't fix) » Fixed

found another issue that wanted this, so just to be clear - you can use whatever code you like in place of nodejs_auth_check_callback().

put this in settings.php:

$conf['nodejs_auth_check_callback'] = 'my_mongo_nodejs_auth_callback';

then define 'my_mongo_nodejs_auth_callback' with whatever code you need.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.