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

Forums / Developing with Sitefinity / NEWBIE ALERT! Help me optimize this

NEWBIE ALERT! Help me optimize this

1 posts, 0 answered
  1. Simon
    Simon avatar
    10 posts
    Registered:
    08 Jun 2012
    10 Oct 2012
    Link to this post
    I want to apologize ahead of time but I am a newbie when it comes to .NET and i know enough but i am no way an expert.  That is where you guys come in...

    Is there a better way of writing this?   I feel like there is... Here is a snippet...

    Some notes:
    --LearningStyles,InstructionalStrategies,SpecializedInstructionalNeeds,GradeLevels, Subjects --> Telerik.OpenAccess.TrackedList
    --the Querystring are separated by PIPES of GUIDs
    --I just want to make this faster because the performance is slow first time around and running it again the second is fine.  it seems to slow down when i have more than 3



    /* SUBJECT -------------------------------------------------------------------------------------------------------------------------------------- */                    if( NarrowById ==  GuidsList.SubjectsTaxonomyId)                    {                        var companies = companiesManager.GetCompanies().Where(c => c.Subjects.Contains(NarrowByTaxaId));                        var resources = resourcesManager.GetCompanyResources().Where(r => r.IsActive == true && (r.Subjects.Contains(NarrowByTaxaId)));                        var grants = grantsManager.GetGrants().Where(r => r.Subjects.Contains(NarrowByTaxaId));                         /* START - FILTERS*/                        char[] splitter = { '|' };                        Guid _gl,_sc,_ls,_is,_sin;                        if (Request.QueryString["gl"] != null)                        {                            string[] queryStringValue = Request.QueryString["gl"].Split(splitter);                            foreach (string queryStringVal in queryStringValue)                            {                                if (Guid.TryParse(queryStringVal, out _gl))                                {                                    resources = resources.Where(r => r.GradeLevels.Contains(_gl));                                    companies = companies.Where(r => r.GradeLevels.Contains(_gl));                                    grants = grants.Where(r => r.GradeLevels.Contains(_gl));                                }                            }                        }                        if (Request.QueryString["sc"] != null)                        {                            string[] queryStringValue = Request.QueryString["sc"].Split(splitter);                            foreach (string queryStringVal in queryStringValue)                            {                                if (Guid.TryParse(queryStringVal, out _sc))                                {                                    resources = resources.Where(r => r.Subjects.Contains(_sc));                                    companies = companies.Where(r => r.Subjects.Contains(_sc));                                    grants = grants.Where(r => r.Subjects.Contains(_sc));                                }                            }                        }                        if (Request.QueryString["rt"] != null)                        {                            resources = resources.Where(r => Request.QueryString["rt"].Contains(r.ResourceType.ToString()));                        }                        if (Request.QueryString["c"] != null)                        {                            resources = resources.Where(r => Request.QueryString["c"].Contains(r.CompanyId.ToString()));                            companies = companies.Where(r => Request.QueryString["c"].Contains(r.Id.ToString()));                            grants = grants.Where(r => Request.QueryString["c"].Contains(r.CompanyId.ToString()));                        }                        if (Request.QueryString["ls"] != null)                        {                            string[] queryStringValue = Request.QueryString["ls"].Split(splitter);                            foreach (string queryStringVal in queryStringValue)                            {                                if (Guid.TryParse(queryStringVal, out _ls))                                {                                    resources = resources.Where(r => r.LearningStyles.Contains(_ls));                                    companies = companies.Where(r => r.LearningStyles.Contains(_ls));                                }                            }                        }                        if (Request.QueryString["is"] != null)                        {                            string[] queryStringValue = Request.QueryString["is"].Split(splitter);                            foreach (string queryStringVal in queryStringValue)                            {                                if (Guid.TryParse(queryStringVal, out _is))                                {                                    resources = resources.Where(r => r.InstructionalStrategies.Contains(_is));                                    companies = companies.Where(r => r.InstructionalStrategies.Contains(_is));                                }                            }                        }                        if (Request.QueryString["sin"] != null)                        {                            string[] queryStringValue = Request.QueryString["sin"].Split(splitter);                            foreach (string queryStringVal in queryStringValue)                            {                                if (Guid.TryParse(queryStringVal, out _sin))                                {                                    resources = resources.Where(r => r.SpecializedInstructionalNeeds.Contains(_sin));                                    companies = companies.Where(r => r.SpecializedInstructionNeeds.Contains(_sin));                                }                            }                        }                        /* END - FILTERS*/                                                  var resultset = companies.Select(c => new { Id = c.Id, DataType ="Companies", Sort = c.DateCreated })                             .Union(resources.Select(c => new { Id = c.Id, DataType ="Resources", Sort = c.DateCreated }));

1 posts, 0 answered