Version 1
[yaffs-website] / web / core / modules / node / src / NodeStorageSchema.php
diff --git a/web/core/modules/node/src/NodeStorageSchema.php b/web/core/modules/node/src/NodeStorageSchema.php
new file mode 100644 (file)
index 0000000..ac45bb5
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+namespace Drupal\node;
+
+use Drupal\Core\Entity\ContentEntityTypeInterface;
+use Drupal\Core\Entity\Sql\SqlContentEntityStorageSchema;
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+
+/**
+ * Defines the node schema handler.
+ */
+class NodeStorageSchema extends SqlContentEntityStorageSchema {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $reset = FALSE) {
+    $schema = parent::getEntitySchema($entity_type, $reset);
+
+    $schema['node_field_data']['indexes'] += [
+      'node__frontpage' => ['promote', 'status', 'sticky', 'created'],
+      'node__title_type' => ['title', ['type', 4]],
+    ];
+
+    return $schema;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $storage_definition, $table_name, array $column_mapping) {
+    $schema = parent::getSharedTableFieldSchema($storage_definition, $table_name, $column_mapping);
+    $field_name = $storage_definition->getName();
+
+    if ($table_name == 'node_revision') {
+      switch ($field_name) {
+        case 'langcode':
+          $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
+          break;
+
+        case 'revision_uid':
+          $this->addSharedTableFieldForeignKey($storage_definition, $schema, 'users', 'uid');
+          break;
+      }
+    }
+
+    if ($table_name == 'node_field_data') {
+      switch ($field_name) {
+        case 'promote':
+        case 'status':
+        case 'sticky':
+        case 'title':
+          // Improves the performance of the indexes defined
+          // in getEntitySchema().
+          $schema['fields'][$field_name]['not null'] = TRUE;
+          break;
+
+        case 'changed':
+        case 'created':
+          // @todo Revisit index definitions:
+          //   https://www.drupal.org/node/2015277.
+          $this->addSharedTableFieldIndex($storage_definition, $schema, TRUE);
+          break;
+      }
+    }
+
+    return $schema;
+  }
+
+}