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

Add DimensionContentQueryEnhancer service #190

Conversation

alexander-schranz
Copy link
Member

@alexander-schranz alexander-schranz commented Jun 21, 2021

The DimensionContentQueryEnhancer will make it possible the Repository of a ContentRichEntity in our current case the Article. The DimensionContentQueryEnhancer provide all required filters like categories, tags, template keys which are used by smart content. Also it provide the logic how the select join work as they are very complex to select only the dimensions which are required to be performant. The current implementation is very imperformant as when a list is loaded all dimension content are loaded as separate queries and are not correctly joined.

@alexander-schranz alexander-schranz force-pushed the feature/dimension-content-query-enhancer branch 3 times, most recently from 0ff0dca to 2c5dc16 Compare June 22, 2021 16:02
@alexander-schranz alexander-schranz force-pushed the feature/dimension-content-query-enhancer branch 4 times, most recently from 26613be to 289d3d4 Compare June 23, 2021 08:33
@coveralls
Copy link

coveralls commented Jun 23, 2021

Pull Request Test Coverage Report for Build 1294915754

  • 119 of 119 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 1291214054: 0.0%
Covered Lines: 2025
Relevant Lines: 2025

💛 - Coveralls

* @param class-string<DimensionContentInterface> $dimensionContentClassName
* @param mixed[] $dimensionAttributes
*/
public function enhanceDimensionContentSelect(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you use this function in the SuluArticleBundle?
if not, i think i would keep the logic in the DimensionContentRepository for now.
if yes, i think i would call it addSelect/addEffectiveDimensionContentSelect 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will be used in the article bundle, but think I need first implement it here in the Example Bundle to also write tests for it.

@alexander-schranz alexander-schranz force-pushed the feature/dimension-content-query-enhancer branch from ec5b56e to 9c07160 Compare June 28, 2021 12:09
): void {
$effectiveAttributes = $dimensionContentClassName::getEffectiveDimensionAttributes($dimensionAttributes);
$this->addSortBy($queryBuilder, $effectiveAttributes);
$queryBuilder->addCriteria($this->getAttributesCriteria('dimensionContent', $effectiveAttributes));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should pass a dimensionContentAlias as parameter? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many other joins so I would not introduce a parameter for the aliases here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think i would add a ALIAS_DIMENSION_CONTENT constant then? 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not yet add any constant here for aliases.

$examples = $queryBuilder->getQuery()->getResult();

foreach ($examples as $example) {
yield $example;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there an advantage of yielding the results here instead of returning an array? 🤔

Copy link
Member Author

@alexander-schranz alexander-schranz Jul 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method should be refractored to us toIterator method of doctrine just need to test it. The advantage is a performance as if correctly used only 1 object instance is in memory why looping over it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently just used a custom Generator to make sure all works with a Generator.

@alexander-schranz alexander-schranz force-pushed the feature/dimension-content-query-enhancer branch from 9c07160 to 2e8fc42 Compare July 8, 2021 11:08
@alexander-schranz alexander-schranz force-pushed the feature/dimension-content-query-enhancer branch 2 times, most recently from 6a10002 to 7df8905 Compare September 14, 2021 09:25
@alexander-schranz alexander-schranz force-pushed the feature/dimension-content-query-enhancer branch from c69b7f5 to a820d3f Compare September 14, 2021 15:38
@alexander-schranz alexander-schranz force-pushed the feature/dimension-content-query-enhancer branch from 65a8c70 to 5e0867b Compare September 14, 2021 16:49
@alexander-schranz alexander-schranz added the DX Only affecting the end developer label Sep 14, 2021
@alexander-schranz alexander-schranz marked this pull request as ready for review September 14, 2021 17:02
@alexander-schranz alexander-schranz changed the title WIP: Add DimensionContentQueryEnhancer service Add DimensionContentQueryEnhancer service Sep 14, 2021
@alexander-schranz
Copy link
Member Author

@nnatter ready for review.

}

$effectiveAttributes = $dimensionContentClassName::getEffectiveDimensionAttributes($dimensionAttributes);
$this->addSortBy($queryBuilder, $effectiveAttributes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not sure if i would expect this method to change my sorting. you want to sort this to return the most specific DimensionContent first, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this also means that calling the addSelects method will lead to multiple rows per entity, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will remove this sorting. in the future maybe it make sense that we can sort specially for smart content by published date but that should be handled in a additional addSortBy method.

);
}

$locale = $dimensionAttributes['locale'] ?? null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think $dimensionAttributes is not defined anywhere? wondering why phpstan is okay with this? 🙈

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is false, funny that the test doesn't cover this

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did update it.


$contentFilters = [];
foreach ([
'locale',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be needed in every repository and makes it harder to extend things 😕

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can just pass all $filters to the dimensionContentQueryEnhancer?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or we could add a prefix for filters that should be passed to the dimensionContentQueryEnhancer? eg dimensionContent.categoryIds

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine currently to forward the filters directly to the enhancer

'dimensionContent'
);

$this->dimensionContentQueryEnhancer->addSelects(
Copy link
Contributor

@niklasnatter niklasnatter Sep 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will lead to multiple rows for a single example like described in #190 (comment), right? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed addSelect will just add the joined to relation and not create a new instance of the example object.

@alexander-schranz alexander-schranz force-pushed the feature/dimension-content-query-enhancer branch 2 times, most recently from 94bb509 to dd1a227 Compare October 1, 2021 11:37
/**
* @var DimensionContentInterface|null
*/
private $unlocalizedDimensionContent;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this are private variables which were just set but not used.

@alexander-schranz alexander-schranz force-pushed the feature/dimension-content-query-enhancer branch from dd1a227 to 15c63ee Compare October 1, 2021 11:48
@alexander-schranz alexander-schranz force-pushed the feature/dimension-content-query-enhancer branch from 15c63ee to d9497bd Compare October 1, 2021 11:49
@alexander-schranz
Copy link
Member Author

@nnatter Ready for rereview ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Only affecting the end developer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants