You are here

public static function MongodbServiceProvider::createIndexes in MongoDB 8

Ensures indexes on various Mongo collections.

Parameters

MongoCollectionFactory $mongo:

array $settings:

2 calls to MongodbServiceProvider::createIndexes()
MongodbServiceProvider::alter in src/MongodbServiceProvider.php
Modifies existing service definitions.
mongodb_install in ./mongodb.install
Implements hook_install().

File

src/MongodbServiceProvider.php, line 63
Definition of Drupal\mongodb\MongodbServiceProvider..

Class

MongodbServiceProvider
MongoDB service provider. Registers Mongo-related services.

Namespace

Drupal\mongodb

Code

public static function createIndexes(MongoCollectionFactory $mongo, array $settings = NULL) {

  // Flood indexes.
  $mongo
    ->get('flood')
    ->ensureIndex(array(
    'event' => 1,
    'identifier' => 1,
    'timestamp' => 1,
    'expiration' => 1,
  ));
  if (isset($settings['flood']['ttl'])) {
    $ttl = $settings['flood']['ttl'];
  }
  else {
    $ttl = 300;
  }
  $mongo
    ->get('flood')
    ->ensureIndex(array(
    'expiration' => 1,
  ), array(
    'expireAfterSeconds' => $ttl,
  ));

  // File usage indexes
  $mongo
    ->get('file_usage')
    ->ensureIndex(array(
    'fid' => 1,
    'module' => 1,
    'type' => 1,
    'id' => 1,
    'count' => 1,
  ));
  $mongo
    ->get('file_usage')
    ->ensureIndex(array(
    'fid' => 1,
    'module' => 1,
    'count' => 1,
  ));
  $mongo
    ->get('file_usage')
    ->ensureIndex(array(
    'fid' => 1,
    'count' => 1,
  ));

  // Path alias. This should cover all queries via index intersections.
  $mongo
    ->get('url_alias')
    ->ensureIndex(array(
    'alias' => 1,
  ));
  $mongo
    ->get('url_alias')
    ->ensureIndex(array(
    'source' => 1,
  ));
  $mongo
    ->get('url_alias')
    ->ensureIndex(array(
    'langcode' => 1,
    '_id' => 1,
  ));
  $mongo
    ->get('url_alias')
    ->ensureIndex(array(
    'langcode' => -1,
    '_id' => 1,
  ));
}