Skip to content

Commit

Permalink
Fix for performance, based on martinabrahams' work
Browse files Browse the repository at this point in the history
  • Loading branch information
André Ferreira committed Nov 17, 2016
1 parent d7cbff9 commit 75719f1
Show file tree
Hide file tree
Showing 2 changed files with 600 additions and 599 deletions.
117 changes: 59 additions & 58 deletions Models/UrlTrackerDomain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,63 @@
using Umbraco.Web;

namespace InfoCaster.Umbraco.UrlTracker.Models
{
public class UrlTrackerDomain
{
public int Id { get; set; }
public int NodeId { get; set; }
public string Name { get; set; }

public Node Node { get { return new Node(NodeId); } }
public string UrlWithDomain
{
get
{
var node = Node;
if (UrlTrackerSettings.HasDomainOnChildNode && node.Parent != null)
{
using (InfoCaster.Umbraco.UrlTracker.Helpers.ContextHelper.EnsureHttpContext())
{
// not sure if this will ever occur because the ensurehttpcontext is now added...
if (UmbracoContext.Current != null)
{
/*var url = new Node(node.Id).Url;
return url;*/
return Node.Url; // do not re-instantiate
}
else
{
return string.Format("{0}{1}{2}", HttpContext.Current != null ? HttpContext.Current.Request.Url.Scheme : Uri.UriSchemeHttp, Uri.SchemeDelimiter, HttpContext.Current.Request.Url.Host + "/" + Node.Parent.UrlName + "/" + Node.UrlName);
}
}
}
else
{
if (Name.Contains(Uri.UriSchemeHttp))
{
return Name;
}
else
{
return string.Format("{0}{1}{2}", HttpContext.Current != null ? HttpContext.Current.Request.Url.Scheme : Uri.UriSchemeHttp, Uri.SchemeDelimiter, Name);
}
}
}
}

public UrlTrackerDomain() { }

public UrlTrackerDomain(int id, int nodeId, string name)
{
Id = id;
NodeId = nodeId;
Name = name;
}

public override string ToString()
{
return UrlWithDomain;
}
}
{
public class UrlTrackerDomain
{
public int Id { get; set; }
public int NodeId { get; set; }
public string Name { get; set; }

public Node Node { get; set; }
public string UrlWithDomain
{
get
{
var node = Node;
if (UrlTrackerSettings.HasDomainOnChildNode && node.Parent != null)
{
using (InfoCaster.Umbraco.UrlTracker.Helpers.ContextHelper.EnsureHttpContext())
{
// not sure if this will ever occur because the ensurehttpcontext is now added...
if (UmbracoContext.Current != null)
{
/*var url = new Node(node.Id).Url;
return url;*/
return Node.Url; // do not re-instantiate
}
else
{
return string.Format("{0}{1}{2}", HttpContext.Current != null ? HttpContext.Current.Request.Url.Scheme : Uri.UriSchemeHttp, Uri.SchemeDelimiter, HttpContext.Current.Request.Url.Host + "/" + Node.Parent.UrlName + "/" + Node.UrlName);
}
}
}
else
{
if (Name.Contains(Uri.UriSchemeHttp))
{
return Name;
}
else
{
return string.Format("{0}{1}{2}", HttpContext.Current != null ? HttpContext.Current.Request.Url.Scheme : Uri.UriSchemeHttp, Uri.SchemeDelimiter, Name);
}
}
}
}

public UrlTrackerDomain() { }

public UrlTrackerDomain(int id, int nodeId, string name)
{
Id = id;
NodeId = nodeId;
Name = name;
Node = new Node(NodeId);
}

public override string ToString()
{
return UrlWithDomain;
}
}
}
Loading

0 comments on commit 75719f1

Please sign in to comment.