Notice GetContentOfContentType will return IContent. Avoid those. UmbracoHelper.TypedContent will return IPublishedContent, which are what you typically want to deal with.
My parent id where I have my 5000 records is 31130 (Member Directory). Now the query comes back in under 15 seconds. var svc = Umbraco.TypedContent(31130);
Above, you were doing GetContentOfContentType(31130) and now you are doing Umbraco.TypedContent(31130). The first is an ID of a content type (aka, a document type) and the second is an ID of a content node. Yet, you are using the same number in both cases... that doesn't make sense. Output the value of svc.Name and svc.NodeId (or maybe it's just svc.Id... I forget). That'll probably show that you aren't dealing with the node you are expecting.
By the way, you can scan the content nodes and look at their node.DocumentTypeAlias to see if it is "MemberDirectory". I'd start at the root node and look at all descendants. You can get the root node by looking at UmbracoHelper.TypedContentAtRoot(). I think there is also an extension method on IPublishedContent called something like DescendantsAndSelf (you may need to include a namespace, like Umbraco.Core or Umbraco.Web or Umbraco.Models... I forget exactly).
API Performance is slow
I Used API to create and publish 5000 records in Umbraco tied to a content type.
The content type has 10 fields (all varchar(100)).
I then created a surface controller method to retrieve back all the rows.
But its now over 5 minutes and the results have not come back..
What am I doing wrong.
Here is the code.
Thanks
[System.Web.Http.AcceptVerbs("GET", "POST")]
[System.Web.Http.HttpGet]
public void getData()
{
string sDDA;
int iDocket;
var svc = ApplicationContext.Services.ContentService;
var items = svc.GetContentOfContentType(31130);
foreach (var m in items)
{
sDDA = m.GetValue<string>("dda");
iDocket = m.GetValue<int>("docket");
}
}
Don't use the content service. That hits the database. Use an instance of UmbracoHelper instead (that uses the XML cache).
Notice GetContentOfContentType will return IContent. Avoid those. UmbracoHelper.TypedContent will return IPublishedContent, which are what you typically want to deal with.
Still need help.
My parent id where I have my 5000 records is 31130 (Member Directory). Now the query comes back in under 15 seconds.
var svc = Umbraco.TypedContent(31130);
But svc.Children.Count() returns 0?
WHat am I missing here?
Thanks
Above, you were doing GetContentOfContentType(31130) and now you are doing Umbraco.TypedContent(31130). The first is an ID of a content type (aka, a document type) and the second is an ID of a content node. Yet, you are using the same number in both cases... that doesn't make sense. Output the value of svc.Name and svc.NodeId (or maybe it's just svc.Id... I forget). That'll probably show that you aren't dealing with the node you are expecting.
By the way, you can scan the content nodes and look at their node.DocumentTypeAlias to see if it is "MemberDirectory". I'd start at the root node and look at all descendants. You can get the root node by looking at UmbracoHelper.TypedContentAtRoot(). I think there is also an extension method on IPublishedContent called something like DescendantsAndSelf (you may need to include a namespace, like Umbraco.Core or Umbraco.Web or Umbraco.Models... I forget exactly).
I'm confused.
If I insert 5000 records this way (see below) using ID of 31130, what do I reference to retrieve the values?
Why does this not work?
var svc = Umbraco.TypedContent(31130);
for (int i = 0; i < 5000; i++)
{
var svc = ApplicationContext.Services.ContentService;
var s = svc.CreateContent("[" + i + "Member]", svc.GetById(31130), "Member");
s.SetValue("dda", i);
s.SetValue("docket", i+1000);
s.SetValue("nonbanknumber", 0);
s.SetValue("name", "[" + i + "John R.Doe]");
svc.SaveAndPublish(s);
}
I am using Umbraco.TypedContent(31130). as I was told not to use content service.
Nicholas:
I figured it out.
Thanks for your support eariler today.
is working on a reply...