-
Notifications
You must be signed in to change notification settings - Fork 4
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
[SD-360] Refactor ::getHierarchy #543
[SD-360] Refactor ::getHierarchy #543
Conversation
93bac1e
to
0f81655
Compare
@@ -181,53 +182,110 @@ public function getHierarchy(EntityInterface $entity, Request $request) { | |||
* The hierarchy. | |||
*/ | |||
protected function buildHierarchy(ContentEntityInterface $entity, NestedSetStorage $storage, CacheableMetadata $cache, $weight, array &$flatten_hierarchy, $site = NULL) { | |||
$resource_type = $this->resourceTypeRepository->get($entity->getEntityTypeId(), $entity->bundle()); | |||
// Try cache first. | |||
$cid = "tide_publication:hierarchy:{$entity->uuid()}:{$weight}:" . ($site ? $site->id() : 'null'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do these get surrounded by {}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @anthony-malkoun , it just clearly defines variable boundary in this string.
$hierarchy = [ | ||
// Cache the results. | ||
$cache_data = [ | ||
'hierarchy' => $hierarchy, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to save both here? You only use flatten
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This refactor confused me a bit at first! I wanted to build a hierarchical tree structure
while also maintaining a flattened array via the reference parameter
😇 . Anyway, I’ve removed the unnecessary calculation results.
Thanks for catching this issue!
$cid = "tide_publication:hierarchy:{$entity->uuid()}:{$weight}:" . ($site ? $site->id() : 'null'); | ||
if ($cached = $this->cacheData->get($cid)) { | ||
$cache->addCacheTags($cached->tags); | ||
$flatten_hierarchy = array_merge($flatten_hierarchy, $cached->data['flatten']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get this? Isn't flatten_hierarchy
derived from the node?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most of my comments are just questions, otherwise this looks fine and good to me.
hey @anthony-malkoun |
Jira
https://digital-vic.atlassian.net/browse/SD-360
Problem/Motivation
cache
::buildHierarchy
results. since::buildHierarchy
consumes a significant amount of resources, it's surprising that the results are not being cached~