From 96582e8e8c480b5c063465d6b6c6ee23f15aa6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20R?= Date: Mon, 25 Jun 2018 15:24:36 +0200 Subject: [PATCH] EZP-28956: Expose lazy loaded Location->getContent() on API for better DX (#2328) * Add SPI ContentHandler::loadContentList() for bulk loading content Note on cache: - By design here version is skipped, as use case for loading lots of content is in current version. - So one downside for cache here is that it won't reuse cache from load() method, causing cache to be duplcated in current design. Possible ways to remedy: - Force having to provide versions also on loadContentList() making it less efficient for some use cases (Page builder scenarios for instance) - Allow $version on load() to be false, or expose a loadContentInCurrentVersion() kind of method, either way adapt usage for this so cache will be shared. * Add Location->getContent() using lazy properties * [Integration] Add coverage for Location->getContent() * Change SearchService->findContent() to bulk load content Now that we have method to load several at once, take advantage in findContent(). * [ContentViewBuilder] Take advantage of Location->getContent() to avoid duplicate loading * Refactor for LoadStruct usage in SPI * fix review comments * Add internal ContentInfo proxy for ContentProxy usage * Make Trash item contain Content as well (as it extends Location) * Fix review comments * Don't use unset() on properties when they are no longer needed * Fix phpdoc on Abstract(Cache)Handler --- Persistence/Content/Handler.php | 15 ++++++++++ Persistence/Content/LoadStruct.php | 48 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 Persistence/Content/LoadStruct.php diff --git a/Persistence/Content/Handler.php b/Persistence/Content/Handler.php index 5b57c5c4d..00ae1fb90 100644 --- a/Persistence/Content/Handler.php +++ b/Persistence/Content/Handler.php @@ -67,6 +67,21 @@ public function createDraftFromVersion($contentId, $srcVersion, $userId); */ public function load($id, $version, array $translations = null); + /** + * Return list of unique Content, with content id as key. + * + * Missing items (NotFound) will be missing from the array and not cause an exception, it's up + * to calling logic to determine if this should cause exception or not. + * + * NOTE: Even if LoadStruct technically allows to load several versions of same content, this method does not allow + * this by design as content is returned as Map with key being content id. + * + * @param \eZ\Publish\SPI\Persistence\Content\LoadStruct[] $contentLoadStructs + * + * @return \eZ\Publish\SPI\Persistence\Content[] + */ + public function loadContentList(array $contentLoadStructs): array; + /** * Returns the metadata object for a content identified by $contentId. * diff --git a/Persistence/Content/LoadStruct.php b/Persistence/Content/LoadStruct.php new file mode 100644 index 000000000..c89c281a4 --- /dev/null +++ b/Persistence/Content/LoadStruct.php @@ -0,0 +1,48 @@ +