Commit 17359414 authored by Crell's avatar Crell

Issue #2701473 by Crell: isLatestRevision() can just use getLatestRevisionId(), which is cheaper

Merge branch '2701473-revision-id' into 8.x-1.x
parents 3803b758 8ca49515
......@@ -173,29 +173,26 @@ class ModerationInformation implements ModerationInformationInterface {
/**
* {@inheritdoc}
*
* @todo Make this more performant.
*/
public function getDefaultRevisionId($entity_type_id, $entity_id) {
$storage = $this->entityTypeManager->getStorage($entity_type_id);
$entity = $storage->load($entity_id);
if ($entity) {
return $entity->getRevisionId();
if ($storage = $this->entityTypeManager->getStorage($entity_type_id)) {
$revision_ids = $storage->getQuery()
->condition($this->entityTypeManager->getDefinition($entity_type_id)->getKey('id'), $entity_id)
->sort($this->entityTypeManager->getDefinition($entity_type_id)->getKey('revision'), 'DESC')
->range(0, 1)
->execute();
if ($revision_ids) {
$revision_id = array_keys($revision_ids)[0];
return $revision_id;
}
}
}
/**
* {@inheritdoc}
*
* @todo There may be a more perfomant way of doing this that doesn't
* require loading the full entity revision.
*/
public function isLatestRevision(ContentEntityInterface $entity) {
$revision = $this->getLatestRevision($entity->getEntityTypeId(), $entity->id());
if (!$revision) {
return FALSE;
}
return $revision->getRevisionId() == $entity->getRevisionId();
return $entity->getRevisionId() == $this->getLatestRevisionId($entity->getEntityTypeId(), $entity->id());
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment