DO NOT DOWNLOAD. DOWNLOAD LATEST STABLE FROM RELEASE TAB

Improving linq to umbracos interaction with the umbraco memory cache
more use of client dependency

[TFS Changeset #59351]
This commit is contained in:
slace
2009-09-22 11:50:46 +00:00
parent 3abb520a98
commit 16ac26d449
4 changed files with 75 additions and 27 deletions

View File

@@ -12,6 +12,7 @@ namespace umbraco.Linq.Core.Node
/// <typeparam name="TDocTypeBase">The type of the doc type base.</typeparam>
public sealed class NodeAssociationTree<TDocTypeBase> : AssociationTree<TDocTypeBase> where TDocTypeBase : DocTypeBase, new()
{
private object lockObject = new object();
private IEnumerable<TDocTypeBase> _nodes;
internal NodeAssociationTree(IEnumerable<TDocTypeBase> nodes)
@@ -50,12 +51,15 @@ namespace umbraco.Linq.Core.Node
provider.CheckDisposed();
var rawNodes = provider.Xml.Descendants("node")
.Where(x => (int)x.Attribute("id") == this.ParentNodeId)
.Single()
.Elements("node")
;
this._nodes = provider.DynamicNodeCreation(rawNodes).Cast<TDocTypeBase>(); //drop is back to the type which was asked for
lock (lockObject)
{
var rawNodes = provider.Xml.Descendants("node")
.Where(x => (int)x.Attribute("id") == this.ParentNodeId)
.Single()
.Elements("node")
;
this._nodes = provider.DynamicNodeCreation(rawNodes).Cast<TDocTypeBase>(); //drop is back to the type which was asked for
}
}
/// <summary>

View File

@@ -6,6 +6,7 @@ using System.Linq.Expressions;
using System.IO;
using System.Xml.Linq;
using System.Xml.Schema;
using System.Xml;
namespace umbraco.Linq.Core.Node
{
@@ -20,6 +21,7 @@ namespace umbraco.Linq.Core.Node
/// </remarks>
public sealed class NodeDataProvider : UmbracoDataProvider
{
private object lockObject = new object();
private string _xmlPath;
private Dictionary<UmbracoInfoAttribute, IContentTree> _trees;
private bool _enforceSchemaValidation;
@@ -27,13 +29,30 @@ namespace umbraco.Linq.Core.Node
private const string UMBRACO_XSD_PATH = "umbraco.Linq.Core.Node.UmbracoConfig.xsd";
private Dictionary<string, Type> _knownTypes;
private bool _tryMemoryCache = false;
internal XDocument Xml
{
get
{
if (this._xml == null)
{
this._xml = XDocument.Load(this._xmlPath);
if (this._tryMemoryCache)
{
var doc = content.Instance.XmlContent;
if (doc != null)
{
this._xml = XDocument.Load(new XmlNodeReader(doc));
}
else
{
this._xml = XDocument.Load(this._xmlPath);
}
}
else
{
this._xml = XDocument.Load(this._xmlPath);
}
if (this._enforceSchemaValidation)
{
@@ -87,6 +106,7 @@ namespace umbraco.Linq.Core.Node
public NodeDataProvider()
: this(umbraco.presentation.UmbracoContext.Current.Server.MapPath(umbraco.presentation.UmbracoContext.Current.Server.ContentXmlPath))
{
this._tryMemoryCache = true;
}
/// <summary>
@@ -179,7 +199,10 @@ namespace umbraco.Linq.Core.Node
var tree = new NodeTree<TDocType>(this);
if (!this._trees.ContainsKey(attr))
{
this._trees.Add(attr, tree); //cache so it's faster to get next time
lock (lockObject)
{
this._trees.Add(attr, tree); //cache so it's faster to get next time
}
}
else
{
@@ -307,5 +330,16 @@ namespace umbraco.Linq.Core.Node
return this._knownTypes;
}
}
/// <summary>
/// Flushes the cache for this provider
/// </summary>
public void Flush()
{
this.CheckDisposed();
this._xml = null;
this._trees.Clear();
}
}
}

View File

@@ -12,6 +12,8 @@ namespace umbraco.Linq.Core.Node
/// <typeparam name="TDocTypeBase">The type of the doc type base.</typeparam>
public sealed class NodeTree<TDocTypeBase> : Tree<TDocTypeBase> where TDocTypeBase : DocTypeBase, new()
{
private object lockObject = new object();
private NodeDataProvider _provider;
private List<TDocTypeBase> _nodes;
@@ -67,15 +69,18 @@ namespace umbraco.Linq.Core.Node
this._nodes = new List<TDocTypeBase>();
var rawNodes = this._provider.Xml.Descendants("node").Where(x => ReflectionAssistance.CompareByAlias(typeof(TDocTypeBase), x));
foreach (XElement n in rawNodes)
lock (lockObject)
{
var dt = new TDocTypeBase();
dt.LoadFromXml(n);
foreach (XElement n in rawNodes)
{
var dt = new TDocTypeBase();
dt.LoadFromXml(n);
dt.IsDirty = false;
dt.Provider = this._provider;
dt.IsDirty = false;
dt.Provider = this._provider;
this._nodes.Add(dt);
this._nodes.Add(dt);
}
}
}
return this._nodes.GetEnumerator();

View File

@@ -1,5 +1,4 @@
using System;
using System.Data;
using System.Globalization;
using System.IO;
using System.Net;
@@ -23,7 +22,6 @@ using umbraco.cms.helpers;
using umbraco.presentation.cache;
using umbraco.scripting;
using umbraco.DataLayer;
using umbraco.presentation.templateControls;
using System.Web.Security;
using umbraco.cms.businesslogic.language;
@@ -1291,22 +1289,29 @@ namespace umbraco
if (p != null)
{
System.Web.UI.HtmlControls.HtmlGenericControl include = new System.Web.UI.HtmlControls.HtmlGenericControl("script");
include.ID = key;
include.Attributes.Add("type", "text/javascript");
include.Attributes.Add("src", url);
if (p.Header != null)
if (ClientDependency.Core.Controls.ClientDependencyLoader.Instance == null)
{
if (p.Header.FindControl(key) == null)
System.Web.UI.HtmlControls.HtmlGenericControl include = new System.Web.UI.HtmlControls.HtmlGenericControl("script");
include.ID = key;
include.Attributes.Add("type", "text/javascript");
include.Attributes.Add("src", url);
if (p.Header != null)
{
p.Header.Controls.Add(include);
if (p.Header.FindControl(key) == null)
{
p.Header.Controls.Add(include);
}
}
else
{
//This is a fallback in case there is no header
p.ClientScript.RegisterClientScriptInclude(p.GetType(), key, url);
}
}
else
{
//This is a fallback in case there is no header
p.ClientScript.RegisterClientScriptInclude(p.GetType(), key, url);
ClientDependency.Core.Controls.ClientDependencyLoader.Instance.RegisterDependency(url, ClientDependency.Core.ClientDependencyType.Javascript);
}
}
}
@@ -1317,7 +1322,7 @@ namespace umbraco
/// </summary>
public static void AddJquery()
{
RegisterJavaScriptFile("jQuery", String.Format("{0}_client/ui/jquery.js", GlobalSettings.Path));
RegisterJavaScriptFile("jQuery", String.Format("{0}/ui/jquery.js", GlobalSettings.ClientPath));
}