From fa6e8ab647167040461d501a0503ece1ab0698ab Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Wed, 28 Aug 2019 12:15:33 +0300 Subject: [PATCH] Optimization --- .../ASC.Common/Utils/HttpRequestExtensions.cs | 45 +++++++++++-------- .../TimeZoneConverter/TimeZoneConverter.cs | 3 +- web/ASC.Web.Core/Users/UserPhotoManager.cs | 11 ++--- 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/common/ASC.Common/Utils/HttpRequestExtensions.cs b/common/ASC.Common/Utils/HttpRequestExtensions.cs index e10c3a7795..1cd120d8b2 100644 --- a/common/ASC.Common/Utils/HttpRequestExtensions.cs +++ b/common/ASC.Common/Utils/HttpRequestExtensions.cs @@ -54,35 +54,42 @@ namespace System.Web public static Uri GetUrlRewriter(IHeaderDictionary headers, HttpRequest request) { - if (request.Query != null && request.Query.Count > 0) - { - var rewriterUri = ParseRewriterUrl(request.Query[UrlRewriterHeader]); - if (rewriterUri != null) + if (headers != null) + { + var h = headers[UrlRewriterHeader]; + var rewriterUri = !string.IsNullOrEmpty(h) ? ParseRewriterUrl(h) : null; + if (request != null && rewriterUri != null) { - var result = new UriBuilder(request.GetDisplayUrl()) + var result = new UriBuilder() { Scheme = rewriterUri.Scheme, Host = rewriterUri.Host, Port = rewriterUri.Port - }; + }; + result.Query = request.QueryString.Value; + result.Path = request.Path.Value; return result.Uri; } - } + } + + if (request != null && request.Query != null) + { + var h = request.Query[UrlRewriterHeader]; + var rewriterUri = !string.IsNullOrEmpty(h) ? ParseRewriterUrl(h) : null; + if (rewriterUri != null) + { + var result = new UriBuilder() + { + Scheme = rewriterUri.Scheme, + Host = rewriterUri.Host, + Port = rewriterUri.Port + }; + result.Query = request.QueryString.Value; + result.Path = request.Path.Value; - if (headers != null && !string.IsNullOrEmpty(headers[UrlRewriterHeader])) - { - var rewriterUri = ParseRewriterUrl(headers[UrlRewriterHeader]); - if (rewriterUri != null) - { - var result = new UriBuilder(request.GetDisplayUrl()) - { - Scheme = rewriterUri.Scheme, - Host = rewriterUri.Host, - Port = rewriterUri.Port - }; return result.Uri; } - } + } return request.Url(); } diff --git a/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs b/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs index 30af3b4e6c..8059d04af7 100644 --- a/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs +++ b/common/ASC.Common/Utils/TimeZoneConverter/TimeZoneConverter.cs @@ -67,7 +67,8 @@ namespace ASC.Common.Utils OlsonTimeZoneId = olsonTimeZone, WindowsTimeZoneId = row.Attribute("other").Value, Territory = row.Attribute("territory").Value - }; + }; + _mapZones = _mapZones.ToList(); } catch (Exception error) { diff --git a/web/ASC.Web.Core/Users/UserPhotoManager.cs b/web/ASC.Web.Core/Users/UserPhotoManager.cs index 785e15074b..b196dbf67d 100644 --- a/web/ASC.Web.Core/Users/UserPhotoManager.cs +++ b/web/ASC.Web.Core/Users/UserPhotoManager.cs @@ -97,7 +97,7 @@ namespace ASC.Web.Core.Users public class UserPhotoManager { - private static readonly ConcurrentDictionary> Photofiles = new ConcurrentDictionary>(); + private static readonly ConcurrentDictionary> Photofiles = new ConcurrentDictionary>(); private static readonly ICacheNotify CacheNotify; static UserPhotoManager() @@ -109,7 +109,7 @@ namespace ASC.Web.Core.Users CacheNotify.Subscribe((data) => { var userId = new Guid(data.UserID.ToByteArray()); - Photofiles.GetOrAdd(userId, (r) => new ConcurrentDictionary())[data.Size] = data.FileName; + Photofiles.GetOrAdd(data.Size, (r) => new ConcurrentDictionary())[userId] = data.FileName; }, CacheNotifyAction.InsertOrUpdate); CacheNotify.Subscribe((data) => @@ -119,7 +119,8 @@ namespace ASC.Web.Core.Users try { - Photofiles.TryRemove(userId, out _); + Photofiles.TryGetValue(CacheSize.Big, out var dict); + dict?.TryRemove(userId, out _); //var storage = GetDataStore(); //storage.DeleteFiles("", data.UserID + "*.*", false); //SetCacheLoadedForTenant(false); @@ -370,11 +371,11 @@ namespace ASC.Web.Core.Users isDef = false; string fileName = null; - Photofiles.TryGetValue(userId, out var photo); + Photofiles.TryGetValue(ToCache(size), out var photo); if (size != Size.Empty) { - photo?.TryGetValue(ToCache(size), out fileName); + photo?.TryGetValue(userId, out fileName); } else {