WIP - removes all the commented out code, now we need to ensure that the DictionaryRepository/Service performs well, there's a bunch of N+1 queries in there and caching will be ignored for several of the get methods when loading with a GUID which we need to have in there if we want it to perform just as well as before.

This commit is contained in:
Shannon
2015-01-12 20:14:12 +11:00
parent b9398375f1
commit ef2c46b6ab
2 changed files with 5 additions and 250 deletions

View File

@@ -103,101 +103,48 @@ namespace umbraco.cms.businesslogic
{
}
internal DictionaryItem(IDictionaryItem item)
{
_dictionaryItem = item;
//this.id = id;
//this._key = key;
//this.UniqueId = item.Key;
//this.ParentId = item.ParentId;
}
private readonly IDictionaryItem _dictionaryItem;
private DictionaryItem _parent;
//private string _key;
//internal Guid UniqueId { get; private set; }
//internal Guid ParentId { get; private set; }
///// <summary>
///// Used internally to construct a new item object and store in cache
///// </summary>
///// <param name="id"></param>
///// <param name="key"></param>
///// <param name="uniqueKey"></param>
///// <param name="parentId"></param>
//internal DictionaryItem(int id, string key, Guid uniqueKey, Guid parentId)
//{
// this.id = id;
// this._key = key;
// this.UniqueId = uniqueKey;
// this.ParentId = parentId;
//}
public DictionaryItem(string key)
{
//EnsureCache();
//var item = DictionaryItems.Values.SingleOrDefault(x => x.key == key);
_dictionaryItem = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemByKey(key);
if (_dictionaryItem == null)
{
throw new ArgumentException("No key " + key + " exists in dictionary");
}
//this.id = item.Id;
//this._key = item.ItemKey;
//this.ParentId = item.ParentId;
//this.UniqueId = item.Key;
}
public DictionaryItem(Guid id)
{
//EnsureCache();
//var item = DictionaryItems.Values.SingleOrDefault(x => x.UniqueId == id);
_dictionaryItem = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(id);
if (_dictionaryItem == null)
{
throw new ArgumentException("No unique id " + id + " exists in dictionary");
}
//this.id = item.Id;
//this._key = item.ItemKey;
//this.ParentId = item.ParentId;
//this.UniqueId = item.Key;
}
public DictionaryItem(int id)
{
//EnsureCache();
_dictionaryItem = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(id);
if (_dictionaryItem == null)
{
throw new ArgumentException("No id " + id + " exists in dictionary");
}
//this.id = item.Id;
//this._key = item.ItemKey;
//this.ParentId = item.ParentId;
//this.UniqueId = item.Key;
}
[Obsolete("This is no longer used and will be removed from the codebase in future versions")]
public bool IsTopMostItem()
{
//EnsureCache();
//return DictionaryItems.Values
// .Where(x => x.id == id)
// .Select(x => x.ParentId)
// .SingleOrDefault() == TopLevelParent;
{
return _dictionaryItem.ParentId == new Guid(Constants.Conventions.Localization.DictionaryItemRootId);
}
@@ -211,8 +158,6 @@ namespace umbraco.cms.businesslogic
//EnsureCache();
if (_parent == null)
{
//var p = DictionaryItems.Values.SingleOrDefault(x => x.UniqueId == this.ParentId);
var p = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(_dictionaryItem.ParentId);
if (p == null)
@@ -245,31 +190,17 @@ namespace umbraco.cms.businesslogic
.WhereNotNull()
.Select(x => new DictionaryItem(x))
.ToArray();
//EnsureCache();
//return DictionaryItems.Values
// .Where(x => x.ParentId == this.UniqueId).OrderBy(item => item.key)
// .ToArray();
}
}
public static bool hasKey(string key)
{
return ApplicationContext.Current.Services.LocalizationService.DictionaryItemExists(key);
//EnsureCache();
//return DictionaryItems.ContainsKey(key);
}
public bool hasChildren
{
get
{
//EnsureCache();
//return DictionaryItems.Values.Any(x => x.ParentId == UniqueId);
return Children.Any();
}
get { return Children.Any(); }
}
/// <summary>
@@ -281,33 +212,7 @@ namespace umbraco.cms.businesslogic
set
{
if (hasKey(value) == false)
{
//lock (Locker)
//{
// SqlHelper.ExecuteNonQuery("Update cmsDictionary set [key] = @key WHERE pk = @Id", SqlHelper.CreateParameter("@key", value),
// SqlHelper.CreateParameter("@Id", id));
// using (IRecordsReader dr =
// SqlHelper.ExecuteReader("Select pk, id, [key], parent from cmsDictionary where id=@id",
// SqlHelper.CreateParameter("@id", this.UniqueId)))
// {
// if (dr.Read())
// {
// //create new dictionaryitem object and put in cache
// var item = new DictionaryItem(dr.GetInt("pk"),
// dr.GetString("key"),
// dr.GetGuid("id"),
// dr.GetGuid("parent"));
// }
// else
// {
// throw new DataException("Could not load updated created dictionary item with id " + id);
// }
// }
// //finally update this objects value
// this._key = value;
//}
{
_dictionaryItem.ItemKey = value;
}
else
@@ -322,11 +227,6 @@ namespace umbraco.cms.businesslogic
var translation = _dictionaryItem.Translations.FirstOrDefault(x => x.Language.Id == languageId);
return translation == null ? string.Empty : translation.Value;
//if (Item.hasText(_dictionaryItem.Key, languageId))
// return Item.Text(_dictionaryItem.Key, languageId);
//return "";
}
public void setValue(int languageId, string value)
@@ -335,12 +235,6 @@ namespace umbraco.cms.businesslogic
_dictionaryItem,
ApplicationContext.Current.Services.LocalizationService.GetLanguageById(languageId),
value);
//if (Item.hasText(_dictionaryItem.Key, languageId))
// Item.setText(languageId, _dictionaryItem.Key, value);
//else
// Item.addText(languageId, _dictionaryItem.Key, value);
// Calling Save method triggers the Saving event
Save();
}
@@ -353,13 +247,6 @@ namespace umbraco.cms.businesslogic
{
var defaultTranslation = _dictionaryItem.Translations.FirstOrDefault(x => x.Language.Id == 1);
return defaultTranslation == null ? string.Empty : defaultTranslation.Value;
//if (Item.hasText(_dictionaryItem.Key, 1))
//{
// return Item.Text(_dictionaryItem.Key, 1);
//}
//return string.Empty;
}
[EditorBrowsable(EditorBrowsableState.Never)]
@@ -371,7 +258,6 @@ namespace umbraco.cms.businesslogic
else
Item.addText(0, _dictionaryItem.Key, value);
// Calling Save method triggers the Saving event
Save();
}
@@ -390,8 +276,6 @@ namespace umbraco.cms.businesslogic
public static int addKey(string key, string defaultValue)
{
//EnsureCache();
int retval = CreateKey(key, TopLevelParent, defaultValue);
return retval;
}
@@ -402,16 +286,6 @@ namespace umbraco.cms.businesslogic
ApplicationContext.Current.Services.LocalizationService.Delete(_dictionaryItem);
//// delete recursive
//foreach (DictionaryItem dd in Children)
// dd.delete();
//// remove all language values from key
//Item.removeText(_dictionaryItem.Key);
//// remove key from database
//SqlHelper.ExecuteNonQuery("delete from cmsDictionary where [key] = @key", SqlHelper.CreateParameter("@key", key));
OnDeleted(EventArgs.Empty);
}
@@ -515,36 +389,6 @@ namespace umbraco.cms.businesslogic
key, parentId, defaultValue);
return item.Id;
//SqlHelper.ExecuteNonQuery("Insert into cmsDictionary (id,parent,[key]) values (@id, @parentId, @dictionaryKey)",
// SqlHelper.CreateParameter("@id", newId),
// SqlHelper.CreateParameter("@parentId", parentId),
// SqlHelper.CreateParameter("@dictionaryKey", key));
//using (IRecordsReader dr =
// SqlHelper.ExecuteReader("Select pk, id, [key], parent from cmsDictionary where id=@id",
// SqlHelper.CreateParameter("@id", newId)))
//{
// if (dr.Read())
// {
// //create new dictionaryitem object and put in cache
// var item = new DictionaryItem(dr.GetInt("pk"),
// dr.GetString("key"),
// dr.GetGuid("id"),
// dr.GetGuid("parent"));
// item.setValue(defaultValue);
// item.OnNew(EventArgs.Empty);
// return item.id;
// }
// else
// {
// throw new DataException("Could not load newly created dictionary item with id " + newId.ToString());
// }
//}
}
else
{

View File

@@ -20,9 +20,6 @@ namespace umbraco.cms.businesslogic.language
[Obsolete("This class is no longer used, nor should it ever be used, it will be removed from the codebase in future versions")]
public class Item
{
//private static readonly ConcurrentDictionary<Guid, Dictionary<int, string>> Items = new ConcurrentDictionary<Guid, Dictionary<int, string>>();
//private static volatile bool _isInitialize;
//private static readonly object Locker = new object();
/// <summary>
/// Gets the SQL helper.
@@ -34,55 +31,6 @@ namespace umbraco.cms.businesslogic.language
get { return Application.SqlHelper; }
}
///// <summary>
///// Populates the global hash table with the data from the database.
///// </summary>
//private static void EnsureCache()
//{
// if (!_isInitialize)
// {
// lock (Locker)
// {
// //double check
// if (!_isInitialize)
// {
// var dtos = ApplicationContext.Current.DatabaseContext.Database.Fetch<LanguageTextDto>("ORDER BY UniqueId");
// foreach (var dto in dtos)
// {
// var languageId = dto.LanguageId;
// var uniqueId = dto.UniqueId;
// var text = dto.Value;
// Items.AddOrUpdate(uniqueId, guid =>
// {
// var languagevalues = new Dictionary<int, string> { { languageId, text } };
// return languagevalues;
// }, (guid, dictionary) =>
// {
// // add/update the text for the id
// dictionary[languageId] = text;
// return dictionary;
// });
// }
// _isInitialize = true;
// }
// }
// }
//}
///// <summary>
///// Clears the cache, this is used for cache refreshers to ensure that the cache is up to date across all servers
///// </summary>
//internal static void ClearCache()
//{
// Items.Clear();
// //reset the flag so that we re-lookup the cache
// _isInitialize = false;
//}
/// <summary>
/// Retrieves the value of a languagetranslated item given the key
/// </summary>
@@ -91,13 +39,6 @@ namespace umbraco.cms.businesslogic.language
/// <returns>The language translated text</returns>
public static string Text(Guid key, int languageId)
{
//EnsureCache();
//Dictionary<int, string> val;
//if (Items.TryGetValue(key, out val))
//{
// return val[languageId];
//}
var item = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(key);
if (item != null)
@@ -120,15 +61,6 @@ namespace umbraco.cms.businesslogic.language
/// <returns>returns True if there is a value associated to the unique identifier with the specified language</returns>
public static bool hasText(Guid key, int languageId)
{
//EnsureCache();
//Dictionary<int, string> val;
//if (Items.TryGetValue(key, out val))
//{
// return val.ContainsKey(languageId);
//}
//return false;
try
{
return Text(key, languageId).IsNullOrWhiteSpace() == false;
@@ -167,13 +99,6 @@ namespace umbraco.cms.businesslogic.language
item.Translations = newTranslations;
ApplicationContext.Current.Services.LocalizationService.Save(item);
}
//if (!hasText(key, languageId)) throw new ArgumentException("Key does not exist");
//ApplicationContext.Current.DatabaseContext.Database.Update<LanguageTextDto>(
// string.Format("set {0} = @value where LanguageId = @languageId And UniqueId = @key",
// SqlSyntaxContext.SqlSyntaxProvider.GetQuotedColumnName("value")),
// new {value = value, languageId = languageId, key = key});
}
/// <summary>
@@ -203,15 +128,6 @@ namespace umbraco.cms.businesslogic.language
item.Translations = newTranslations;
ApplicationContext.Current.Services.LocalizationService.Save(item);
}
//if (hasText(key, languageId)) throw new ArgumentException("Key being add'ed already exists");
//ApplicationContext.Current.DatabaseContext.Database.Insert(new LanguageTextDto
// {
// LanguageId = languageId,
// Value = value,
// UniqueId = key
// });
}
/// <summary>
@@ -220,8 +136,6 @@ namespace umbraco.cms.businesslogic.language
/// <param name="key">Unique identifier</param>
public static void removeText(Guid key)
{
//// remove from database
//ApplicationContext.Current.DatabaseContext.Database.Delete<LanguageTextDto>("where UniqueId = @UniqueId", new { UniqueId = key });
var found = ApplicationContext.Current.Services.LocalizationService.GetDictionaryItemById(key);
if (found != null)
{
@@ -242,9 +156,6 @@ namespace umbraco.cms.businesslogic.language
{
ApplicationContext.Current.Services.LocalizationService.Delete(lang);
}
//// remove from database
//ApplicationContext.Current.DatabaseContext.Database.Delete<LanguageTextDto>("where languageId = @languageId", new { languageId = languageId });
}
}
}