cache_monitor-1.0.x-dev/cache_monitor.install

cache_monitor.install
<?php

/**
 * Implements hook_schema().
 */
function cache_monitor_schema() {
  $schema['cache_monitor_request'] = [
    'description' => 'Cache per-request cache timing header.',
    'fields' => [
      'rid'      => ['type' => 'serial', 'not null' => TRUE],
      'created'  => ['type' => 'int', 'not null' => TRUE, 'description' => 'Unix timestamp'],
      'method'   => ['type' => 'varchar', 'length' => 10, 'not null' => TRUE],
      'uri'      => ['type' => 'varchar', 'length' => 1024, 'not null' => TRUE],
      'uid'      => ['type' => 'int', 'not null' => TRUE, 'default' => 0],
      'ip'       => ['type' => 'varchar', 'length' => 64, 'not null' => TRUE, 'default' => ''],
      // Optional request context (e.g. route name), nullable.
      'context'  => ['type' => 'varchar', 'length' => 255, 'not null' => FALSE],
    ],
    'primary key' => ['rid'],
    'indexes' => [
      'created' => ['created'],
      'uri'     => ['uri'],
      'uid'     => ['uid'],
    ],
  ];

  $schema['cache_monitor_metric'] = [
    'description' => 'Cache per-request cache timing rows by bin/op.',
    'fields' => [
      'id'     => ['type' => 'serial', 'not null' => TRUE],
      'rid'    => ['type' => 'int', 'not null' => TRUE],
      'bin'    => ['type' => 'varchar', 'length' => 190, 'not null' => TRUE],
      'backend'   => ['type' => 'varchar', 'length' => 190, 'not null' => TRUE, 'default' => ''],
      'op'     => ['type' => 'varchar', 'length' => 64, 'not null' => TRUE], // get, getMultiple, set, ...
      'calls'  => ['type' => 'int', 'not null' => TRUE, 'default' => 0],
      'items'  => ['type' => 'int', 'not null' => TRUE, 'default' => 0],
      'ms'     => ['type' => 'float', 'size' => 'big', 'not null' => TRUE, 'default' => 0],
      'ms_avg' => ['type' => 'float', 'size' => 'big', 'not null' => TRUE, 'default' => 0],
      'no_activity' => ['type' => 'int', 'not null' => TRUE, 'default' => 0], // boolean-ish
    ],
    'primary key' => ['id'],
    'indexes' => [
      'rid'     => ['rid'],
      'bin_op'  => ['bin', 'op'],
    ],
    'foreign keys' => [
      'rid_fk' => ['table' => 'cache_monitor_request', 'columns' => ['rid' => 'rid']],
    ],
  ];

  return $schema;
}

/**
 * Add backend column to metrics.
 */
function cache_monitor_update_9001() {
  $schema = \Drupal::database()->schema();
  if ($schema->tableExists('cache_monitor_metric') && !$schema->fieldExists('cache_monitor_metric', 'backend')) {
    $schema->addField('cache_monitor_metric', 'backend', [
      'type' => 'varchar',
      'length' => 190,
      'not null' => TRUE,
      'default' => '',
      'description' => 'Backend service id (e.g. cache.backend.apcu).',
    ]);
  }
}

/**
 * Implements hook_uninstall().
 */
function cache_monitor_uninstall() {
  \Drupal::database()->schema()->dropTable('cache_monitor_metric');
  \Drupal::database()->schema()->dropTable('cache_monitor_request');
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc