mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Changed the handling of the Initializing shell status.
This improves the responsiveness of subsequent requests coming in dramatically.
This commit is contained in:
@@ -44,12 +44,9 @@ namespace Orchard.Setup.Controllers {
|
||||
|
||||
public ActionResult Index() {
|
||||
var initialSettings = _setupService.Prime();
|
||||
|
||||
if(initialSettings.State == TenantState.Initializing)
|
||||
return View("Initializing");
|
||||
|
||||
var recipes = _setupService.Recipes().ToList();
|
||||
string recipeDescription = null;
|
||||
|
||||
if (recipes.Count > 0) {
|
||||
recipeDescription = recipes[0].Description;
|
||||
}
|
||||
|
@@ -137,9 +137,6 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Document.cshtml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Views\Setup\Initializing.cshtml" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
|
@@ -86,6 +86,9 @@ namespace Orchard.Setup.Services {
|
||||
|
||||
context.EnabledFeatures = hardcoded.Union(context.EnabledFeatures ?? Enumerable.Empty<string>()).Distinct().ToList();
|
||||
|
||||
// Set shell state to "Initializing" so that subsequent HTTP requests are responded to with "Service Unavailable" while Orchard is setting up.
|
||||
_shellSettings.State = TenantState.Initializing;
|
||||
|
||||
var shellSettings = new ShellSettings(_shellSettings);
|
||||
|
||||
if (String.IsNullOrEmpty(shellSettings.DataProvider)) {
|
||||
@@ -174,7 +177,7 @@ namespace Orchard.Setup.Services {
|
||||
}
|
||||
}
|
||||
|
||||
// Set shell state to "Initializing" so that subsequent HTTP requests are responded to with "Service Unavailable" while Orchard is setting up.
|
||||
// Reset shell state to "Initializing" so that subsequent HTTP requests are responded to with "Service Unavailable" while Orchard is setting up.
|
||||
shellSettings.State = _shellSettings.State = TenantState.Initializing;
|
||||
_shellSettingsManager.SaveSettings(shellSettings);
|
||||
|
||||
|
@@ -1 +0,0 @@
|
||||
@T("Orchard is initializing. Please check back in a few minutes.")
|
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Security.Cryptography;
|
||||
using System.Threading.Tasks;
|
||||
using Orchard.Caching;
|
||||
using Orchard.Environment.Configuration;
|
||||
@@ -12,6 +11,7 @@ using Orchard.Environment.Descriptor;
|
||||
using Orchard.Environment.Descriptor.Models;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Mvc;
|
||||
using Orchard.Utility.Extensions;
|
||||
|
||||
namespace Orchard.Environment {
|
||||
@@ -25,12 +25,13 @@ namespace Orchard.Environment {
|
||||
private readonly IExtensionLoaderCoordinator _extensionLoaderCoordinator;
|
||||
private readonly IExtensionMonitoringCoordinator _extensionMonitoringCoordinator;
|
||||
private readonly ICacheManager _cacheManager;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly static object _syncLock = new object();
|
||||
private readonly static object _shellContextsWriteLock = new object();
|
||||
|
||||
private IEnumerable<ShellContext> _shellContexts;
|
||||
|
||||
private readonly ContextState<IList<ShellSettings>> _tenantsToRestart;
|
||||
|
||||
public DefaultOrchardHost(
|
||||
IShellSettingsManager shellSettingsManager,
|
||||
IShellContextFactory shellContextFactory,
|
||||
@@ -39,7 +40,9 @@ namespace Orchard.Environment {
|
||||
IExtensionLoaderCoordinator extensionLoaderCoordinator,
|
||||
IExtensionMonitoringCoordinator extensionMonitoringCoordinator,
|
||||
ICacheManager cacheManager,
|
||||
IHostLocalRestart hostLocalRestart) {
|
||||
IHostLocalRestart hostLocalRestart,
|
||||
IHttpContextAccessor httpContextAccessor) {
|
||||
|
||||
_shellSettingsManager = shellSettingsManager;
|
||||
_shellContextFactory = shellContextFactory;
|
||||
_runningShellTable = runningShellTable;
|
||||
@@ -48,6 +51,7 @@ namespace Orchard.Environment {
|
||||
_extensionMonitoringCoordinator = extensionMonitoringCoordinator;
|
||||
_cacheManager = cacheManager;
|
||||
_hostLocalRestart = hostLocalRestart;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
||||
_tenantsToRestart = new ContextState<IList<ShellSettings>>("DefaultOrchardHost.TenantsToRestart", () => new List<ShellSettings>());
|
||||
|
||||
@@ -189,7 +193,6 @@ namespace Orchard.Environment {
|
||||
private ShellContext CreateShellContext(ShellSettings settings) {
|
||||
switch (settings.State) {
|
||||
case TenantState.Uninitialized:
|
||||
case TenantState.Initializing:
|
||||
Logger.Debug("Creating shell context for tenant {0} setup.", settings.Name);
|
||||
return _shellContextFactory.CreateSetupContext(settings);
|
||||
default:
|
||||
@@ -236,6 +239,8 @@ namespace Orchard.Environment {
|
||||
}
|
||||
|
||||
protected virtual void BeginRequest() {
|
||||
BlockRequestsDuringSetup();
|
||||
|
||||
// Ensure all shell contexts are loaded, or need to be reloaded if
|
||||
// extensions have changed
|
||||
MonitorExtensions();
|
||||
@@ -343,6 +348,20 @@ namespace Orchard.Environment {
|
||||
_tenantsToRestart.GetState().Add(context.Settings);
|
||||
}
|
||||
|
||||
private void BlockRequestsDuringSetup() {
|
||||
if (_shellContexts == null)
|
||||
return;
|
||||
|
||||
// If there's only one tenant and it's initializing, return a Service Unavailable HTTP status code.
|
||||
var shellContexts = _shellContexts.ToList();
|
||||
if (shellContexts.Count == 1 && shellContexts[0].Settings.State == TenantState.Initializing) {
|
||||
var response = _httpContextAccessor.Current().Response;
|
||||
response.StatusCode = 503;
|
||||
response.StatusDescription = "Orchard is currently setting up. Please check back in a few moments.";
|
||||
response.Write("Orchard is currently setting up. Please check back in a few moments.");
|
||||
}
|
||||
}
|
||||
|
||||
// To be used from CreateStandaloneEnvironment(), also disposes the ShellContext LifetimeScope.
|
||||
private class StandaloneEnvironmentWorkContextScopeWrapper : IWorkContextScope {
|
||||
private readonly ShellContext _shellContext;
|
||||
|
Reference in New Issue
Block a user