3

I am trying to get all the components and their data using Tridion Core services. Here is the code.

SearchQueryData filter = new SearchQueryData();
filter.FullTextQuery = "Sample";
filter.ItemTypes = new ItemType[] { ItemType.Component };
filter.SearchIn = new LinkToIdentifiableObjectData() { IdRef = ARTICLE_FOLDER_URI };

BasedOnSchemaData articleSchema = new BasedOnSchemaData();
articleSchema.Schema = new LinkToSchemaData() { IdRef = ARTILCE_SCHEMA_URI };
articleSchema.Field = "Author";
articleSchema.FieldValue = "Ravi*";

filter.BasedOnSchemas = new BasedOnSchemaData[] { articleSchema };
var results = _client.GetSearchResults(filter); // Here I got results based on the filters, but it has only TCMIds
foreach (var comp in results)
{
    var item = (ComponentData)comp; //Here item.Content is null. 
}

This code gives me search results with TCM ids only. How do I get the component data also? (_client.Read(tcmId, new ReadOptions()); I can use this method to get the component data, but again I am hitting the database for individual items, which I don't want.

4

SDL Tridion doesn't provide a method to bulk-load components. When loading items from an OrganizationalItem (like a folder) you can use .GetItems which will load all the objects, but under the hood it's still hitting the database for each individual items anyway.

In other words, that's the way it (currently) is.

2

I see that you are concerned with the performance as well. You may think of using the GetListXml method of Core Service.

The code that is working and tested for me to retrieve even all the component of a publication or a folder with huge numbers of component with all the detail is as below -

public XElement GetItems(string tcmURI)
{
   TcmUri tcm = new TcmUri(tcmURI);
   ItemType type = tcm.ItemType;

   XElement componentXMLList = null;
   switch (type)
   {
      case ItemType.Publication:
        RepositoryItemsFilterData pubFilter = new RepositoryItemsFilterData();
        pubFilter.ItemTypes = new[] { CS_ItemType.Component };
        pubFilter.Recursive = true;
        componentXMLList = client.GetListXml(tcmURI, pubFilter);
        break;
      case ItemType.Folder:
        OrganizationalItemItemsFilterData folderFilter = new OrganizationalItemItemsFilterData();
        folderFilter.ItemTypes = new[] { CS_ItemType.Component };
        folderFilter.Recursive = true;
        componentXMLList = client.GetListXml(tcmURI, folderFilter);
        break;

    }


   return componentXMLList;
}

You can further parse this XML information to retrieve any component detail.

  • Thank you for suggestion, right now it's searching sub folders. In my case, I need actual component data of all components not just tcm Uris(in one call). – Ravi Gadag Jan 2 '15 at 11:30
  • The actual Component data is stored behind the scene in the form of XML and the above code will give all XML content (the really actual component data) and not only the TCM URI – Pankaj Gaur Jan 3 '15 at 13:57
1

What reason do you have for assuming the database query overhead is so large that it would offer a significant performance boost if you could bulk-load the data? The potential performance issues here are more likely due to ineffective caching strategies or redundant lookups...

If your code is really that sensitive to performance I would suggest bypassing the entire webservice layer as the HTTP request overhead is most likely larger than the database query overhead to begin with; if you only intend to read data you could try using the TOM.Net API (which does not use HTTP requests) or you could be one of the rare cases where API access does not meet your needs and you end up querying the database directly (you could bulk-load data using a custom stored procedure) but be aware that that of course affects your upgrade path and support options with SDL...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.