Skip to content

Commit

Permalink
Merge pull request #185 from City-of-Helsinki/UHF-9452
Browse files Browse the repository at this point in the history
UHF-9452: Queue entities without checking revisions
  • Loading branch information
tuutti authored Nov 22, 2024
2 parents bed9714 + 2ffc309 commit d5d46f3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 6 additions & 3 deletions helfi_api_base.module
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,18 @@ function helfi_api_base_entity_update(EntityInterface $entity) : void {
if (!$revisionManager->entityTypeIsSupported($entity->getEntityTypeId())) {
return;
}
$revisions = $revisionManager->getRevisions($entity->getEntityTypeId(), $entity->id());
static $cache = [];

// Queue entity revisions for deletion.
if ($revisions) {
$key = sprintf('%s-%s', $entity->getEntityTypeId(), $entity->id());

// Only queue entity once per request.
if (!isset($cache[$key])) {
$queue = \Drupal::queue('helfi_api_base_revision');
$queue->createItem([
'entity_id' => $entity->id(),
'entity_type' => $entity->getEntityTypeId(),
]);
$cache[$key] = TRUE;
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/src/Kernel/Entity/Revision/RevisionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function testRevision() : void {
->save();

$this->assertCount(0, $this->getSut()->getRevisions('remote_entity_test', $entity->id()));
$this->assertQueueItems(0);
$this->assertQueueItems(1);

for ($i = 0; $i < 10; $i++) {
$rmt = $storage->load($entity->id());
Expand All @@ -162,8 +162,8 @@ public function testRevision() : void {

$storage->createRevision($rmt)->save();
}
// Make sure items are queued on entity update.
$this->assertQueueItems(5);
// Make sure items are only queued once per request.
$this->assertQueueItems(1);

$revisions = $this->getSut()->getRevisionsPerLanguage('remote_entity_test', $entity->id());

Expand Down

0 comments on commit d5d46f3

Please sign in to comment.