From 3528d3f69ccd7ea0f36dbc6f9538b919c539d2ab Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 27 Sep 2018 19:38:50 +0000 Subject: [PATCH] --- server/AyaNova/biz/Search.cs | 17 +++++++++++++---- server/AyaNova/biz/UserBiz.cs | 10 +++++----- server/AyaNova/biz/WidgetBiz.cs | 27 +++++++++++++++++++++++++++ server/AyaNova/util/Seeder.cs | 28 ++++++++++++++++++++-------- 4 files changed, 65 insertions(+), 17 deletions(-) diff --git a/server/AyaNova/biz/Search.cs b/server/AyaNova/biz/Search.cs index ca5613b8..495d51bb 100644 --- a/server/AyaNova/biz/Search.cs +++ b/server/AyaNova/biz/Search.cs @@ -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(); 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(); 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 diff --git a/server/AyaNova/biz/UserBiz.cs b/server/AyaNova/biz/UserBiz.cs index 6d7b5e62..5f5609ef 100644 --- a/server/AyaNova/biz/UserBiz.cs +++ b/server/AyaNova/biz/UserBiz.cs @@ -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; diff --git a/server/AyaNova/biz/WidgetBiz.cs b/server/AyaNova/biz/WidgetBiz.cs index e27da3e6..effb2ca6 100644 --- a/server/AyaNova/biz/WidgetBiz.cs +++ b/server/AyaNova/biz/WidgetBiz.cs @@ -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 diff --git a/server/AyaNova/util/Seeder.cs b/server/AyaNova/util/Seeder.cs index 21d59d82..6b327053 100644 --- a/server/AyaNova/util/Seeder.cs +++ b/server/AyaNova/util/Seeder.cs @@ -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());