4

I'm currently trying to get all relation items for one parent by calling:

var items = ApplicationContext.Current.Services.RelationService.GetByParentId(members.GetCurrentMemberId()).ToArray();

It all works fine. Except when I look at the MiniProfiler, I can see it's firing off two queries per item, which is causing some major performance issues with larger amounts of items. MiniProfiler

I looked at the UmbracoCMS code and I found this piece of code:

protected override IEnumerable<IRelation> PerformGetByQuery(IQuery<IRelation> query)
{
    var sqlClause = GetBaseQuery(false);
    var translator = new SqlTranslator<IRelation>(sqlClause, query);
    var sql = translator.Translate();

    var dtos = Database.Fetch<RelationDto>(sql);

    foreach (var dto in dtos)
    {
        yield return Get(dto.Id);
    }
}

The foreach on the dtos is sending a query for each MoveNext() to the umbracoRelationType table. The Get() method actually queries the individual item from the umbracoRelation table. I think it's supposed to utilize the cache there, but evidently it's not.

Anyway. How do I improve performance here? Can I somehow get to the content in just a single query without completely bypassing Umbraco?

I'm using Umbraco 7.2.6

Sam7
  • 3,382
  • 2
  • 34
  • 57
  • 3
    Maybe ask the same question on http://our.umbraco.org - or, ultimately, create an issue on http://issues.umbraco.org/ ? I know that won't automagically solve your problem, but maybe getting more eyes on it can get you closer :-) – Jannik Anker Jul 08 '15 at 06:38
  • Thanks. I submitted the issue here: http://issues.umbraco.org/issue/U4-6801 – Sam7 Jul 08 '15 at 07:44
  • Your MiniProfiler profile screenshot starts at 40s! I'm more interested in what happens in that time rather than during the snippet you've posted. – csharpforevermore Oct 16 '15 at 02:30

1 Answers1

0

I would recommend getting the parent node or Id - and then using

ApplicationContext.Services.RelationService.GetById(parent.Id)
as it suffers from less database queries.
csharpforevermore
  • 1,472
  • 15
  • 27