I am facing the following issue that I have a simple Controller Rendering with which is using the Demo template with 1 field (Label) and if I switch to Debug Mode in Experience Editor then I can see that this component has 19 item reads. Is it normal that 1 item has that much item read? If it is normal, why?
Here is my whole implementation with Glass Mapper.
using System;
using System.Collections.Generic;
using Sitecore.Globalization;
namespace Foundation.GlassBase.Models
{
public interface IGlassBase
{
Guid Id { get; set; }
Language Language { get; }
int Version { get; set; }
IEnumerable<Guid> BaseTemplateIds { get; }
string TemplateName { get; }
Guid TemplateId { get; set; }
string Name { get; set; }
string Url { get; }
string FullPath { get; }
}
}
using Foundation.GlassBase.Models;
namespace Feature.Demo.Models
{
public interface IDemo : IGlassBase
{
string Label { get; }
}
}
using Glass.Mapper.Sc.Maps;
using Feature.Demo.Models;
using Foundation.GlassBase.Models;
namespace Feature.Demo.Maps
{
public class DemoMap : SitecoreGlassMap<IDemo>
{
public override void Configure()
{
Map(x =>
{
ImportMap<IGlassBase>();
x.Field(y => y.Label).FieldId(SitecoreTemplates.Demo.Label.FieldId);
});
}
}
}
using Glass.Mapper.Sc;
using Sitecore.Mvc.Presentation;
using Foundation.Alerts.Exceptions;
namespace Foundation.Data.Repositories
{
public class ItemRepository : IItemRepository
{
protected readonly ISitecoreContext _sitecoreContext;
public ItemRepository(ISitecoreContext sitecoreContext)
{
_sitecoreContext = sitecoreContext;
}
public T GetDatasourceItem<T>() where T : class
{
var datasource = _sitecoreContext.GetItem<T>(RenderingContext.Current.Rendering.DataSource);
if (datasource == null)
{
throw new InvalidDataSourceItemException();
}
return datasource;
}
}
}
using System.Web.Mvc;
using Feature.Demo.Models;
using Foundation.Data.Repositories;
namespace Feature.Demo.Controllers
{
public class DemoController : Controller
{
private readonly IItemRepository _itemRepository;
public DemoController(IItemRepository itemRepository)
{
_itemRepository = itemRepository;
}
public ViewResult Demo()
{
var datasource = _itemRepository.GetDatasourceItem<IDemo>();
return View("~/Views/Demo.cshtml", datasource);
}
}
}
@using Glass.Mapper.Sc.Web.Mvc
@model Feature.Demo.Models.IDemo
<div>
@Html.Glass().Editable(Model, m => m.Label)
</div>
Then I have the following row in Debug Mode:
IGlassBase
exceptID
and it is 8 item reads. I would like to know/do more deeply what's happening in the background.BaseTemplateIds
. That's why it's 19 - 8 -some more base templates items
. 19 item reads is not a problem. Sitecore caching mechanisms are really good. You don't need to worry about 19 item reads. If you have performance issues, don't look on 19 item reads. The problem will be in another placeIGlassBase
and use the combination of these interfaces like if I don't need the template ID in my feature then I don't need to use it. So I will have more base interfaces likeILanguage
,ITemplate
,IPath
and etc. only if you want maximize the optimizitaion. I don't say it make sense in any cases :)