diff --git a/server/AyaNova/biz/Search.cs b/server/AyaNova/biz/Search.cs index dde805df..3d0ab2ac 100644 --- a/server/AyaNova/biz/Search.cs +++ b/server/AyaNova/biz/Search.cs @@ -415,45 +415,52 @@ namespace AyaNova.Biz List MatchingKeywordIdList = new List(); - //######### FROM HERE NEEDS TO LOCK SEARCHDICTIONARY FROM HERE TO ADDING NEW WORDS - using (var transaction = ct.Database.BeginTransaction()) + + //ITERATE ALL THE KEYWORDS, SEARCH IN THE SEARCHDICTIONARY TABLE AND COLLECT ID'S OF ANY PRE-EXISTING IN DB KEYWORDS + var ExistingKeywordMatches = ct.SearchDictionary.Where(m => KeyWordList.Contains(m.Word)).ToDictionary(m => m.Id, m => m.Word); + //Put the matching keyword ID's into the list + foreach (KeyValuePair K in ExistingKeywordMatches) { - //ITERATE ALL THE KEYWORDS, SEARCH IN THE SEARCHDICTIONARY TABLE AND COLLECT ID'S OF ANY PRE-EXISTING IN DB KEYWORDS - var ExistingKeywordMatches = ct.SearchDictionary.Where(m => KeyWordList.Contains(m.Word)).ToDictionary(m => m.Id, m => m.Word); - //Put the matching keyword ID's into the list - foreach (KeyValuePair K in ExistingKeywordMatches) - { - bool IsName = false; - if (NameKeyWordList.Contains(K.Value)) - IsName = true; - MatchingKeywordIdList.Add(new MatchingDictionaryEntry() { DictionaryId = K.Key, InName = IsName }); - } + bool IsName = false; + if (NameKeyWordList.Contains(K.Value)) + IsName = true; + MatchingKeywordIdList.Add(new MatchingDictionaryEntry() { DictionaryId = K.Key, InName = IsName }); + } - //ITERATE THROUGH THE KEYWORDS THAT DO *NOT* HAVE MATCHES IN THE SEARCHDICTIONARY AND ADD THEM TO THE SEARCH DICTIONARY, COLLECTING THEIR ID'S - bool NewWordsAdded = false; - var NewSearchDictionaryWordsList = new List(); - foreach (string KeyWord in KeyWordList) + //ITERATE THROUGH THE KEYWORDS THAT DO *NOT* HAVE MATCHES IN THE SEARCHDICTIONARY AND ADD THEM TO THE SEARCH DICTIONARY, COLLECTING THEIR ID'S + bool NewWordsAdded = false; + var NewSearchDictionaryWordsList = new List(); + foreach (string KeyWord in KeyWordList) + { + if (!ExistingKeywordMatches.ContainsValue(KeyWord)) { - if (!ExistingKeywordMatches.ContainsValue(KeyWord)) - { - NewSearchDictionaryWordsList.Add(new SearchDictionary() { Word = KeyWord }); - NewWordsAdded = true; - } + NewSearchDictionaryWordsList.Add(new SearchDictionary() { Word = KeyWord }); + NewWordsAdded = true; } + } - //Save the context in order to get the id's of the new words added - if (NewWordsAdded) + //Save the context in order to get the id's of the new words added + if (NewWordsAdded) + { + //adding in a range sped this up noticeably + ct.SearchDictionary.AddRange(NewSearchDictionaryWordsList); + try { - //adding in a range sped this up noticeably - ct.SearchDictionary.AddRange(NewSearchDictionaryWordsList); ct.SaveChanges(); } + catch (Exception ex) + { + //In integration testing hit duplicate values of widget names + //adjusted uniquify code in test util class to use milliseconds instead of seconds (duh) and didn't hit this again, + //however just in case I'm leaving it here as a potential debug break point if it arises again + //Outside of a test situation I can't imagine this will be an issue in actual production use + //as it seems unlikely that two separate manual users inputting data are going to generate the same word at the same exact moment + //in time + throw ex; + } + } - transaction.Commit(); - }//end transaction - //######################### - - + //----- //Now add the id's of the newly created words to the matching keyword id list for this object diff --git a/test/raven-integration/Widget/WidgetRights.cs b/test/raven-integration/Widget/WidgetRights.cs index 9c2a927f..b6778a8e 100644 --- a/test/raven-integration/Widget/WidgetRights.cs +++ b/test/raven-integration/Widget/WidgetRights.cs @@ -112,7 +112,7 @@ namespace raven_integration uint OriginalConcurrencyToken = a.ObjectResponse["result"]["concurrencyToken"].Value(); //Now TechFullAuthToken attempt to modify it via patch - var newName = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToPatchNonOwned - UPDATED TEST WIDGET"); + var newName = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToPatchNonOwned - UPDATED TEST WIDGETB"); string patchJson = "[{\"value\": \"" + newName + "\",\"path\": \"/name\",\"op\": \"replace\"}]"; a = await Util.PatchAsync("Widget/" + Id.ToString() + "/" + OriginalConcurrencyToken.ToString(), await Util.GetTokenAsync( "TechFull"), patchJson); //2004 unauthorized expected diff --git a/test/raven-integration/util.cs b/test/raven-integration/util.cs index 0dbc0a55..e4367b55 100644 --- a/test/raven-integration/util.cs +++ b/test/raven-integration/util.cs @@ -22,7 +22,7 @@ namespace raven_integration public static string Uniquify(string s) { - return s + ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds(); + return s + ((DateTimeOffset)DateTime.Now).ToUnixTimeMilliseconds().ToString(); } public async static Task GetTokenAsync(string login, string password = null)