This commit is contained in:
2018-09-27 19:38:50 +00:00
parent 03b21d29b4
commit 3528d3f69c
4 changed files with 65 additions and 17 deletions

View File

@@ -394,18 +394,23 @@ namespace AyaNova.Biz
//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))
{
ct.SearchDictionary.Add(new SearchDictionary() { Word = KeyWord });
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)
{
//adding in a range sped this up noticeably
ct.SearchDictionary.AddRange(NewSearchDictionaryWordsList);
ct.SaveChanges();
}
//-----
@@ -432,14 +437,18 @@ namespace AyaNova.Biz
}
//CREATE THE SEARCHKEY RECORDS FOR ALL THE KEYWORDS
var NewSearchKeyList = new List<SearchKey>();
foreach (MatchingDictionaryEntry E in MatchingKeywordIdList)
{
ct.SearchKey.Add(new SearchKey() { WordId = E.DictionaryId, InName = E.InName, ObjectId = objectID, ObjectType = objectType });
NewSearchKeyList.Add(new SearchKey() { WordId = E.DictionaryId, InName = E.InName, ObjectId = objectID, ObjectType = objectType });
//ct.SearchKey.Add(new SearchKey() { WordId = E.DictionaryId, InName = E.InName, ObjectId = objectID, ObjectType = objectType });
}
ct.SearchKey.AddRange(NewSearchKeyList);
ct.SaveChanges();
//---------------------------------
ct.SaveChanges();
}//eoc

View File

@@ -95,7 +95,7 @@ namespace AyaNova.Biz
////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE
internal User Create(User inObj)
internal User Create(AyContext TempContext, User inObj)
{
//This is a new user so it will have been posted with a password in plaintext which needs to be salted and hashed
inObj.Salt = Hasher.GenerateSalt();
@@ -113,18 +113,18 @@ namespace AyaNova.Biz
if (outObj.UserOptions == null)
outObj.UserOptions = new UserOptions(UserId);
ct.User.Add(outObj);
TempContext.User.Add(outObj);
//save to get Id
ct.SaveChanges();
TempContext.SaveChanges();
//Handle child and associated items
//Log event
EventLogProcessor.AddEntryToContextNoSave(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), ct);
EventLogProcessor.AddEntryToContextNoSave(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext);
//ct.SaveChanges();
//SEARCH INDEXING
Search.ProcessNewObjectKeywords(ct, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.EmployeeNumber, outObj.Notes, outObj.Name);
Search.ProcessNewObjectKeywords(TempContext, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.EmployeeNumber, outObj.Notes, outObj.Name);
return outObj;

View File

@@ -73,6 +73,33 @@ namespace AyaNova.Biz
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
//CREATE
internal Widget Create(AyContext TempContext, Widget inObj)
{
Validate(inObj, true);
if (HasErrors)
return null;
else
{
//do stuff with widget
Widget outObj = inObj;
outObj.OwnerId = UserId;
TempContext.Widget.Add(outObj);
TempContext.SaveChanges();
//Handle child and associated items:
//EVENT LOG
EventLogProcessor.AddEntryToContextNoSave(new Event(UserId, outObj.Id, BizType, AyaEvent.Created), TempContext);
//SEARCH INDEXING
Search.ProcessNewObjectKeywords(TempContext, UserLocaleId, outObj.Id, BizType, outObj.Name, outObj.Notes, outObj.Name);
return outObj;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////
/// GET

View File

@@ -165,13 +165,21 @@ namespace AyaNova.Util
//PERF
watch.Stop();
log.LogInformation($"** (SYNC) Users seeded in {watch.ElapsedMilliseconds} ms");
log.LogInformation($"Users seeded in {watch.ElapsedMilliseconds} ms");
//20000 widgets
for (int i = 0; i < 400; i++)
{
GenSeedWidget(log, 50);
}
log.LogInformation($"Seeding Widgets....");
watch = new Stopwatch();
watch.Start();
GenSeedWidget(log, 20000);
// for (int i = 0; i < 400; i++)
// {
// GenSeedWidget(log, 50);
// }
//PERF
watch.Stop();
log.LogInformation($"Widgets seeded in {watch.ElapsedMilliseconds} ms");
break;
}
@@ -306,9 +314,13 @@ namespace AyaNova.Util
u.UserOptions = new UserOptions(1);
u.UserOptions.EmailAddress = p.Email.Replace("gmail.com", "helloayanova.com").Replace("hotmail.com", "helloayanova.com").Replace("yahoo.com", "helloayanova.com");
//var NewObject = Biz.CreateAsync(u).Result;
var NewObject = Biz.Create(u);//sync version seems consistently faster than async one
//Re-instantiating the biz object in the loop speeds it up probably due to db context losing changes to track from before
// UserBiz Biz = UserBiz.GetBizInternal(ServiceProviderProvider.DBContext);
// //allow creation of not entirely ready users (missing client id or subcontractor vendor id etc)
// Biz.SeedOrImportRelaxedRulesMode = true;
var NewObject = Biz.Create(ServiceProviderProvider.DBContext, u);//sync version faster than async one
if (NewObject == null)
{
log.LogError($"Seeder::GenSeedUser error creating user {u.Name}\r\n" + Biz.GetErrorsAsString());
@@ -343,7 +355,7 @@ namespace AyaNova.Util
//this is nonsense but just to test an enum
o.Roles = AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited;
o.Notes = f.Lorem.Paragraph();
var NewObject = Biz.CreateAsync(o).Result;
var NewObject = Biz.Create(ServiceProviderProvider.DBContext, o);
if (NewObject == null)
{
log.LogError($"Seeder::GenSeedWidget error creating widget {o.Name}\r\n" + Biz.GetErrorsAsString());