Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-9452: Queue entities without checking revisions #185

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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