Why Ipublishcontent hitting Database
# help-with-umbraco
n
@{ var site2 = Model.Root(); var attendeesByUser = site2.Descendants().Where(x => x.Member != null && x.Member.Id == currMemberId).OrderBy(x => x.StartDate); } My Events @foreach (var att in attendeesByUser) { My Events } This above code hits DB and reaches CPU 100%. Umbraco version : 11
p
Your Descendants call basically goes through all of your nodes on the website. You should try to avoid Descendants and go through your tree with Children of other methods
What does your tree look like and what do you want to show?
n
I'd suggest the .Member call may be the issue. Perhaps move it to after the MemberId check.
d
It will be the member call. Try it without and compare.
n
ok thanks. I will give a go and will update
the Ya its member call. How do i optimised the code ? i have to compare current member id
Member picker should return IPublishedContent only so ideally should not hit DB
m
If you've got so many records that this is trashing your DB, i'd use the search index to get the items you need.
I'm with Patrick that you might not want to loop trough your entire site tree, so indeed, how's your tree set up?
n
Here is the tree structure - Events - Event Category 1 - Event 1 - Attendee - Attendee 1 ( Reference to Member) - Attendee 2 ( Reference to Member) - Event Category 2 - Event 1 - Attendee - Attendee 1 ( Reference to Member) - Attendee 2 ( Reference to Member) - Event Category 3 - Event 1 - Attendee - Attendee 1 ( Reference to Member) - Attendee 2 ( Reference to Member)
a My concern is att.Member ( member picker) is having performance issue but that is returning Ipublishcontent so why it would hit DB? seems like bug