rework dynamic image schedule

pull/702/head
Luke Pulverenti 10 years ago
parent b8fb177fc8
commit 4b83dd4b56

@ -191,6 +191,8 @@ namespace MediaBrowser.Server.Implementations.Photos
throw new ArgumentException("Unexpected image type");
}
private const int MaxImageAgeDays = 7;
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date)
{
if (!Supports(item))
@ -198,6 +200,11 @@ namespace MediaBrowser.Server.Implementations.Photos
return false;
}
if (item is UserView)
{
return HasChanged(item, ImageType.Primary) || HasChanged(item, ImageType.Thumb);
}
var items = GetItemsWithImages(item).Result;
var cacheKey = GetConfigurationCacheKey(items, item.Name);
@ -216,7 +223,6 @@ namespace MediaBrowser.Server.Implementations.Photos
}
var currentPathCacheKey = (Path.GetFileNameWithoutExtension(image.Path) ?? string.Empty).Split('_').LastOrDefault();
if (string.Equals(cacheKey, currentPathCacheKey, StringComparison.OrdinalIgnoreCase))
{
return false;
@ -226,6 +232,27 @@ namespace MediaBrowser.Server.Implementations.Photos
return true;
}
protected bool HasChanged(IHasImages item, ImageType type)
{
var image = item.GetImageInfo(type, 0);
if (image != null)
{
if (!FileSystem.ContainsSubPath(item.GetInternalMetadataPath(), image.Path))
{
return false;
}
var age = DateTime.UtcNow - image.DateModified;
if (age.TotalDays <= MaxImageAgeDays)
{
return false;
}
}
return true;
}
protected List<BaseItem> GetFinalItems(List<BaseItem> items)
{
return GetFinalItems(items, 4);
@ -234,7 +261,7 @@ namespace MediaBrowser.Server.Implementations.Photos
protected virtual List<BaseItem> GetFinalItems(List<BaseItem> items, int limit)
{
// Rotate the images once every x days
var random = DateTime.Now.DayOfYear % 7;
var random = DateTime.Now.DayOfYear % MaxImageAgeDays;
return items
.OrderBy(i => (random + "" + items.IndexOf(i)).GetMD5())

@ -21,13 +21,11 @@ namespace MediaBrowser.Server.Implementations.UserViews
public class DynamicImageProvider : BaseDynamicImageProvider<UserView>
{
private readonly IUserManager _userManager;
private readonly ILibraryManager _libraryManager;
public DynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, IUserManager userManager, ILibraryManager libraryManager)
public DynamicImageProvider(IFileSystem fileSystem, IProviderManager providerManager, IApplicationPaths applicationPaths, IImageProcessor imageProcessor, IUserManager userManager)
: base(fileSystem, providerManager, applicationPaths, imageProcessor)
{
_userManager = userManager;
_libraryManager = libraryManager;
}
public override IEnumerable<ImageType> GetSupportedImages(IHasImages item)

Loading…
Cancel
Save