This commit is contained in:
2018-09-27 17:15:42 +00:00
parent a30d0f11cd
commit 03b21d29b4
17 changed files with 135 additions and 51 deletions

View File

@@ -23,7 +23,7 @@ namespace AyaNova.Util
private const int DESIRED_SCHEMA_LEVEL = 9;
internal const long EXPECTED_COLUMN_COUNT = 99;
internal const long EXPECTED_INDEX_COUNT = 20;
internal const long EXPECTED_INDEX_COUNT = 21;
//!!!!WARNING: BE SURE TO UPDATE THE DbUtil::PrepareDatabaseForSeeding WHEN NEW TABLES ADDED!!!!
/////////////////////////////////////////////////////////////////
@@ -136,7 +136,7 @@ namespace AyaNova.Util
//too little is bad if search takes a dogs age to find anything
exec("CREATE TABLE asearchdictionary (id BIGSERIAL PRIMARY KEY, word varchar(255) not null)");
// exec("CREATE UNIQUE INDEX tagname_idx ON atag (name);");
exec("CREATE UNIQUE INDEX searchdictword_idx ON asearchdictionary (word);");
exec("CREATE TABLE asearchkey (id BIGSERIAL PRIMARY KEY, wordid bigint not null REFERENCES asearchdictionary (id), objectid bigint not null, objecttype integer not null, inname bool not null)");
//create locale text tables

View File

