Unverified Commit 8b9a7e5d authored by Alex Pott's avatar Alex Pott
Browse files

perf: #3564969 Static cache field storage definitions

By: catch
By: alexpott
(cherry picked from commit 43a14ed5)
parent a38db813
Loading
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -33,6 +33,13 @@ class EntityLastInstalledSchemaRepository implements EntityLastInstalledSchemaRe
   */
  protected $entityTypeDefinitions = NULL;

  /**
   * The loaded installed field storage definitions.
   *
   * @var array|null
   */
  protected $entityFieldStorageDefinitions = NULL;

  /**
   * Constructs a new EntityLastInstalledSchemaRepository.
   *
@@ -117,10 +124,15 @@ public function deleteLastInstalledDefinition($entity_type_id) {
   * {@inheritdoc}
   */
  public function getLastInstalledFieldStorageDefinitions($entity_type_id) {
    if (isset($this->entityFieldStorageDefinitions[$entity_type_id])) {
      return $this->entityFieldStorageDefinitions[$entity_type_id];
    }
    if ($cache = $this->cacheBackend->get($entity_type_id . '.field_storage_definitions.installed')) {
      $this->entityFieldStorageDefinitions[$entity_type_id] = $cache->data;
      return $cache->data;
    }
    $definitions = $this->keyValueFactory->get('entity.definitions.installed')->get($entity_type_id . '.field_storage_definitions', []);
    $this->entityFieldStorageDefinitions[$entity_type_id] = $definitions;
    $this->cacheBackend->set($entity_type_id . '.field_storage_definitions.installed', $definitions, Cache::PERMANENT);
    return $definitions;
  }
@@ -130,6 +142,7 @@ public function getLastInstalledFieldStorageDefinitions($entity_type_id) {
   */
  public function setLastInstalledFieldStorageDefinitions($entity_type_id, array $storage_definitions) {
    $this->keyValueFactory->get('entity.definitions.installed')->set($entity_type_id . '.field_storage_definitions', $storage_definitions);
    unset($this->entityFieldStorageDefinitions[$entity_type_id]);
    $this->cacheBackend->delete($entity_type_id . '.field_storage_definitions.installed');
  }

@@ -138,6 +151,7 @@ public function setLastInstalledFieldStorageDefinitions($entity_type_id, array $
   */
  public function setLastInstalledFieldStorageDefinition(FieldStorageDefinitionInterface $storage_definition) {
    $entity_type_id = $storage_definition->getTargetEntityTypeId();
    unset($this->entityFieldStorageDefinitions[$entity_type_id]);
    $definitions = $this->getLastInstalledFieldStorageDefinitions($entity_type_id);
    $definitions[$storage_definition->getName()] = $storage_definition;
    $this->setLastInstalledFieldStorageDefinitions($entity_type_id, $definitions);
@@ -150,6 +164,7 @@ public function deleteLastInstalledFieldStorageDefinition(FieldStorageDefinition
    $entity_type_id = $storage_definition->getTargetEntityTypeId();
    $definitions = $this->getLastInstalledFieldStorageDefinitions($entity_type_id);
    unset($definitions[$storage_definition->getName()]);
    unset($this->entityFieldStorageDefinitions[$entity_type_id]);
    $this->setLastInstalledFieldStorageDefinitions($entity_type_id, $definitions);
  }

+2 −2
Original line number Diff line number Diff line
@@ -129,11 +129,11 @@ protected function doTestNodePageAdministrator(): void {

    $expected = [
      'QueryCount' => 304,
      'CacheGetCount' => 324,
      'CacheGetCount' => 311,
      'CacheGetCountByBin' => [
        'config' => 66,
        'bootstrap' => 16,
        'discovery' => 108,
        'discovery' => 95,
        'data' => 23,
        'entity' => 25,
        'dynamic_page_cache' => 1,
+1 −1
Original line number Diff line number Diff line
@@ -53,7 +53,7 @@ protected function testFrontPageColdCache(): void {

    $expected = [
      'QueryCount' => 219,
      'CacheGetCount' => 289,
      'CacheGetCount' => 277,
      'CacheSetCount' => 295,
      'CacheDeleteCount' => 0,
      'CacheTagLookupQueryCount' => 25,