We're making use of the LocalDatasource module in our build.

It works fine apart from one particular template.

The local_datasource_content field gets populated on the master index, but it is empty on the web after publishing.

I have added some logging to the computed field in the module:

        var dataSources = item.GetLocalDatasourceDependencies();

        if (dataSources == null || !dataSources.Any())
            Log.Info($"LocalDatasourceContentField: No local datasource content found for item {item.ID}", this);

        var result = new StringBuilder();
        foreach (var dataSource in dataSources)
            foreach (var field in dataSource.Fields.Where(this.ShouldIndexField))

        var content = result.ToString();

        Log.Info($"LocalDatasourceContentField: Content for item {item.ID} : {content}", this);

        return content;

When I save the item in the content editor, I can see that field is gathering the content correctly and I see:

ManagedPoolThread #4 14:57:57 INFO LocalDatasourceContentField: Content for item {83CD49F5-C730-4459-A01F-2F2316217BD6} : <p>Rich Text Content</p>

However, when I publish the same item I see:

2018-01-23T14:58:14.177 ManagedPoolThread #3 14:58:14 INFO LocalDatasourceContentField: No local datasource content found for item {83CD49F5-C730-4459-A01F-2F2316217BD6}

So the computed field is being hit OK, but it doesn't seem to find the dependencies.

I have checked the web db to make sure the child datasources have indeed been published - they have.

The dependencies are fetched through the links database using:

var references = Globals.LinkDatabase.GetReferences(item);

So I have rebuilt the links database, but it still doesn't populate the field in the index after publishing.

The strange thing is that it seems to work fine for other templates - but I can't see what would cause the issue with this particular template.


I have added extra logging in the GetLocalDatasourceDependencies() extension method:

      var hasLocalDatasourceFolder = item.HasLocalDatasourceFolder();

        Log.Info($"GetLocalDatasourceDependencies: {item.ID} - hasLocalDatasourceFolder: {hasLocalDatasourceFolder}", typeof(ItemExtensions));

        if (!hasLocalDatasourceFolder)
            return new Item[] { };

        var references = Globals.LinkDatabase.GetReferences(item);

        Log.Info($"GetLocalDatasourceDependencies: {item.ID} - references count: {references.Count()}", typeof(ItemExtensions));

        var itemLinks = references
            .Where(r => (r.SourceFieldID == FieldIDs.LayoutField || r.SourceFieldID == FieldIDs.FinalLayoutField) && r.TargetDatabaseName == item.Database.Name)

        Log.Info($"GetLocalDatasourceDependencies: {item.ID} - itemLinks count: {itemLinks.Count} - DB: {item.Database.Name}", typeof(ItemExtensions));

        var localDatasourceItems = itemLinks
            .Select(l => l.GetTargetItem())
            .Where(i => i != null && i.IsLocalDatasourceItem(item))

        Log.Info($"GetLocalDatasourceDependencies: {item.ID} - localDatasourceItems count: {itemLinks.Count}", typeof(ItemExtensions));

And this shows that it is indeed the Globals.LinkDatabase.GetReferences(item) line that is not returning any items, rather than any subsequent predicate conditions.

When saving the item I can see:

INFO GetLocalDatasourceDependencies: {83CD49F5-C730-4459-A01F-2F2316217BD6} - localDatasourceItems count: 22
INFO GetLocalDatasourceDependencies: {83CD49F5-C730-4459-A01F-2F2316217BD6} - itemLinks count: 22 - DB: master
INFO GetLocalDatasourceDependencies: {83CD49F5-C730-4459-A01F-2F2316217BD6} - references count: 24
INFO GetLocalDatasourceDependencies: {83CD49F5-C730-4459-A01F-2F2316217BD6} - hasLocalDatasourceFolder: True

And then publishing:

INFO GetLocalDatasourceDependencies: {83CD49F5-C730-4459-A01F-2F2316217BD6} - localDatasourceItems count: 0
INFO GetLocalDatasourceDependencies: {83CD49F5-C730-4459-A01F-2F2316217BD6} - itemLinks count: 0 - DB: web
INFO GetLocalDatasourceDependencies: {83CD49F5-C730-4459-A01F-2F2316217BD6} - references count: 0
INFO GetLocalDatasourceDependencies: {83CD49F5-C730-4459-A01F-2F2316217BD6} - hasLocalDatasourceFolder: True

So I have to conclude there is some sort of issue with the links database. But I have rebuilt the links database and the problem persists.

  • Did you check what the code inside the extension method GetLocalDatasourceDependencies returns, specifically ` var itemLinks = Globals.LinkDatabase.GetReferences(item).Where(r => (r.SourceFieldID == FieldIDs.LayoutField || r.SourceFieldID == FieldIDs.FinalLayoutField) && r.TargetDatabaseName == item.Database.Name);`. My guess that one of those conditions could give you some insights.
    – Marco
    Jan 23 '18 at 18:06
  • What makes this more strange and difficult is that it only happens on our QA environment, which is split between a CM & CD. Locally it works fine. But I can't really see anything in those conditions that would cause it not to find the referenced items, particularly for one specific template type Jan 24 '18 at 9:03

Issue resolved on Slack chat.

Turns out, LinkDatabase was set to point to "web" on the CD environment, but "core" on CM environment. Updates and rebuilds of the LinkDatabase did not propagate across to the CD environment, and this was the root cause.

<LinkDatabase type="Sitecore.Data.SqlServer.SqlServerLinkDatabase, Sitecore.Kernel"><param connectionStringName="web"/></LinkDatabase>

This line was patched in, on the configuration on the CD environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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