2

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:

enter image description here

4
  • 3
    Is 19 read of items a problem? You must read rendering definition item, datasource, template, base templates, template fields items etc.
    – Marek Musielak
    Mar 15, 2017 at 14:09
  • @MarekMusielak For me it still sounds much for 1 item. Now I have removed the all properties from IGlassBase except ID and it is 8 item reads. I would like to know/do more deeply what's happening in the background. Mar 16, 2017 at 13:51
  • 1
    In Sitecore every field is an item. You removed 8 fields and one of them was 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 place
    – Marek Musielak
    Mar 16, 2017 at 15:12
  • @MarekMusielak thx for the clarification. don't have performance issues just I was curious in general how it counts. You are right! Totally forgot that field value count as an item read... maybe makes sense to split the IGlassBase 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 like ILanguage, ITemplate, IPath and etc. only if you want maximize the optimizitaion. I don't say it make sense in any cases :) Mar 16, 2017 at 15:22

1 Answer 1

2

Comments from our short discussion converted into an answer.

In Sitecore everything is an item. Template is an item, field is an item.

If your model contains 9 fields, using any of them counts as an item touch.

Also for BaseTemplateIds there will be a single item read for each of the base templates.

That's why for creating a model from a single item, Sitecore does multiple item reads (19 in your case).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.