You are here

public function Logger::ensureSchema in MongoDB 8.2

Ensure indexes are set on the collections and tracker collection is capped.

First index is on <line, timestamp> instead of <function, line, timestamp>, because we write to this collection a lot, and the smaller index on two numbers should be much faster to create than one with a string included.

File

modules/mongodb_watchdog/src/Logger.php, line 532

Class

Logger
Class Logger is a PSR/3 Logger using a MongoDB data store.

Namespace

Drupal\mongodb_watchdog

Code

public function ensureSchema() : void {
  $trackerCollection = $this
    ->ensureCappedCollection(static::TRACKER_COLLECTION, $this->requests * 1024);
  $indexes = [
    [
      'name' => 'tracker-request',
      'key' => [
        'request_id' => 1,
      ],
    ],
  ];
  $trackerCollection
    ->createIndexes($indexes);
  $indexes = [
    // Index for adding/updating increments.
    [
      'name' => 'for-increments',
      'key' => [
        'line' => 1,
        'changed' => -1,
      ],
    ],
    // Index for overview page without filters.
    [
      'name' => 'overview-no-filters',
      'key' => [
        'changed' => -1,
      ],
    ],
    // Index for overview page filtering by type.
    [
      'name' => 'overview-by-type',
      'key' => [
        'type' => 1,
        'changed' => -1,
      ],
    ],
    // Index for overview page filtering by severity.
    [
      'name' => 'overview-by-severity',
      'key' => [
        'severity' => 1,
        'changed' => -1,
      ],
    ],
    // Index for overview page filtering by type and severity.
    [
      'name' => 'overview-by-both',
      'key' => [
        'type' => 1,
        'severity' => 1,
        'changed' => -1,
      ],
    ],
  ];
  $this
    ->templateCollection()
    ->createIndexes($indexes);
}