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.
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