mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-06 05:43:03 +02:00
reduce repeated deserialization of dlna profiles
This commit is contained in:
parent
2733c598b2
commit
cbeb77c0ad
|
@ -29,6 +29,8 @@ namespace MediaBrowser.Dlna
|
||||||
private readonly IJsonSerializer _jsonSerializer;
|
private readonly IJsonSerializer _jsonSerializer;
|
||||||
private readonly IServerApplicationHost _appHost;
|
private readonly IServerApplicationHost _appHost;
|
||||||
|
|
||||||
|
private readonly Dictionary<string, DeviceProfile> _profiles = new Dictionary<string, DeviceProfile>(StringComparer.Ordinal);
|
||||||
|
|
||||||
public DlnaManager(IXmlSerializer xmlSerializer,
|
public DlnaManager(IXmlSerializer xmlSerializer,
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
IApplicationPaths appPaths,
|
IApplicationPaths appPaths,
|
||||||
|
@ -300,20 +302,31 @@ namespace MediaBrowser.Dlna
|
||||||
|
|
||||||
private DeviceProfile ParseProfileXmlFile(string path, DeviceProfileType type)
|
private DeviceProfile ParseProfileXmlFile(string path, DeviceProfileType type)
|
||||||
{
|
{
|
||||||
try
|
lock (_profiles)
|
||||||
{
|
{
|
||||||
var profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);
|
DeviceProfile profile;
|
||||||
|
if (_profiles.TryGetValue(path, out profile))
|
||||||
|
{
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
|
||||||
profile.Id = path.ToLower().GetMD5().ToString("N");
|
try
|
||||||
profile.ProfileType = type;
|
{
|
||||||
|
profile = (DeviceProfile)_xmlSerializer.DeserializeFromFile(typeof(DeviceProfile), path);
|
||||||
|
|
||||||
return profile;
|
profile.Id = path.ToLower().GetMD5().ToString("N");
|
||||||
}
|
profile.ProfileType = type;
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.ErrorException("Error parsing profile xml: {0}", ex, path);
|
|
||||||
|
|
||||||
return null;
|
_profiles[path] = profile;
|
||||||
|
|
||||||
|
return profile;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.ErrorException("Error parsing profile xml: {0}", ex, path);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +441,7 @@ namespace MediaBrowser.Dlna
|
||||||
var newFilename = _fileSystem.GetValidFilename(profile.Name) + ".xml";
|
var newFilename = _fileSystem.GetValidFilename(profile.Name) + ".xml";
|
||||||
var path = Path.Combine(UserProfilesPath, newFilename);
|
var path = Path.Combine(UserProfilesPath, newFilename);
|
||||||
|
|
||||||
_xmlSerializer.SerializeToFile(profile, path);
|
SaveProfile(profile, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateProfile(DeviceProfile profile)
|
public void UpdateProfile(DeviceProfile profile)
|
||||||
|
@ -455,6 +468,15 @@ namespace MediaBrowser.Dlna
|
||||||
_fileSystem.DeleteFile(current.Path);
|
_fileSystem.DeleteFile(current.Path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SaveProfile(profile, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SaveProfile(DeviceProfile profile, string path)
|
||||||
|
{
|
||||||
|
lock (_profiles)
|
||||||
|
{
|
||||||
|
_profiles[path] = profile;
|
||||||
|
}
|
||||||
_xmlSerializer.SerializeToFile(profile, path);
|
_xmlSerializer.SerializeToFile(profile, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -162,6 +162,8 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
{
|
{
|
||||||
var path = CacheFilePath;
|
var path = CacheFilePath;
|
||||||
|
|
||||||
|
_logger.Info("Loading data from {0}", path);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var endpoint = _fileSystem.ReadAllText(path, Encoding.UTF8);
|
var endpoint = _fileSystem.ReadAllText(path, Encoding.UTF8);
|
||||||
|
|
|
@ -359,7 +359,7 @@ namespace MediaBrowser.Server.Implementations.Connect
|
||||||
{
|
{
|
||||||
var path = CacheFilePath;
|
var path = CacheFilePath;
|
||||||
|
|
||||||
_logger.Debug("Loading data from {0}", path);
|
_logger.Info("Loading data from {0}", path);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue