From f057976f788a091d3f9b9762db4d6817620c22de Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Thu, 14 Jan 2016 15:06:16 +0100 Subject: [PATCH 1/3] U4-7735 Localization fallback doesn't seem to work. #U4-7735 Fixed --- .../Services/LocalizedTextService.cs | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Core/Services/LocalizedTextService.cs b/src/Umbraco.Core/Services/LocalizedTextService.cs index 886fa47cbf..84ff3b745b 100644 --- a/src/Umbraco.Core/Services/LocalizedTextService.cs +++ b/src/Umbraco.Core/Services/LocalizedTextService.cs @@ -112,19 +112,15 @@ namespace Umbraco.Core.Services } //convert all areas + keys to a single key with a '/' - var areas = xmlSource[culture].Value.XPathSelectElements("//area"); - foreach (var area in areas) + result = GetStoredTranslations(xmlSource, culture); + + //merge with the english file in case there's keys in there that don't exist in the local file + var englishCulture = new CultureInfo("en-US"); + if (culture.Equals(englishCulture) == false) { - var keys = area.XPathSelectElements("./key"); - foreach (var key in keys) - { - var dictionaryKey = string.Format("{0}/{1}", (string) area.Attribute("alias"), (string) key.Attribute("alias")); - //there could be duplicates if the language file isn't formatted nicely - which is probably the case for quite a few lang files - if (result.ContainsKey(dictionaryKey) == false) - { - result.Add(dictionaryKey, key.Value); - } - } + var englishResults = GetStoredTranslations(xmlSource, englishCulture); + foreach (var englishResult in englishResults.Where(englishResult => result.ContainsKey(englishResult.Key) == false)) + result.Add(englishResult.Key, englishResult.Value); } } else @@ -153,6 +149,25 @@ namespace Umbraco.Core.Services return result; } + private Dictionary GetStoredTranslations(IDictionary> xmlSource, CultureInfo cult) + { + var result = new Dictionary(); + var areas = xmlSource[cult].Value.XPathSelectElements("//area"); + foreach (var area in areas) + { + var keys = area.XPathSelectElements("./key"); + foreach (var key in keys) + { + var dictionaryKey = string.Format("{0}/{1}", (string)area.Attribute("alias"), + (string)key.Attribute("alias")); + //there could be duplicates if the language file isn't formatted nicely - which is probably the case for quite a few lang files + if (result.ContainsKey(dictionaryKey) == false) + result.Add(dictionaryKey, key.Value); + } + } + return result; + } + /// /// Returns a list of all currently supported cultures /// From bfa12856db4a76f88ca9fc882d9578bac107ff7c Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 14 Jan 2016 16:36:03 +0100 Subject: [PATCH 2/3] Fixes issue with DefaultRepositoryCachePolicy when creating new items - we were generating the cache key before actually calling the method to create the item therefore there was no id assigned yet (it would be zero). --- .../Cache/DefaultRepositoryCachePolicy.cs | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs b/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs index fda57cefee..a5777a5775 100644 --- a/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs +++ b/src/Umbraco.Core/Cache/DefaultRepositoryCachePolicy.cs @@ -35,8 +35,6 @@ namespace Umbraco.Core.Cache public void CreateOrUpdate(TEntity entity, Action persistMethod) { - var cacheKey = GetCacheIdKey(entity.Id); - try { persistMethod(entity); @@ -44,7 +42,12 @@ namespace Umbraco.Core.Cache //set the disposal action SetCacheAction(() => { - Cache.InsertCacheItem(cacheKey, () => entity); + //just to be safe, we cannot cache an item without an identity + if (entity.HasIdentity) + { + Cache.InsertCacheItem(GetCacheIdKey(entity.Id), () => entity); + } + //If there's a GetAllCacheAllowZeroCount cache, ensure it is cleared Cache.ClearCacheItem(GetCacheTypeKey()); }); @@ -57,7 +60,7 @@ namespace Umbraco.Core.Cache { //if an exception is thrown we need to remove the entry from cache, this is ONLY a work around because of the way // that we cache entities: http://issues.umbraco.org/issue/U4-4259 - Cache.ClearCacheItem(cacheKey); + Cache.ClearCacheItem(GetCacheIdKey(entity.Id)); //If there's a GetAllCacheAllowZeroCount cache, ensure it is cleared Cache.ClearCacheItem(GetCacheTypeKey()); @@ -188,7 +191,14 @@ namespace Umbraco.Core.Cache /// protected virtual void SetCacheAction(string cacheKey, TEntity entity) { - SetCacheAction(() => Cache.InsertCacheItem(cacheKey, () => entity)); + SetCacheAction(() => + { + //just to be safe, we cannot cache an item without an identity + if (entity.HasIdentity) + { + Cache.InsertCacheItem(cacheKey, () => entity); + } + }); } /// @@ -214,7 +224,11 @@ namespace Umbraco.Core.Cache foreach (var entity in entityCollection.WhereNotNull()) { var localCopy = entity; - Cache.InsertCacheItem(GetCacheIdKey(entity.Id), () => localCopy); + //just to be safe, we cannot cache an item without an identity + if (localCopy.HasIdentity) + { + Cache.InsertCacheItem(GetCacheIdKey(entity.Id), () => localCopy); + } } } }); From 7958b5fcb1a890dccd928beb3c257da66e1e0196 Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 14 Jan 2016 16:43:31 +0100 Subject: [PATCH 3/3] U4-7740 Speed up the current user's culture lookup --- src/Umbraco.Web/Editors/BackOfficeController.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 0eac1958dc..66e05aca07 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -4,6 +4,7 @@ using System.Globalization; using System.IO; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Web; using System.Web.Mvc; @@ -98,7 +99,8 @@ namespace Umbraco.Web.Editors var cultureInfo = string.IsNullOrWhiteSpace(culture) //if the user is logged in, get their culture, otherwise default to 'en' ? Security.IsAuthenticated() - ? Security.CurrentUser.GetUserCulture(Services.TextService) + //current culture is set at the very beginning of each request + ? Thread.CurrentThread.CurrentCulture : CultureInfo.GetCultureInfo("en") : CultureInfo.GetCultureInfo(culture);