+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Problem linking modules

Problem linking modules

4 posts, 0 answered
  1. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    07 Jan 2011
    Link to this post
    Hi,

    I have two custom modules, with the following metakeys:

    MembersModule
    - Name
    - County
    - UserID

    PublicationsModule
    - Name
    - UserID

    A Publication can be linked back to a Member via the UserID metakey.

    I need to produce a pageable set of results for "All Publications WHERE County = 'London'". The only way I have been able to do this is to loop through all Members, then search for Publications with the matching UserID. The problem is this code is taking about 6 seconds to run - so is not possible on a production site.

    My code is:
    //create an instance of the membersModule content manager
    ContentManager oMembersMgr = new ContentManager(MembersManager.DefaultContentProvider);
     
    //create an empty filter
    List<IMetaSearchInfo> oMembersFilter = new List<IMetaSearchInfo>();
     
    //only filter on county if one has been provided
    if (!string.IsNullOrEmpty(this._county)) {
     
        //create a filter on county (or Wildcard)
        oMembersFilter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "ContactCounty", ((this._county == Convert.ToString(0)) ? "%" : this._county), SearchCondition.Equal, JoinType.And));
     
    }
     
    //get the members
    IList oMembers = oMembersMgr.GetContent(0,0, "Name ASC", ContentStatus.Published, oMembersFilter.ToArray());
     
    //create an empty list for storing the publications
    IList oPublications = new List<IContent>();
     
    //loop through each member
    foreach (IContent oMember in oMembers) {
     
        //create an instance of the publicationsModule content manager
        ContentManager oPublicationsMgr = new ContentManager(PublicationsManager.DefaultContentProvider);
        List<IMetaSearchInfo> oPublicationsFilter = new List<IMetaSearchInfo>();
        oPublicationsFilter.Add(new MetaSearchInfo(MetaValueTypes.ShortText, "UserID", oMember.GetMetaData("UserID").ToString(), SearchCondition.Equal));
        IList oResults = oPublicationsMgr.GetContent(0, 0, "Name ASC", ContentStatus.Published, oPublicationsFilter.ToArray());
     
        foreach (IContent oResult in oResults) {
     
            oPublications.Add(oResult);
     
        }
     
    }

    Is there a better, more efficient way of doing this?

    Thanks
    higgsy
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    07 Jan 2011
    Link to this post
    Hello higgsy,

    If you can add some filter when you get "oMembers " this will give you less results depending on the users query. Another option is using some control that supports paging like RadGrid and  you can return portion of users - say by 50 per page.

    All the best,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. higgsy
    higgsy avatar
    336 posts
    Registered:
    05 Aug 2010
    07 Jan 2011
    Link to this post
    Hi Ivan,

    I could get the first 10 oMembers which would massively reduce the load time, however this present two problems:

    - Not all members have a Publication, therefore even though I return 10 records, only 5 of them might be relevant
    - Without checking each oMember to see whether there is a correlating Publication, it is impossible for me to tell the pager how many pages there should be.

    Is there literally no other way? It's such a common requirement to be able to cross reference data.

    Thanks
    higgsy
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    09 Dec 2016
    10 Jan 2011
    Link to this post
    Hi higgsy,

    You can create two filters and then call oMembersMgr.GetContent(0,0, "Name ASC", ContentStatus.Published, combinedFilter.ToArray());

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Register for webinar
4 posts, 0 answered