aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations')
-rw-r--r--Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs42
-rw-r--r--Emby.Server.Implementations/IO/ManagedFileSystem.cs23
-rw-r--r--Emby.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs9
3 files changed, 21 insertions, 53 deletions
diff --git a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
index 3aab10026..6d65250a1 100644
--- a/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
+++ b/Emby.Server.Implementations/HttpClientManager/HttpClientManager.cs
@@ -264,7 +264,7 @@ namespace Emby.Server.Implementations.HttpClientManager
var responseCachePath = Path.Combine(_appPaths.CachePath, "httpclient", urlHash);
- var response = await GetCachedResponse(responseCachePath, options.CacheLength, url).ConfigureAwait(false);
+ var response = GetCachedResponse(responseCachePath, options.CacheLength, url);
if (response != null)
{
return response;
@@ -280,30 +280,24 @@ namespace Emby.Server.Implementations.HttpClientManager
return response;
}
- private async Task<HttpResponseInfo> GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url)
+ private HttpResponseInfo GetCachedResponse(string responseCachePath, TimeSpan cacheLength, string url)
{
try
{
if (_fileSystem.GetLastWriteTimeUtc(responseCachePath).Add(cacheLength) > DateTime.UtcNow)
{
- using (var stream = _fileSystem.GetFileStream(responseCachePath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read, true))
- {
- var memoryStream = new MemoryStream();
-
- await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
- memoryStream.Position = 0;
+ var stream = _fileSystem.GetFileStream(responseCachePath, FileOpenMode.Open, FileAccessMode.Read, FileShareMode.Read, true);
- return new HttpResponseInfo
- {
- ResponseUrl = url,
- Content = memoryStream,
- StatusCode = HttpStatusCode.OK,
- ContentLength = memoryStream.Length
- };
- }
+ return new HttpResponseInfo
+ {
+ ResponseUrl = url,
+ Content = stream,
+ StatusCode = HttpStatusCode.OK,
+ ContentLength = stream.Length
+ };
}
}
- catch (FileNotFoundException)
+ catch (FileNotFoundException) // REVIEW: @bond Is this really faster?
{
}
@@ -319,19 +313,11 @@ namespace Emby.Server.Implementations.HttpClientManager
{
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(responseCachePath));
- using (var responseStream = response.Content)
+ using (var fileStream = _fileSystem.GetFileStream(responseCachePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.None, true))
{
- var memoryStream = new MemoryStream();
- await responseStream.CopyToAsync(memoryStream).ConfigureAwait(false);
- memoryStream.Position = 0;
+ await response.Content.CopyToAsync(fileStream).ConfigureAwait(false);
- using (var fileStream = _fileSystem.GetFileStream(responseCachePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.None, true))
- {
- await memoryStream.CopyToAsync(fileStream).ConfigureAwait(false);
-
- memoryStream.Position = 0;
- response.Content = memoryStream;
- }
+ response.Content.Position = 0;
}
}
diff --git a/Emby.Server.Implementations/IO/ManagedFileSystem.cs b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
index ae1470190..573333e79 100644
--- a/Emby.Server.Implementations/IO/ManagedFileSystem.cs
+++ b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
@@ -445,10 +445,7 @@ namespace Emby.Server.Implementations.IO
}
public Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, FileOpenOptions fileOpenOptions)
- {
- var defaultBufferSize = 4096;
- return new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), defaultBufferSize, GetFileOptions(fileOpenOptions));
- }
+ => new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), 4096, GetFileOptions(fileOpenOptions));
private static FileOptions GetFileOptions(FileOpenOptions mode)
{
@@ -759,18 +756,13 @@ namespace Emby.Server.Implementations.IO
// Only include drives in the ready state or this method could end up being very slow, waiting for drives to timeout
return DriveInfo.GetDrives().Where(d => d.IsReady).Select(d => new FileSystemMetadata
{
- Name = GetName(d),
+ Name = d.Name,
FullName = d.RootDirectory.FullName,
IsDirectory = true
}).ToList();
}
- private static string GetName(DriveInfo drive)
- {
- return drive.Name;
- }
-
public IEnumerable<FileSystemMetadata> GetDirectories(string path, bool recursive = false)
{
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
@@ -846,17 +838,6 @@ namespace Emby.Server.Implementations.IO
return File.OpenRead(path);
}
- private void CopyFileUsingStreams(string source, string target, bool overwrite)
- {
- using (var sourceStream = OpenRead(source))
- {
- using (var targetStream = GetFileStream(target, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
- {
- sourceStream.CopyTo(targetStream);
- }
- }
- }
-
public void CopyFile(string source, string target, bool overwrite)
{
File.Copy(source, target, overwrite);
diff --git a/Emby.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs b/Emby.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs
index 16b5a2d3a..8ef227689 100644
--- a/Emby.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs
+++ b/Emby.Server.Implementations/Library/Resolvers/TV/SeriesResolver.cs
@@ -107,7 +107,8 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
return null;
}
- public static bool IsSeriesFolder(string path,
+ public static bool IsSeriesFolder(
+ string path,
IEnumerable<FileSystemMetadata> fileSystemChildren,
IDirectoryService directoryService,
IFileSystem fileSystem,
@@ -135,7 +136,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
{
if (IsSeasonFolder(child.FullName, isTvContentType, libraryManager))
{
- //logger.LogDebug("{0} is a series because of season folder {1}.", path, child.FullName);
+ logger.LogDebug("{Path} is a series because of season folder {Dir}.", path, child.FullName);
return true;
}
}
@@ -161,7 +162,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
isOptimistic = false;
}
- var episodeInfo = episodeResolver.Resolve(fullName, false, isNamed, isOptimistic, null, false);
+ var episodeInfo = episodeResolver.Resolve(fullName, false, isNamed, isOptimistic, fillExtendedInfo: false);
if (episodeInfo != null && episodeInfo.EpisodeNumber.HasValue)
{
return true;
@@ -170,7 +171,7 @@ namespace Emby.Server.Implementations.Library.Resolvers.TV
}
}
- //logger.LogDebug("{0} is not a series folder.", path);
+ logger.LogDebug("{Path} is not a series folder.", path);
return false;
}