This commit is contained in:
@@ -3,7 +3,8 @@
|
|||||||
{"login": "OpsAdminLimited","password": "OpsAdminLimited"}
|
{"login": "OpsAdminLimited","password": "OpsAdminLimited"}
|
||||||
|
|
||||||
|
|
||||||
|
todo: FAKER, is there a leak, do I need to dispose of it somehow, am I using it right?
|
||||||
|
(it appeared high in objects in allocated memory when investigating memory consumption)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ namespace AyaNova.Api.Controllers
|
|||||||
// //test allocation and cleanup
|
// //test allocation and cleanup
|
||||||
// for (int x = 0; x < 100000; x++)
|
// for (int x = 0; x < 100000; x++)
|
||||||
// {
|
// {
|
||||||
// AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext;
|
// using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||||
// var v=await ct.Widget.Where(z=>z.Serial<100).ToListAsync();
|
// var v=await ct.Widget.Where(z=>z.Serial<100).ToListAsync();
|
||||||
// // int i = await ct.Database.ExecuteSqlRawAsync($"select * from aglobalbizsettings");
|
// // int i = await ct.Database.ExecuteSqlRawAsync($"select * from aglobalbizsettings");
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ namespace AyaNova.Biz
|
|||||||
log.LogTrace("Sweep starting");
|
log.LogTrace("Sweep starting");
|
||||||
using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext)
|
using (AyContext ct = AyaNova.Util.ServiceProviderProvider.DBContext)
|
||||||
{
|
{
|
||||||
|
|
||||||
//SWEEP SUCCESSFUL JOBS
|
//SWEEP SUCCESSFUL JOBS
|
||||||
//calculate cutoff to delete
|
//calculate cutoff to delete
|
||||||
DateTime dtDeleteCutoff = DateTime.UtcNow - SUCCEEDED_JOBS_DELETE_AFTER_THIS_TIMESPAN;
|
DateTime dtDeleteCutoff = DateTime.UtcNow - SUCCEEDED_JOBS_DELETE_AFTER_THIS_TIMESPAN;
|
||||||
@@ -64,7 +63,6 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
private static async Task sweepAsync(AyContext ct, DateTime dtDeleteCutoff, JobStatus jobStatus)
|
private static async Task sweepAsync(AyContext ct, DateTime dtDeleteCutoff, JobStatus jobStatus)
|
||||||
{
|
{
|
||||||
// AyContext ct = ServiceProviderProvider.DBContext;
|
|
||||||
//Get the deleteable succeeded jobs list
|
//Get the deleteable succeeded jobs list
|
||||||
var jobs = await ct.OpsJob
|
var jobs = await ct.OpsJob
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
@@ -96,8 +94,6 @@ namespace AyaNova.Biz
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private static async Task killStuckJobsAsync(AyContext ct, DateTime dtRunningDeadline)
|
private static async Task killStuckJobsAsync(AyContext ct, DateTime dtRunningDeadline)
|
||||||
{
|
{
|
||||||
|
|
||||||
// AyContext ct = ServiceProviderProvider.DBContext;
|
|
||||||
//Get the deleteable succeeded jobs list
|
//Get the deleteable succeeded jobs list
|
||||||
var jobs = await ct.OpsJob
|
var jobs = await ct.OpsJob
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
@@ -119,7 +115,6 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
private static async Task SweepInternalJobsLogsAsync(AyContext ct, DateTime dtDeleteCutoff)
|
private static async Task SweepInternalJobsLogsAsync(AyContext ct, DateTime dtDeleteCutoff)
|
||||||
{
|
{
|
||||||
// AyContext ct = ServiceProviderProvider.DBContext;
|
|
||||||
//Get the deleteable list (this is for reporting, could easily just do it in one go)
|
//Get the deleteable list (this is for reporting, could easily just do it in one go)
|
||||||
var logs = await ct.OpsJobLog
|
var logs = await ct.OpsJobLog
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
|
|||||||
@@ -87,9 +87,6 @@ namespace AyaNova.Util
|
|||||||
apiServerState.SetOpsOnly("Seeding database with sample data");
|
apiServerState.SetOpsOnly("Seeding database with sample data");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//WIDGET sample form customization
|
//WIDGET sample form customization
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -140,15 +137,12 @@ namespace AyaNova.Util
|
|||||||
};
|
};
|
||||||
|
|
||||||
//Create and save to db
|
//Create and save to db
|
||||||
using (var cct = ServiceProviderProvider.DBContext)
|
using (var ct = ServiceProviderProvider.DBContext)
|
||||||
{
|
await FormCustomBiz.GetBiz(ct).CreateAsync(fc);
|
||||||
await FormCustomBiz.GetBiz(cct).CreateAsync(fc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Create a couple of DataListView's for development and testing
|
//Create a couple of DataListView's for development and testing
|
||||||
{
|
{
|
||||||
|
|
||||||
var dlv = new DataListView()
|
var dlv = new DataListView()
|
||||||
{
|
{
|
||||||
Name = "Name starts with generic",
|
Name = "Name starts with generic",
|
||||||
@@ -156,14 +150,11 @@ namespace AyaNova.Util
|
|||||||
ListKey = "TestWidgetDataList",
|
ListKey = "TestWidgetDataList",
|
||||||
Public = true,
|
Public = true,
|
||||||
ListView = @"[{""fld"": ""widgetname"",""filter"": {""any"":false,""items"": [{""op"": ""%-"",""value"": ""Generic""}]}}]"
|
ListView = @"[{""fld"": ""widgetname"",""filter"": {""any"":false,""items"": [{""op"": ""%-"",""value"": ""Generic""}]}}]"
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//Create and save to db
|
//Create and save to db
|
||||||
using (var cct = ServiceProviderProvider.DBContext)
|
using (var ct = ServiceProviderProvider.DBContext)
|
||||||
{
|
await DataListViewBiz.GetBiz(ct).CreateAsync(dlv);
|
||||||
await DataListViewBiz.GetBiz(cct).CreateAsync(dlv);
|
|
||||||
}
|
|
||||||
|
|
||||||
dlv = new DataListView()
|
dlv = new DataListView()
|
||||||
{
|
{
|
||||||
@@ -172,14 +163,11 @@ namespace AyaNova.Util
|
|||||||
ListKey = "TestWidgetDataList",
|
ListKey = "TestWidgetDataList",
|
||||||
Public = true,
|
Public = true,
|
||||||
ListView = @"[{""fld"": ""widgetname"",""filter"": {""any"":false,""items"": [{""op"": ""%-"",""value"": ""Awesome""}]}},{""fld"":""widgetserial""},{""fld"":""widgetdollaramount""},{""fld"":""widgetusertype""},{""fld"":""widgetstartdate""},{""fld"":""widgetactive""},{""fld"":""username""},{""fld"":""widgettags""},{""fld"":""widgetcustom1""},{""fld"":""widgetcustom2""}]"
|
ListView = @"[{""fld"": ""widgetname"",""filter"": {""any"":false,""items"": [{""op"": ""%-"",""value"": ""Awesome""}]}},{""fld"":""widgetserial""},{""fld"":""widgetdollaramount""},{""fld"":""widgetusertype""},{""fld"":""widgetstartdate""},{""fld"":""widgetactive""},{""fld"":""username""},{""fld"":""widgettags""},{""fld"":""widgetcustom1""},{""fld"":""widgetcustom2""}]"
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//Create and save to db
|
//Create and save to db
|
||||||
using (var cct = ServiceProviderProvider.DBContext)
|
using (var ct = ServiceProviderProvider.DBContext)
|
||||||
{
|
await DataListViewBiz.GetBiz(ct).CreateAsync(dlv);
|
||||||
await DataListViewBiz.GetBiz(cct).CreateAsync(dlv);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -560,13 +548,6 @@ namespace AyaNova.Util
|
|||||||
if (translationId == 0)
|
if (translationId == 0)
|
||||||
translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
|
translationId = ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID;
|
||||||
|
|
||||||
//Don't do the following commented out, it's slower
|
|
||||||
// using (var ct = ServiceProviderProvider.DBContext)
|
|
||||||
// {
|
|
||||||
// UserBiz Biz = UserBiz.GetBiz(ct);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Faker Fake = new Faker();
|
Faker Fake = new Faker();
|
||||||
|
|
||||||
for (int x = 0; x < count; x++)
|
for (int x = 0; x < count; x++)
|
||||||
@@ -731,19 +712,19 @@ namespace AyaNova.Util
|
|||||||
// ***
|
// ***
|
||||||
// ";
|
// ";
|
||||||
|
|
||||||
//this seems wrong but is actually faster!?
|
//this seems wrong to get a new context inside a loop but in testing is actually faster!?
|
||||||
UserBiz Biz = UserBiz.GetBiz(ServiceProviderProvider.DBContext);
|
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||||
|
{
|
||||||
|
UserBiz Biz = UserBiz.GetBiz(ct);
|
||||||
//allow creation of not entirely ready users (missing client id or subcontractor vendor id etc)
|
//allow creation of not entirely ready users (missing client id or subcontractor vendor id etc)
|
||||||
Biz.SeedOrImportRelaxedRulesMode = true;
|
Biz.SeedOrImportRelaxedRulesMode = true;
|
||||||
|
|
||||||
|
|
||||||
var NewObject = await Biz.CreateAsync(u);
|
var NewObject = await Biz.CreateAsync(u);
|
||||||
if (NewObject == null)
|
if (NewObject == null)
|
||||||
{
|
{
|
||||||
log.LogError($"Seeder::GenSeedUser error creating user {u.Name}\r\n" + Biz.GetErrorsAsString());
|
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());
|
throw new System.Exception("Seeder::GenSeedUser error creating user\r\n" + Biz.GetErrorsAsString());
|
||||||
}
|
}
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SeededUserCount += count;
|
SeededUserCount += count;
|
||||||
@@ -756,9 +737,9 @@ namespace AyaNova.Util
|
|||||||
{
|
{
|
||||||
//this is 4 times slower than doing it inside the loop below
|
//this is 4 times slower than doing it inside the loop below
|
||||||
//seems counterintuitive but maybe it's to do with the db context not being refreshed?
|
//seems counterintuitive but maybe it's to do with the db context not being refreshed?
|
||||||
// WidgetBiz biz = WidgetBiz.GetBiz(ServiceProviderProvider.DBContext);
|
|
||||||
|
|
||||||
var f = new Bogus.Faker();
|
|
||||||
|
var f = new Bogus.Faker();//todo: this *can't* be right, I'm seeding 20k widgets in some cases
|
||||||
|
|
||||||
|
|
||||||
//RANDOM ROLES
|
//RANDOM ROLES
|
||||||
@@ -772,23 +753,16 @@ namespace AyaNova.Util
|
|||||||
Widget o = new Widget();
|
Widget o = new Widget();
|
||||||
o.Name = Uniquify(f.Commerce.ProductName());
|
o.Name = Uniquify(f.Commerce.ProductName());
|
||||||
o.Active = true;
|
o.Active = true;
|
||||||
// o.StartDate = f.Date.Between(DateTime.Now, DateTime.Now.AddMinutes(60)).ToUniversalTime();
|
|
||||||
// o.EndDate = f.Date.Between(DateTime.Now.AddMinutes(90), DateTime.Now.AddHours(5)).ToUniversalTime();
|
|
||||||
|
|
||||||
// o.StartDate = DateTime.Now.ToUniversalTime();
|
|
||||||
// o.EndDate = DateTime.Now.AddMinutes(60).ToUniversalTime();
|
|
||||||
DateTime dtSeed = f.Date.Between(seedStartWindow, seedEndWindow).ToUniversalTime();
|
DateTime dtSeed = f.Date.Between(seedStartWindow, seedEndWindow).ToUniversalTime();
|
||||||
o.StartDate = dtSeed;
|
o.StartDate = dtSeed;
|
||||||
o.EndDate = dtSeed.AddMinutes(60).ToUniversalTime();
|
o.EndDate = dtSeed.AddMinutes(60).ToUniversalTime();
|
||||||
o.DollarAmount = Convert.ToDecimal(f.Commerce.Price());
|
o.DollarAmount = Convert.ToDecimal(f.Commerce.Price());
|
||||||
|
|
||||||
//Random but valid enum
|
//Random but valid enum
|
||||||
UserType randomUserType = (UserType)values.GetValue(random.Next(values.Length));
|
UserType randomUserType = (UserType)values.GetValue(random.Next(values.Length));
|
||||||
o.UserType = randomUserType;
|
o.UserType = randomUserType;
|
||||||
|
|
||||||
o.Notes = f.Lorem.Sentence(null, 5);
|
o.Notes = f.Lorem.Sentence(null, 5);
|
||||||
|
|
||||||
o.Tags = RandomTags(f);
|
o.Tags = RandomTags(f);
|
||||||
|
|
||||||
o.UserId = f.Random.Int(1, SeededUserCount);
|
o.UserId = f.Random.Int(1, SeededUserCount);
|
||||||
|
|
||||||
//RANDOM CUSTOM FIELD DATA
|
//RANDOM CUSTOM FIELD DATA
|
||||||
@@ -797,18 +771,19 @@ namespace AyaNova.Util
|
|||||||
var c3 = f.Random.Int(1, 99999999);
|
var c3 = f.Random.Int(1, 99999999);
|
||||||
var c4 = f.Random.Bool().ToString().ToLowerInvariant();
|
var c4 = f.Random.Bool().ToString().ToLowerInvariant();
|
||||||
var c5 = f.Random.Decimal();
|
var c5 = f.Random.Decimal();
|
||||||
|
|
||||||
o.CustomFields = $@"{{c1:""{c1}"",c2:""{c2}"",c3:{c3},c4:{c4},c5:{c5}}}";
|
o.CustomFields = $@"{{c1:""{c1}"",c2:""{c2}"",c3:{c3},c4:{c4},c5:{c5}}}";
|
||||||
|
|
||||||
//This seems wrong to do in a loop but is 4 times faster this way ?!?
|
//This seems wrong to do in a loop but is 4 times faster this way ?!?
|
||||||
WidgetBiz biz = WidgetBiz.GetBiz(ServiceProviderProvider.DBContext);
|
using (AyContext ct = ServiceProviderProvider.DBContext)
|
||||||
|
{
|
||||||
|
WidgetBiz biz = WidgetBiz.GetBiz(ct);
|
||||||
var NewObject = await biz.CreateAsync(o);
|
var NewObject = await biz.CreateAsync(o);
|
||||||
if (NewObject == null)
|
if (NewObject == null)
|
||||||
{
|
{
|
||||||
log.LogError($"Seeder::GenSeedWidget error creating widget {o.Name}\r\n" + biz.GetErrorsAsString());
|
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());
|
throw new System.Exception("Seeder::GenSeedWidget error creating widget\r\n" + biz.GetErrorsAsString());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user