mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-02 11:44:41 +08:00
Caching last written for installed extensions.
--HG-- branch : dev
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Orchard.Caching;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
using Orchard.Environment.Descriptor;
|
using Orchard.Environment.Descriptor;
|
||||||
@@ -16,19 +17,23 @@ namespace Orchard.Modules.Services {
|
|||||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||||
private readonly IExtensionManager _extensionManager;
|
private readonly IExtensionManager _extensionManager;
|
||||||
private readonly IShellDescriptorManager _shellDescriptorManager;
|
private readonly IShellDescriptorManager _shellDescriptorManager;
|
||||||
|
private readonly ICacheManager _cacheManager;
|
||||||
|
|
||||||
public ModuleService(
|
public ModuleService(
|
||||||
IFeatureManager featureManager,
|
IFeatureManager featureManager,
|
||||||
IOrchardServices orchardServices,
|
IOrchardServices orchardServices,
|
||||||
IVirtualPathProvider virtualPathProvider,
|
IVirtualPathProvider virtualPathProvider,
|
||||||
IExtensionManager extensionManager,
|
IExtensionManager extensionManager,
|
||||||
IShellDescriptorManager shellDescriptorManager) {
|
IShellDescriptorManager shellDescriptorManager,
|
||||||
|
ICacheManager cacheManager) {
|
||||||
|
|
||||||
Services = orchardServices;
|
Services = orchardServices;
|
||||||
|
|
||||||
_featureManager = featureManager;
|
_featureManager = featureManager;
|
||||||
_virtualPathProvider = virtualPathProvider;
|
_virtualPathProvider = virtualPathProvider;
|
||||||
_extensionManager = extensionManager;
|
_extensionManager = extensionManager;
|
||||||
_shellDescriptorManager = shellDescriptorManager;
|
_shellDescriptorManager = shellDescriptorManager;
|
||||||
|
_cacheManager = cacheManager;
|
||||||
|
|
||||||
if (_featureManager.FeatureDependencyNotification == null) {
|
if (_featureManager.FeatureDependencyNotification == null) {
|
||||||
_featureManager.FeatureDependencyNotification = GenerateWarning;
|
_featureManager.FeatureDependencyNotification = GenerateWarning;
|
||||||
@@ -95,13 +100,17 @@ namespace Orchard.Modules.Services {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="extensionDescriptor">The extension descriptor.</param>
|
/// <param name="extensionDescriptor">The extension descriptor.</param>
|
||||||
public bool IsRecentlyInstalled(ExtensionDescriptor extensionDescriptor) {
|
public bool IsRecentlyInstalled(ExtensionDescriptor extensionDescriptor) {
|
||||||
string projectFile = GetManifestPath(extensionDescriptor);
|
DateTime lastWrittenUtc = _cacheManager.Get(extensionDescriptor, descriptor => {
|
||||||
if (!string.IsNullOrEmpty(projectFile)) {
|
string projectFile = GetManifestPath(extensionDescriptor);
|
||||||
// If project file was modified less than 24 hours ago, the module was recently deployed
|
if (!string.IsNullOrEmpty(projectFile)) {
|
||||||
return DateTime.UtcNow.Subtract(_virtualPathProvider.GetFileLastWriteTimeUtc(projectFile)) < new TimeSpan(1, 0, 0, 0);
|
// If project file was modified less than 24 hours ago, the module was recently deployed
|
||||||
}
|
return _virtualPathProvider.GetFileLastWriteTimeUtc(projectFile);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return DateTime.UtcNow;
|
||||||
|
});
|
||||||
|
|
||||||
|
return DateTime.UtcNow.Subtract(lastWrittenUtc) < new TimeSpan(1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -126,6 +135,23 @@ namespace Orchard.Modules.Services {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void GenerateWarning(string messageFormat, string featureName, IEnumerable<string> featuresInQuestion) {
|
private void GenerateWarning(string messageFormat, string featureName, IEnumerable<string> featuresInQuestion) {
|
||||||
|
if (featuresInQuestion.Count() < 1)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Services.Notifier.Warning(T(
|
||||||
|
messageFormat,
|
||||||
|
featureName,
|
||||||
|
featuresInQuestion.Count() > 1
|
||||||
|
? string.Join("",
|
||||||
|
featuresInQuestion.Select(
|
||||||
|
(fn, i) =>
|
||||||
|
T(i == featuresInQuestion.Count() - 1
|
||||||
|
? "{0}"
|
||||||
|
: (i == featuresInQuestion.Count() - 2
|
||||||
|
? "{0} and "
|
||||||
|
: "{0}, "), fn).ToString()).ToArray())
|
||||||
|
: featuresInQuestion.First()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web.Routing;
|
using System.Web.Routing;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
using Orchard.Caching;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
using Orchard.Environment.Features;
|
using Orchard.Environment.Features;
|
||||||
@@ -17,16 +18,20 @@ namespace Orchard.Themes.Services {
|
|||||||
private readonly IFeatureManager _featureManager;
|
private readonly IFeatureManager _featureManager;
|
||||||
private readonly IEnumerable<IThemeSelector> _themeSelectors;
|
private readonly IEnumerable<IThemeSelector> _themeSelectors;
|
||||||
private readonly IVirtualPathProvider _virtualPathProvider;
|
private readonly IVirtualPathProvider _virtualPathProvider;
|
||||||
|
private readonly ICacheManager _cacheManager;
|
||||||
|
|
||||||
public ThemeService(
|
public ThemeService(
|
||||||
IExtensionManager extensionManager,
|
IExtensionManager extensionManager,
|
||||||
IFeatureManager featureManager,
|
IFeatureManager featureManager,
|
||||||
IEnumerable<IThemeSelector> themeSelectors,
|
IEnumerable<IThemeSelector> themeSelectors,
|
||||||
IVirtualPathProvider virtualPathProvider) {
|
IVirtualPathProvider virtualPathProvider,
|
||||||
|
ICacheManager cacheManager) {
|
||||||
|
|
||||||
_extensionManager = extensionManager;
|
_extensionManager = extensionManager;
|
||||||
_featureManager = featureManager;
|
_featureManager = featureManager;
|
||||||
_themeSelectors = themeSelectors;
|
_themeSelectors = themeSelectors;
|
||||||
_virtualPathProvider = virtualPathProvider;
|
_virtualPathProvider = virtualPathProvider;
|
||||||
|
_cacheManager = cacheManager;
|
||||||
|
|
||||||
Logger = NullLogger.Instance;
|
Logger = NullLogger.Instance;
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
@@ -116,15 +121,19 @@ namespace Orchard.Themes.Services {
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines if a theme was recently installed by using the project's last written time.
|
/// Determines if a theme was recently installed by using the project's last written time.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="descriptor">The extension descriptor.</param>
|
/// <param name="extensionDescriptor">The extension descriptor.</param>
|
||||||
public bool IsRecentlyInstalled(ExtensionDescriptor descriptor) {
|
public bool IsRecentlyInstalled(ExtensionDescriptor extensionDescriptor) {
|
||||||
string projectFile = GetManifestPath(descriptor);
|
DateTime lastWrittenUtc = _cacheManager.Get(extensionDescriptor, descriptor => {
|
||||||
if (!string.IsNullOrEmpty(projectFile)) {
|
string projectFile = GetManifestPath(extensionDescriptor);
|
||||||
// If project file was modified less than 24 hours ago, the module was recently deployed
|
if (!string.IsNullOrEmpty(projectFile)) {
|
||||||
return DateTime.UtcNow.Subtract(_virtualPathProvider.GetFileLastWriteTimeUtc(projectFile)) < new TimeSpan(1, 0, 0, 0);
|
// If project file was modified less than 24 hours ago, the module was recently deployed
|
||||||
}
|
return _virtualPathProvider.GetFileLastWriteTimeUtc(projectFile);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return DateTime.UtcNow;
|
||||||
|
});
|
||||||
|
|
||||||
|
return DateTime.UtcNow.Subtract(lastWrittenUtc) < new TimeSpan(1, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string GetManifestPath(ExtensionDescriptor descriptor) {
|
private string GetManifestPath(ExtensionDescriptor descriptor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user