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 support for caching fetched relations with Criteria #2090

Merged
merged 10 commits into from
Apr 6, 2020

Conversation

bahusoid
Copy link
Member

Follow up to #1952
As for Criteria it's much simpler to collect entities that are already present in ResultTypes (and so in cache) I've reversed original implementation - and instead of additional entities to cache provide entities that already cached. And additional entities (fetched entities and collections) are calculated automatically.

@@ -55,7 +55,6 @@ public void InitializeDerivedSelectClause(FromClause fromClause)

ASTAppender appender = new ASTAppender(ASTFactory, this); // Get ready to start adding nodes.
int size = fromElements.Count;
List<IType> sqlResultTypeList = new List<IType>(size);
Copy link
Member Author

Choose a reason for hiding this comment

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

Small unrelated clean up

@bahusoid bahusoid changed the title Add support for caching fetched relations with Criteria WIP Add support for caching fetched relations with Criteria Mar 27, 2019
@bahusoid

This comment has been minimized.

@bahusoid
Copy link
Member Author

bahusoid commented Mar 27, 2019

Nope. I'm wrong. Transformers are applied in both cases before caching. All we need is hql query with fetches and additional data in output and transformer that modifies number of objects in results. So something like this fails in hql on master too:

var list = session.CreateQuery("select o.Customer.CompanyName, o from Order o join fetch o.Customer")
         .SetCacheable(true)
         .SetResultTransformer(new RootEntityResultTransformer())
         .List<object>();

@bahusoid
Copy link
Member Author

So the issue: QueryCacheResultBuilder builds results based on loader.ResultTypes. It expects count to match provided tuple. But user transformer can modify tuple size (RootEntityResultTransformer is one example) and that breaks QueryCacheResultBuilder.AddRow logic.

The fix: put in cache untransformed results for queries that recognized as "queries with fetched relations"

@bahusoid bahusoid changed the title WIP Add support for caching fetched relations with Criteria Add support for caching fetched relations with Criteria Mar 27, 2019
@bahusoid
Copy link
Member Author

bahusoid commented Mar 28, 2019

Found another cache quirk. Entities returned in hql/linq projections (like Select(x => x.Customer)) are not cached. See added test ProjectedEntitiesAreCachable

Though this issue is unrelated to changes here or in #1952. As this query doesn't have fetches and processed by old logic.

@bahusoid bahusoid force-pushed the criteriaFetchCache branch from e454d82 to 384c145 Compare March 28, 2019 07:55
@bahusoid

This comment has been minimized.

Copy link
Member

@fredericDelaporte fredericDelaporte left a comment

Choose a reason for hiding this comment

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

I have rebased for fixing conflicts.

public class QueryOverCacheableTests : CriteriaNorthwindReadonlyTestCase
{
//Just for discoverability
private class CriteriaCacheableTest{}
Copy link
Member

Choose a reason for hiding this comment

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

I do not get what is its purpose.

Copy link
Member Author

@bahusoid bahusoid Apr 5, 2020

Choose a reason for hiding this comment

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

To make it appear in search when user enters Criteria trying to find some Criteria related tests

Copy link
Member

@fredericDelaporte fredericDelaporte Apr 5, 2020

Choose a reason for hiding this comment

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

Can-it be just a comment, not a dummy class?
Or do we need really need it anyway? It is there just because query-over is an added layer to criteria and so test it by the way, isn't-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.

Can-it be just a comment, not a dummy class?

When I'm not sure which test fixture I need I often try to find fixture class I need by some keywords. So comment is less discoverable than dummy class. Well if you really dislike it - you can drop it.

It is there just because query-over is an added layer to criteria and so test it by the way, isn't-it?

Yes.

@bahusoid
Copy link
Member Author

bahusoid commented Apr 5, 2020

And why bug? IMHO it's a new feature

@fredericDelaporte
Copy link
Member

I have classified it as bug for consistency with #1195 which was fixed by #1952. It was considered there that not caching fetches in Linq was a bug, so why not doing the same for criteria/query-over? Otherwise we should re-qualify #1195.

@fredericDelaporte fredericDelaporte added this to the 5.3 milestone Apr 5, 2020
@bahusoid
Copy link
Member Author

bahusoid commented Apr 5, 2020

It was considered there that not caching fetches in Linq was a bug, so why not doing the same for criteria/query-over

Hm... Ok. I didn't pay attention how it was classified for Linq/hql. But if re-qualifying means only changing labels - let's re-qualify. IMO those PRs should be stated in release in New Features list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants