Skip to content

Commit

Permalink
Merge pull request #33 from AndreyMaximov/fix-out-of-memory
Browse files Browse the repository at this point in the history
fix(performance): Free entity.memory_cache so that it doesn't consume too much memory
  • Loading branch information
podarok authored Jul 10, 2023
2 parents 04a1b4a + 77d9bd3 commit ec2f679
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion openy_repeat.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ services:
- { name: pdf_generator }
openy_repeat.repository:
class: Drupal\openy_repeat\OpenyRepeatRepository
arguments: ['@entity_type.manager', '@config.factory', '@cache.default']
arguments: ['@entity_type.manager', '@config.factory', '@cache.default', '@entity.memory_cache']
7 changes: 6 additions & 1 deletion src/OpenyRepeatRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Drupal\Core\Cache\Cache;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\MemoryCache\MemoryCacheInterface;
use Drupal\Core\Cache\UseCacheBackendTrait;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Entity\EntityTypeManager;
Expand Down Expand Up @@ -47,15 +48,18 @@ class OpenyRepeatRepository implements OpenyRepeatRepositoryInterface {
* ConfigFactory.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
* The cache backend.
* @param \Drupal\Core\Cache\MemoryCache\MemoryCacheInterface $memory_cache
* The memory cache.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function __construct(EntityTypeManager $entity_type_manager, ConfigFactory $configFactory, CacheBackendInterface $cache_backend) {
public function __construct(EntityTypeManager $entity_type_manager, ConfigFactory $configFactory, CacheBackendInterface $cache_backend, MemoryCacheInterface $memory_cache) {
$this->entityTypeManager = $entity_type_manager;
$this->configFactory = $configFactory;
$this->cacheBackend = $cache_backend;
$this->nodeStorage = $this->entityTypeManager->getStorage('node');
$this->memoryCache = $memory_cache;
}

/**
Expand Down Expand Up @@ -130,6 +134,7 @@ public function getLocationsIds() {
$locationId = $session->get('field_session_location')->getString();
$locationsIds[$locationId] = $locationId;
}
$this->memoryCache->deleteAll();
}
return $locationsIds;
}
Expand Down

0 comments on commit ec2f679

Please sign in to comment.