-
Notifications
You must be signed in to change notification settings - Fork 13
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
Avoid hitting the database when rendering MNTP #8
Conversation
EntityService.GetObjectType() explicitly hits the database with zero caching. This method should generally be avoided in frontend rendering.
Awesome! I only changed to the method looking up each type due to issue #1 as there was no workaround. However I fixed the underlying issue in Umbraco for v7.2, hence why I just reworked it again. I will give your PR a good test with various situations and let you know. |
Cool. I tested it with all three node types and it seems to work.
|
Avoid hitting the database when rendering MNTP
…numerable and it's the same type when empty
Thanks for this, it works great. I made a small change to ensure that the return type is System.Linq.Enumerable for typed. The only difference with this version is that they now return "System.Linq.Enumerable+WhereListIterator" as previously they returned "System.Linq.Enumerable+WhereEnumerableIterator" I don't think this is a issue, any thoughts? |
Cool And nah, that shouldn't be an issue. I assume people will just use the return value as |
Nice work! 💯 |
That is some truly clever optimization! 💯 One thing I would note, which should solve your issue @Jeavon, is that you are returning a If you returned it using this little trick.
Then this is better because we are not returning a collection that can be cast back to p.s I'm totally stealing this. 😄 |
Steal away 😃 |
@JimBobSquarePants That's an interesting idea, I tried all sorts of things trying to get it to return System.Linq.Enumerable+WhereEnumerableIterator, with the skip it returns
|
@JimBobSquarePants p.s. I do have it returning Enumerable already, it's just the +ListIterator so I don't think the collection is modifiable. See here https://github.com/Jeavon/Umbraco-Core-Property-Value-Converters/blob/v2/Our.Umbraco.PropertyConverters/MultiNodeTreePickerPropertyConverter.cs#L136 |
@Jeavon Bugger. I didn't realise. Yeah, looks like that looks like it might work. You can't cast it back certainly. You could use an extension method if you want the exact same signature. Something like...
You should then be able to use the following.
|
That works, thanks @JimBobSquarePants ! |
No worries 😄 |
EntityService.GetObjectType()
is used in the property editor value converter for MNTP. This method explicitly hits the database with zero caching and should thus be avoided in frontend rendering.I can see you've made a few changes since 2.1.4 (which is used in the screenshots below) that will limit the number of DB hits to one per MNTP on a page. That's definitively better than one hit per selected node :) but still I think it's worth going an extra mile to avoid hitting the DB altogether.