I figured this out.
I made the update to change the value of LinkDatabase.MaximumBatchSize to 1000 as suggested and it didn't work.
<sitecore>
<settings>
<setting name="LinkDatabase.MaximumBatchSize">
<patch:attribute name="value">1000</patch:attribute>
</setting>
</settings>
</sitecore>
I then looked at the console in more detail in Chrome and saw this error:
"Error during serialization or deserialization using the JSON
JavaScriptSerializer. The length of the string exceeds the value set
on the maxJsonLength property."
After some Googling I found I can update this via the web.config like so:
<system.web.extensions xdt:Transform="Insert">
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647"/>
</webServices>
</scripting>
</system.web.extensions>
Again this didn't work :-(. I think the Json Serialization code ignores this setting.
Then I came across this Blog Post by Dirk Schäfauer:
https://seitenkern.com/2014/03/28/sitecore-7-mvc-json-serialization-and-maxjsonlength/
This post says I need A custom JsonSerializer, a PreprocessRequest Pipeline and .config to patch in my pipeline. This code is outdated for 8.1 though so I've updated it below:
JsonSerializer:
namespace SitecoreContrib.Serialization
{
public class LargeJsonSerializer : ISerializer
{
public string SerializedDataMediaType
{
get { return "application/json"; }
}
public string Serialize(object value)
{
Assert.ArgumentNotNull(value, "value");
var scriptSerializer = new JavaScriptSerializer { MaxJsonLength = 2097152 };
var setting = Settings.GetSetting("JsonSerialization.MaxLength");
int result;
if (!string.IsNullOrEmpty(setting) && !scriptSerializer.MaxJsonLength.ToString(CultureInfo.InvariantCulture).Equals(setting, StringComparison.InvariantCultureIgnoreCase) && int.TryParse(setting, out result))
{
scriptSerializer.MaxJsonLength = result;
}
return scriptSerializer.Serialize(value);
}
}
}
Pipeline:
namespace SitecoreContrib.Serialization.Pipelines.PreprocessRequest
{
public class RewriteUrlForLargeJsonResponse : RewriteUrl
{
public override void Process(PreprocessRequestArgs arguments)
{
Assert.ArgumentNotNull((object)arguments, "arguments");
try
{
string localPath = arguments.Context.Request.Url.LocalPath;
if (!localPath.StartsWith("/-/item/"))
return;
Sc.ItemWebApi.Context.Current = new Sc.ItemWebApi.Context
{
Serializer = (ISerializer)new LargeJsonSerializer(),
Version = GetVersion(localPath),
ResponseOutputBuilder = new ResponseOutputBuilder()
};
Rewrite(arguments.Context);
}
catch (Exception ex)
{
Logger.Error(ex);
}
}
private static int GetVersion(string path)
{
Assert.ArgumentNotNull((object)path, "path");
string str = path.TrimStart('/').Split('/')[2];
Assert.IsTrue(str.StartsWith("v"), "Version token is wrong.");
int result;
Assert.IsTrue(int.TryParse(str.Replace("v", string.Empty), out result), "Version not recognized.");
return result;
}
private static void Rewrite(HttpContext context)
{
Assert.ArgumentNotNull((object)context, "context");
Uri url = context.Request.Url;
string[] strArray1 = url.LocalPath.TrimStart('/').Split('/');
int length = strArray1.Length - 3;
string[] strArray2 = new string[length];
Array.Copy((Array)strArray1, 3, (Array)strArray2, 0, length);
string str1 = string.Format("/{0}", (object)string.Join("/", strArray2));
string str2 = url.Query.TrimStart('?');
WebUtil.RewriteUrl(new UrlString
{
Path = str1,
Query = str2
}.ToString());
}
}
}
Config:
<sitecore>
<pipelines>
<preprocessRequest>
<processor type="SitecoreContrib.Serialization.Pipelines.PreprocessRequest.RewriteUrlForLargeJsonResponse, SitecoreContrib.Serialization" patch:instead="*[@type='Sitecore.ItemWebApi.Pipelines.PreprocessRequest.RewriteUrl, Sitecore.ItemWebApi']" />
</preprocessRequest>
</pipelines>
<settings>
<!-- JsonSerialization.MaxLength
Specifies the maximum length of JSON strings which can be serialized by the JsonSerializer.
Value is specified in bytes. Default value: 2097152 (2 MB)
-->
<setting name="JsonSerialization.MaxLength" value="2147483647" />
</settings>
</sitecore>
Thats it, this should work well and load large json datasets for you when you have lots of sub-items.