This commit is contained in:
@@ -415,45 +415,52 @@ namespace AyaNova.Biz
|
||||
List<MatchingDictionaryEntry> MatchingKeywordIdList = new List<MatchingDictionaryEntry>();
|
||||
|
||||
|
||||
//######### 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<long, string> 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<long, string> 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<SearchDictionary>();
|
||||
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<SearchDictionary>();
|
||||
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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user