Fixing memory pressure when creating new tenants

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-09-08 14:57:08 -07:00
parent 09f9963502
commit 87f9b5f77c
5 changed files with 44 additions and 30 deletions

View File

@@ -109,38 +109,44 @@ namespace Orchard.Setup.Services {
var shellBlueprint = _compositionStrategy.Compose(shellSettings, shellDescriptor);
// initialize database explicitly, and store shell descriptor
var bootstrapLifetimeScope = _shellContainerFactory.CreateContainer(shellSettings, shellBlueprint);
using (var bootstrapLifetimeScope = _shellContainerFactory.CreateContainer(shellSettings, shellBlueprint))
{
using (var environment = bootstrapLifetimeScope.CreateWorkContextScope()) {
using (var environment = bootstrapLifetimeScope.CreateWorkContextScope())
{
// check if the database is already created (in case an exception occured in the second phase)
var shellDescriptorRepository = environment.Resolve<IRepository<ShellDescriptorRecord>>();
try {
shellDescriptorRepository.Get(x => true);
}
catch {
var schemaBuilder = new SchemaBuilder(environment.Resolve<IDataMigrationInterpreter>());
var reportsCoordinator = environment.Resolve<IReportsCoordinator>();
reportsCoordinator.Register("Data Migration", "Setup", "Orchard installation");
schemaBuilder.CreateTable("Orchard_Framework_DataMigrationRecord",
table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<string>("DataMigrationClass")
.Column<int>("Version"));
var dataMigrationManager = environment.Resolve<IDataMigrationManager>();
dataMigrationManager.Update("Settings");
foreach (var feature in context.EnabledFeatures) {
dataMigrationManager.Update(feature);
// check if the database is already created (in case an exception occured in the second phase)
var shellDescriptorRepository = environment.Resolve<IRepository<ShellDescriptorRecord>>();
try
{
shellDescriptorRepository.Get(x => true);
}
catch
{
var schemaBuilder = new SchemaBuilder(environment.Resolve<IDataMigrationInterpreter>());
var reportsCoordinator = environment.Resolve<IReportsCoordinator>();
environment.Resolve<IShellDescriptorManager>().UpdateShellDescriptor(
0,
shellDescriptor.Features,
shellDescriptor.Parameters);
reportsCoordinator.Register("Data Migration", "Setup", "Orchard installation");
schemaBuilder.CreateTable("Orchard_Framework_DataMigrationRecord",
table => table
.Column<int>("Id", column => column.PrimaryKey().Identity())
.Column<string>("DataMigrationClass")
.Column<int>("Version"));
var dataMigrationManager = environment.Resolve<IDataMigrationManager>();
dataMigrationManager.Update("Settings");
foreach (var feature in context.EnabledFeatures)
{
dataMigrationManager.Update(feature);
}
environment.Resolve<IShellDescriptorManager>().UpdateShellDescriptor(
0,
shellDescriptor.Features,
shellDescriptor.Parameters);
}
}
}

View File

@@ -65,6 +65,7 @@ namespace Orchard.Setup {
builder.RegisterType<WorkContextAccessor>().As<IWorkContextAccessor>().InstancePerMatchingLifetimeScope("shell");
builder.RegisterType<ResourceManager>().As<IResourceManager>().InstancePerLifetimeScope();
builder.RegisterType<ResourceFilter>().As<IFilterProvider>().InstancePerLifetimeScope();
builder.RegisterType<DefaultOrchardShell>().As<IOrchardShell>().InstancePerMatchingLifetimeScope("shell");
// setup mode specific implementations of needed service interfaces
builder.RegisterType<SafeModeThemeService>().As<IThemeManager>().InstancePerLifetimeScope();
@@ -77,7 +78,7 @@ namespace Orchard.Setup {
builder.RegisterType<RecipeHarvester>().As<IRecipeHarvester>().InstancePerLifetimeScope();
builder.RegisterType<RecipeParser>().As<IRecipeParser>().InstancePerLifetimeScope();
builder.RegisterType<DefaultCacheHolder>().As<ICacheHolder>().InstancePerLifetimeScope();
builder.RegisterType<DefaultCacheHolder>().As<ICacheHolder>().SingleInstance();
// in progress - adding services for display/shape support in setup
builder.RegisterType<DisplayHelperFactory>().As<IDisplayHelperFactory>();

View File

@@ -167,6 +167,7 @@ namespace Orchard.Environment {
if (_current != null) {
foreach (var shellContext in _current) {
shellContext.Shell.Terminate();
shellContext.LifetimeScope.Dispose();
}
_current = null;
}

View File

@@ -71,6 +71,7 @@ namespace Orchard.Environment.ShellBuilders {
_shellDescriptorCache.Store(settings.Name, currentDescriptor);
blueprint = _compositionStrategy.Compose(settings, currentDescriptor);
shellScope.Dispose();
shellScope = _shellContainerFactory.CreateContainer(settings, blueprint);
}

View File

@@ -5,7 +5,7 @@ using Orchard.Environment;
using Orchard.Logging;
namespace Orchard.Tasks {
public class SweepGenerator : IOrchardShellEvents {
public class SweepGenerator : IOrchardShellEvents, IDisposable {
private readonly IWorkContextAccessor _workContextAccessor;
private readonly Timer _timer;
@@ -74,5 +74,10 @@ namespace Orchard.Tasks {
}
}
public void Dispose()
{
_timer.Elapsed -= Elapsed;
_timer.Dispose();
}
}
}