Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lazily recompile PureLive models and lazily create models for nucache #6347

Merged
merged 45 commits into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
8fef824
Moves rebuilding models and cache to background thread
Shazwazza Sep 9, 2019
fdad387
renames objects/methods and adds a lock to the routing mechanism
Shazwazza Sep 9, 2019
296afb1
Renames and puts in temp fix to try to find out why we are binding to…
Shazwazza Sep 10, 2019
596c745
Uses an event on UmbracoContext for when the snapshot is created so w…
Shazwazza Sep 10, 2019
b997281
Only waits for background processing to finish if it's a front-end re…
Shazwazza Sep 10, 2019
44fbdb7
renames class
Shazwazza Sep 10, 2019
0a12f86
Moves the reserved path detection to RoutableDocumentFilter, adds cac…
Shazwazza Sep 10, 2019
81d9ecc
fixing tests
Shazwazza Sep 10, 2019
de03130
Don't fully regenerate models on startup, they will be regenerated if…
Shazwazza Sep 10, 2019
c219c21
ensures tests and benchmark projects are building in Debug mode
Shazwazza Sep 10, 2019
642c068
ensure we don't wait on background operations when not in PureLive
Shazwazza Sep 10, 2019
127c429
fix tests
Shazwazza Sep 10, 2019
19716e3
fixing tests
Shazwazza Sep 11, 2019
942c6c7
fixes tests
Shazwazza Sep 11, 2019
81b2773
better logging
Shazwazza Sep 12, 2019
2c27a63
Update src/Umbraco.Web/RoutableDocumentFilter.cs
Shazwazza Sep 12, 2019
d7b950f
Update src/Umbraco.Web/RoutableDocumentFilter.cs
Shazwazza Sep 12, 2019
c7c2f64
removes comments
Shazwazza Sep 12, 2019
6ade207
Merge branch 'v8/bugfix/background-pure-live-rebuild-AB1833' of https…
Shazwazza Sep 12, 2019
aa9ece9
naming convention and null check
Shazwazza Sep 12, 2019
e5634d1
Lazily create content and models in NuCache
Sep 13, 2019
ba74b75
wraps package uninstall in a scope, creates temp SuspendSafeLiveFacto…
Shazwazza Sep 16, 2019
84fcd30
Merge pull request #6346 from zpqrtbnk/v8/bugfix/lazy-nucache
Shazwazza Sep 16, 2019
5898b64
disable force rebuilding pure live models on schema changes
Shazwazza Sep 16, 2019
a85d8f3
ensure that we don't CreateModel during cache notification
Shazwazza Sep 16, 2019
bc42adb
removes notifying all content/media of content type changes since nuc…
Shazwazza Sep 16, 2019
fc82100
Adds ext methods for creating a flag to indicate model recompilation …
Shazwazza Sep 16, 2019
ebada94
temp - removing the SuspendSafeLiveFactory for now
Shazwazza Sep 16, 2019
4c77582
fixes null ref issues since the field values were not copied on clone
Shazwazza Sep 16, 2019
bc40216
Ensure package installation for data is executed within a single scop…
Shazwazza Sep 16, 2019
47d3af9
removes the test suspendable model factory code
Shazwazza Sep 16, 2019
00c7204
Uses reflection to call ResetModels to flag MB to recompile.
Shazwazza Sep 16, 2019
2b9ab0a
Merge branch 'v8/bugfix/background-pure-live-rebuild-AB1833' into v8/…
Shazwazza Sep 16, 2019
c27e876
Removes BackgroundPublishedSnapshotNotifier
Shazwazza Sep 16, 2019
de8d253
obsoletes WithSafeLiveFactory
Shazwazza Sep 16, 2019
6d886e3
removes uneeded IsDocumentRequest method
Shazwazza Sep 16, 2019
e1433dd
Merge remote-tracking branch 'origin/v8/dev' into v8/bugfix/AB2684-pu…
Shazwazza Sep 17, 2019
5411057
dont hide model binding exceptions if in debug mode
Shazwazza Sep 17, 2019
7fdbb84
Fixes bug with nucache - it wasn't using gen/snapshots the way it was…
Shazwazza Sep 17, 2019
1eb1c9d
allows for disabling the modelbinderexceptionfilter from config for t…
Shazwazza Sep 17, 2019
ef00738
only enable the ModelBindingExceptionFilter when running PureLive, th…
Shazwazza Sep 17, 2019
3cf1e18
Merge remote-tracking branch 'origin/v8/dev' into v8/bugfix/AB2684-pu…
Shazwazza Sep 17, 2019
ab79cd7
Fixes lazy iteration issue on package install
Shazwazza Sep 17, 2019
e6805b2
Oops! didn't complete the scope, ok now package install works within …
Shazwazza Sep 17, 2019
cc1e46a
Simplifies ContentStore for all the instances it's trying to find a l…
Shazwazza Sep 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Umbraco.Core/Configuration/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public class GlobalSettings : IGlobalSettings
/// </summary>
private static void ResetInternal()
{
GlobalSettingsExtensions.Reset();
_reservedPaths = null;
_reservedUrls = null;
HasSmtpServer = null;
Expand Down
113 changes: 11 additions & 102 deletions src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.Routing;
using Umbraco.Core.IO;
Expand All @@ -9,22 +11,9 @@ namespace Umbraco.Core.Configuration
{
public static class GlobalSettingsExtensions
{
/// <summary>
/// Used in unit testing to reset all config items, this is automatically called by GlobalSettings.Reset()
/// </summary>
internal static void Reset()
{
_reservedUrlsCache = null;
_mvcArea = null;
}

private static readonly object Locker = new object();
//make this volatile so that we can ensure thread safety with a double check lock
private static volatile string _reservedUrlsCache;
private static string _reservedPathsCache;
private static HashSet<string> _reservedList = new HashSet<string>();
private static string _mvcArea;


/// <summary>
/// This returns the string of the MVC Area route.
/// </summary>
Expand All @@ -40,103 +29,23 @@ public static string GetUmbracoMvcArea(this IGlobalSettings globalSettings)
{
if (_mvcArea != null) return _mvcArea;

if (globalSettings.Path.IsNullOrWhiteSpace())
{
throw new InvalidOperationException("Cannot create an MVC Area path without the umbracoPath specified");
}
_mvcArea = GetUmbracoMvcAreaNoCache(globalSettings);

var path = globalSettings.Path;
if (path.StartsWith(SystemDirectories.Root)) // beware of TrimStart, see U4-2518
path = path.Substring(SystemDirectories.Root.Length);
_mvcArea = path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower();
return _mvcArea;
}

/// <summary>
/// Determines whether the specified URL is reserved or is inside a reserved path.
/// </summary>
/// <param name="globalSettings"></param>
/// <param name="url">The URL to check.</param>
/// <returns>
/// <c>true</c> if the specified URL is reserved; otherwise, <c>false</c>.
/// </returns>
internal static bool IsReservedPathOrUrl(this IGlobalSettings globalSettings, string url)
internal static string GetUmbracoMvcAreaNoCache(this IGlobalSettings globalSettings)
{
if (_reservedUrlsCache == null)
{
lock (Locker)
{
if (_reservedUrlsCache == null)
{
// store references to strings to determine changes
_reservedPathsCache = globalSettings.ReservedPaths;
_reservedUrlsCache = globalSettings.ReservedUrls;

// add URLs and paths to a new list
var newReservedList = new HashSet<string>();
foreach (var reservedUrlTrimmed in _reservedUrlsCache
.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim().ToLowerInvariant())
.Where(x => x.IsNullOrWhiteSpace() == false)
.Select(reservedUrl => IOHelper.ResolveUrl(reservedUrl).Trim().EnsureStartsWith("/"))
.Where(reservedUrlTrimmed => reservedUrlTrimmed.IsNullOrWhiteSpace() == false))
{
newReservedList.Add(reservedUrlTrimmed);
}

foreach (var reservedPathTrimmed in _reservedPathsCache
.Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim().ToLowerInvariant())
.Where(x => x.IsNullOrWhiteSpace() == false)
.Select(reservedPath => IOHelper.ResolveUrl(reservedPath).Trim().EnsureStartsWith("/").EnsureEndsWith("/"))
.Where(reservedPathTrimmed => reservedPathTrimmed.IsNullOrWhiteSpace() == false))
{
newReservedList.Add(reservedPathTrimmed);
}

// use the new list from now on
_reservedList = newReservedList;
}
}
}

//The url should be cleaned up before checking:
// * If it doesn't contain an '.' in the path then we assume it is a path based URL, if that is the case we should add an trailing '/' because all of our reservedPaths use a trailing '/'
// * We shouldn't be comparing the query at all
var pathPart = url.Split(new[] {'?'}, StringSplitOptions.RemoveEmptyEntries)[0].ToLowerInvariant();
if (pathPart.Contains(".") == false)
if (globalSettings.Path.IsNullOrWhiteSpace())
{
pathPart = pathPart.EnsureEndsWith('/');
throw new InvalidOperationException("Cannot create an MVC Area path without the umbracoPath specified");
}

// return true if url starts with an element of the reserved list
return _reservedList.Any(x => pathPart.InvariantStartsWith(x));
}

/// <summary>
/// Determines whether the current request is reserved based on the route table and
/// whether the specified URL is reserved or is inside a reserved path.
/// </summary>
/// <param name="globalSettings"></param>
/// <param name="url"></param>
/// <param name="httpContext"></param>
/// <param name="routes">The route collection to lookup the request in</param>
/// <returns></returns>
internal static bool IsReservedPathOrUrl(this IGlobalSettings globalSettings, string url, HttpContextBase httpContext, RouteCollection routes)
{
if (httpContext == null) throw new ArgumentNullException(nameof(httpContext));
if (routes == null) throw new ArgumentNullException(nameof(routes));

//check if the current request matches a route, if so then it is reserved.
//TODO: This value should be cached! Else this is doing double routing in MVC every request!
var route = routes.GetRouteData(httpContext);
if (route != null)
return true;

//continue with the standard ignore routine
return globalSettings.IsReservedPathOrUrl(url);
var path = globalSettings.Path;
if (path.StartsWith(SystemDirectories.Root)) // beware of TrimStart, see U4-2518
path = path.Substring(SystemDirectories.Root.Length);
return path.TrimStart('~').TrimStart('/').Replace('/', '-').Trim().ToLower();
}


}
}
Loading