@@ -6,6 +6,7 @@ using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using Bogus;
using AyaNova.Api.ControllerHelpers;
using System.Diagnostics;
namespace AyaNova.Util
@@ -46,10 +47,10 @@ namespace AyaNova.Util
DbUtil.PrepareDatabaseForSeeding(log);
//Seed special test data for integration testing
log.LogInformation("Seeding known users");
//log.LogInformation("Seeding known users");
SeedKnownUsers(log);
log.LogInformation("Seeding all other data");
//log.LogInformation("Seeding all other data");
switch (slevel)
{
@@ -109,6 +110,12 @@ namespace AyaNova.Util
//this is a large corporation with multiple branches in multiple locations all in the same country
//Each location has a full staff and corporate head office has an overarching staff member in charge of each location
case SeedLevel.LargeCorporateMultiRegionalTrialDataSet:
//PERF
log.LogInformation($"Seeding user(s)....");
var watch = new Stopwatch();
watch.Start();
//IT administrator, can change ops but nothing else
GenSeedUser(log, 2, AuthorizationRoles.OpsAdminFull, UserType.NonSchedulable);
@@ -119,7 +126,12 @@ namespace AyaNova.Util
GenSeedUser(log, 5, AuthorizationRoles.DispatchLimited | AuthorizationRoles.InventoryLimited | AuthorizationRoles.OpsAdminLimited, UserType.NonSchedulable);
//techs
GenSeedUser(log, 100, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited, UserType.Schedulable);
//GenSeedUser(log, 100, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited, UserType.Schedulable);
for (int i = 0; i < 20; i++)
{
GenSeedUser(log, 5, AuthorizationRoles.TechFull | AuthorizationRoles.DispatchLimited, UserType.Schedulable);
}
//limited techs
GenSeedUser(log, 50, AuthorizationRoles.TechLimited | AuthorizationRoles.DispatchLimited, UserType.Schedulable);
@@ -146,13 +158,20 @@ namespace AyaNova.Util
GenSeedUser(log, 5, AuthorizationRoles.AccountingFull | AuthorizationRoles.BizAdminLimited, UserType.NonSchedulable);
//100 full on client users
GenSeedUser(log, 100, AuthorizationRoles.ClientFull, UserType.Client);
GenSeedUser(log, 20, AuthorizationRoles.ClientFull, UserType.Client);
//100 limited client users
GenSeedUser(log, 100, AuthorizationRoles.ClientLimited, UserType.Client);
GenSeedUser(log, 20, AuthorizationRoles.ClientLimited, UserType.Client);
//PERF
watch.Stop();
log.LogInformation($"** (SYNC) Users seeded in {watch.ElapsedMilliseconds} ms");
//20000 widgets
GenSeedWidget(log, 20000);
for (int i = 0; i < 400; i++)
{
GenSeedWidget(log, 50);
}
break;
}
@@ -172,6 +191,12 @@ namespace AyaNova.Util
}
public static long RUNNING_COUNT = 0;
public static string Uniquify(string s)
{
//return s + " " + ((DateTimeOffset)DateTime.Now).ToUnixTimeSeconds();
return s + " " + (++RUNNING_COUNT).ToString();
}
//////////////////////////////////////////////////////
@@ -239,9 +264,15 @@ namespace AyaNova.Util
}
public async static void GenSeedUser(ILogger log, int count, AuthorizationRoles roles, UserType userType, bool active = true, string login = null, string password = null)
public static void GenSeedUser(ILogger log, int count, AuthorizationRoles roles, UserType userType, bool active = true, string login = null, string password = null)
{
log.LogInformation($"Seeding {count.ToString()} user(s)");
// log.LogInformation($"Seeding {count.ToString()} user(s)");
//var watch = new Stopwatch();
//watch.Start();
UserBiz Biz = UserBiz.GetBizInternal(ServiceProviderProvider.DBContext);
//allow creation of not entirely ready users (missing client id or subcontractor vendor id etc)
Biz.SeedOrImportRelaxedRulesMode = true;
@@ -252,7 +283,7 @@ namespace AyaNova.Util
u.Active = active;
u.OwnerId = 1;
var p = new Bogus.Person();
u.Name = p.FullName;
u.Name = Uniquify(p.FullName);
// u.Salt = Hasher.GenerateSalt();
if (login != null)
{
@@ -275,22 +306,27 @@ 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 = await Biz.CreateAsync(u);
//var NewObject = Biz.CreateAsync(u).Result;
var NewObject = Biz.Create(u);//sync version seems consistently faster than async one
if (NewObject == null)
{
log.LogError($"Seeder::GenSeedUser error creating user {u.Name}\r\n" + Biz.GetErrorsAsString());
throw new System.Exception("Seeder::GenSeedUser error creating user\r\n" + Biz.GetErrorsAsString());
}
}
log.LogInformation("User seeding completed");
// watch.Stop();
// log.LogInformation($"{count.ToString()} user(s) seeded in {watch.ElapsedMilliseconds} ms");
}
//////////////////////////////////////////////////////
//Seed widget for testing
//
public static async void GenSeedWidget(ILogger log, int count)
public static void GenSeedWidget(ILogger log, int count)
{
log.LogInformation($"Seeding {count.ToString()} Widget(s)");
var watch = new Stopwatch();
watch.Start();
//get a context just for this op to save memory on changetracking
//AyContext ct = ServiceProviderProvider.DBContext;
WidgetBiz Biz = WidgetBiz.GetBizInternal(ServiceProviderProvider.DBContext);
@@ -298,7 +334,7 @@ namespace AyaNova.Util
for (int x = 0; x < count; x++)
{
Widget o = new Widget();
o.Name = f.Commerce.ProductName() + x.ToString();
o.Name = Uniquify(f.Commerce.ProductName());
o.Active = true;
o.StartDate = f.Date.Between(DateTime.Now, DateTime.Now.AddMinutes(60));
o.EndDate = f.Date.Between(DateTime.Now.AddMinutes(90), DateTime.Now.AddHours(5));
@@ -307,14 +343,15 @@ 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 = await Biz.CreateAsync(o);
var NewObject = Biz.CreateAsync(o).Result;
if (NewObject == null)
{
log.LogError($"Seeder::GenSeedWidget error creating widget {o.Name}\r\n" + Biz.GetErrorsAsString());
throw new System.Exception("Seeder::GenSeedWidget error creating widget\r\n" + Biz.GetErrorsAsString());
}
}
log.LogInformation("Widget seeding completed");
watch.Stop();
log.LogInformation($"{count.ToString()} Widget(s) seeded in {watch.ElapsedMilliseconds} ms");
}
}//eoc