Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 161 posts 322 karma points
    Feb 04, 2015 @ 21:36
    Tom
    0

    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");

                }

            }

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Feb 04, 2015 @ 23:59
    Nicholas Westby
    0

    Don't use the content service. That hits the database. Use an instance of UmbracoHelper instead (that uses the XML cache).

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Feb 04, 2015 @ 23:59
    Nicholas Westby
    0

    Notice GetContentOfContentType will return IContent. Avoid those. UmbracoHelper.TypedContent will return IPublishedContent, which are what you typically want to deal with.

  • Tom 161 posts 322 karma points
    Feb 05, 2015 @ 13:04
    Tom
    0

    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

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Feb 05, 2015 @ 14:26
    Nicholas Westby
    0

    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).

  • Tom 161 posts 322 karma points
    Feb 05, 2015 @ 16:06
    Tom
    0

    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.

     


  • Tom 161 posts 322 karma points
    Feb 05, 2015 @ 21:11
    Tom
    0

    Nicholas:

     

    I figured it out.  

    Thanks for your support eariler today.

Please Sign in or register to post replies

Write your reply to:

Draft