Command “timing out” during Sitecore automated ite

2019-09-02 21:35发布

问题:

I have a command that I've added to a "national" node in the Sitecore Editor. The command generates a list of the 50 state nodes beneath it. It then goes through the state nodes (1 at a time) and generates a list of local nodes under each state node. Within the lists of local nodes, I iterate through them and check if the new item exists - if it does not, I add (create) it as a child under the local node. Ultimately, there are nearly 300 local items that are being added during the course of this command.

Is there a more efficient way to do this (fast query to get the 300 local nodes into one list, then check if the item exists, and create it)? If so, I'm not sure how to do that...

I'm not sure what is the most costly part of the operation. Ultimately, I'm still doing up to 300 separate queries to check if it's there, followed by insert statements, so that may still take a while to run. If so, which setting in web config will increase the applicable "timeout" setting in Sitecore? The sample structure is as follows:

//Derive the template from the name of the item (page) that was passed in - this assumes that the template name and the item name are the same
Sitecore.Data.Database database = Sitecore.Data.Database.GetDatabase("master");                

TemplateItem contentPageTemplate = database.SelectSingleItem("fast:/sitecore/Templates/User Defined/Home/Pages/Local Site/" + newPage);

Sitecore.Data.Items.Item[] stateNodes = null;
Sitecore.Data.Items.Item[] localNodes = null;
Item localHomePage = null;
Item newLocalPage = null;
int webBusinessID = 0;
string ID = "";
WebBusiness business;

//Get all of the immediate child nodes (state pages) under the "parent" node ("National Locations") - and put them into a list or array                

stateNodes = database.SelectItems("fast:/sitecore/content/Home/National Locations/*");

for (int i = 0; i < stateNodes.Length; i++)
{ 

  if (stateNodes[i].Children.Count > 0)
  {
    localNodes = database.SelectItems("fast:/sitecore/content/Home/National Locations/" + stateNodes[i].Fields["State Abbreviation"].ToString() + "/*");
  }
  else
  {
    //Do nothing
  }                   

  for (int j = 0; j < localNodes.Length; j++)
  {
    localHomePage = localNodes[j];

    if (localHomePage.Publishing.IsPublishable(DateTime.Now, false) == true)                        
    {   

      //If the new page does not exist, create it
      if (localHomePage.Children[newPage] == null)
      {
        newLocalPage = localHomePage.Add(newPage, contentPageTemplate);
        counter = counter + 1;
      }
      else
      {
        //Additional business logic
      }
    }
  }
}

回答1:

Unless I'm missing logic/code you don't have there, I think you can simply trim this down to one query to get to the local nodes by changing the XPath:

localNodes = database.SelectItems("fast:/sitecore/content/Home/National Locations/*/*");

The change is to get all immediate sub-items of the immediate sub-items of "National Locations"



标签: sitecore