From e064de3401e972e8366f3c8a855a3f729e17f229 Mon Sep 17 00:00:00 2001
From: "M.A" <8120158+mkahvi@users.noreply.github.com>
Date: Sun, 20 Mar 2022 17:19:49 +0200
Subject: [PATCH 1/7] Make CRUD setting fetching easily extensible
---
module/classes/DevModeConfig.mjs | 6 +++---
templates/settings.hbs | 3 ++-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/module/classes/DevModeConfig.mjs b/module/classes/DevModeConfig.mjs
index c03457f..3bb6c64 100644
--- a/module/classes/DevModeConfig.mjs
+++ b/module/classes/DevModeConfig.mjs
@@ -188,9 +188,9 @@ export class DevModeConfig extends FormApplication {
switch (event.currentTarget?.dataset?.action) {
case 'actorCRUD': {
- const inputVal = html.find('input[name="actorCrudIterations"]').val();
- console.log('inputVal', inputVal);
- return DevModePerformance.actorCRUDTest(inputVal || undefined);
+ const form = new FormDataExtended(event.currentTarget.closest('form')).toObject();
+ const iterations = form.actorCrudIterations;
+ return DevModePerformance.actorCRUDTest(iterations || undefined);
}
default:
return;
diff --git a/templates/settings.hbs b/templates/settings.hbs
index e433a60..c4a1aae 100644
--- a/templates/settings.hbs
+++ b/templates/settings.hbs
@@ -90,7 +90,8 @@
From aed7b96bbbc4a9fee915b158df858efc5569ed8a Mon Sep 17 00:00:00 2001
From: "M.A" <8120158+mkahvi@users.noreply.github.com>
Date: Sun, 20 Mar 2022 17:22:54 +0200
Subject: [PATCH 2/7] Add actor type selection
---
module/classes/DevModeConfig.mjs | 7 ++++++-
module/classes/DevModePerformance.mjs | 5 +++--
templates/settings.hbs | 9 +++++++--
3 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/module/classes/DevModeConfig.mjs b/module/classes/DevModeConfig.mjs
index 3bb6c64..5735b79 100644
--- a/module/classes/DevModeConfig.mjs
+++ b/module/classes/DevModeConfig.mjs
@@ -164,6 +164,10 @@ export class DevModeConfig extends FormApplication {
packageSpecificDebugFormData,
debugOverrideFormData,
overrideConfigDebug: game.settings.get(DevMode.MODULE_ID, DevMode.SETTINGS.overrideConfigDebug),
+ actorTypes: game.system.template.Actor.types.reduce((types, type) => {
+ types[type] = `ACTOR.Type${type.capitalize()}`;
+ return types;
+ }, {}),
};
DevMode.log(false, data, {
@@ -189,8 +193,9 @@ export class DevModeConfig extends FormApplication {
switch (event.currentTarget?.dataset?.action) {
case 'actorCRUD': {
const form = new FormDataExtended(event.currentTarget.closest('form')).toObject();
+ const actorType = form.actorCrudType;
const iterations = form.actorCrudIterations;
- return DevModePerformance.actorCRUDTest(iterations || undefined);
+ return DevModePerformance.actorCRUDTest(actorType, iterations || undefined);
}
default:
return;
diff --git a/module/classes/DevModePerformance.mjs b/module/classes/DevModePerformance.mjs
index a18dfe5..7f120ee 100644
--- a/module/classes/DevModePerformance.mjs
+++ b/module/classes/DevModePerformance.mjs
@@ -17,14 +17,15 @@ export class DevModePerformance {
});
}
- static actorCRUDTest = async (iterations = 1000) => {
+ static actorCRUDTest = async (type, iterations = 1000) => {
console.log('running test with iterations:', `${iterations}`, !!iterations, iterations || 1000);
+ if (!game.system.template.Actor.types.includes(type)) return console.error(type, "is invalid actor type");
const debugConfig = { ...CONFIG.debug };
this.resetDebug();
const now = performance.now();
for (let x = 0; x <= iterations; x++) {
- const created = await Actor.create({ name: `${x}`, type: 'npc' });
+ const created = await Actor.create({ name: `${x}`, type });
await created.update({ name: 'Actor' + x });
await created.delete();
if (x % 10 == 0) SceneNavigation.displayProgressBar({ label: 'Test Progress', pct: (x / iterations) * 100 });
diff --git a/templates/settings.hbs b/templates/settings.hbs
index c4a1aae..16770d8 100644
--- a/templates/settings.hbs
+++ b/templates/settings.hbs
@@ -85,8 +85,13 @@
{{localize 'DEV.configMenu.performance.hint'}}
- {{localize
- 'DEV.configMenu.performance.actorCRUD.label'}}
+ {{localize 'DEV.configMenu.performance.actorCRUD.label'}}
+
+
+
+
+
+
+
+
{{localize 'DEV.configMenu.performance.actorCRUD.hint'}}
From bc13667b66e6be907601a0f2dd0680cac1a4c5bb Mon Sep 17 00:00:00 2001
From: "M.A" <8120158+mkahvi@users.noreply.github.com>
Date: Sun, 20 Mar 2022 17:25:55 +0200
Subject: [PATCH 4/7] Touchup
---
module/classes/DevModePerformance.mjs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/module/classes/DevModePerformance.mjs b/module/classes/DevModePerformance.mjs
index d40c89b..fb6259a 100644
--- a/module/classes/DevModePerformance.mjs
+++ b/module/classes/DevModePerformance.mjs
@@ -18,8 +18,11 @@ export class DevModePerformance {
}
static actorCRUDTest = async (type, iterations = 1000, synthetic) => {
- console.log('running test with iterations:', `${iterations}`, !!iterations, iterations || 1000);
if (!game.system.template.Actor.types.includes(type)) return console.error(type, "is invalid actor type");
+ // Force some defaults
+ iterations ||= 1000;
+ synthetic ??= true;
+ console.log(`Running CRUD test on "${type}" type with ${iterations} iterations`);
const debugConfig = { ...CONFIG.debug };
this.resetDebug();
From 8832c04d01710f47fa44e9ffbac17eb915535baa Mon Sep 17 00:00:00 2001
From: "M.A" <8120158+mkahvi@users.noreply.github.com>
Date: Sun, 20 Mar 2022 17:52:00 +0200
Subject: [PATCH 5/7] Pass arguments as object
---
module/classes/DevModeConfig.mjs | 8 ++------
templates/settings.hbs | 4 ++--
2 files changed, 4 insertions(+), 8 deletions(-)
diff --git a/module/classes/DevModeConfig.mjs b/module/classes/DevModeConfig.mjs
index 50a0df2..1dc2833 100644
--- a/module/classes/DevModeConfig.mjs
+++ b/module/classes/DevModeConfig.mjs
@@ -192,12 +192,8 @@ export class DevModeConfig extends FormApplication {
switch (event.currentTarget?.dataset?.action) {
case 'actorCRUD': {
- const form = new FormDataExtended(event.currentTarget.closest('form')).toObject();
- const actorType = form.actorCrudType;
- const iterations = form.actorCrudIterations;
- const synthetic = form.actorCrudSynthetic;
- console.log('CRUD', { actorType, iterations, synthetic });
- return DevModePerformance.actorCRUDTest(actorType, iterations || undefined, synthetic);
+ const formData = expandObject(new FormDataExtended(event.currentTarget.closest('form')).toObject());
+ return DevModePerformance.actorCRUDTest(formData.actorCrud);
}
default:
return;
diff --git a/templates/settings.hbs b/templates/settings.hbs
index 9ad27b5..57d83b2 100644
--- a/templates/settings.hbs
+++ b/templates/settings.hbs
@@ -88,14 +88,14 @@
{{localize 'DEV.configMenu.performance.actorCRUD.label'}}
-
From 5b60bae3b0081fecf0243f46977a2843dfa93490 Mon Sep 17 00:00:00 2001
From: "M.A" <8120158+mkahvi@users.noreply.github.com>
Date: Sun, 20 Mar 2022 17:53:43 +0200
Subject: [PATCH 6/7] Remove synthetic option.
Foundry doesn't like .update() on synthetic actors
---
module/classes/DevModePerformance.mjs | 5 ++---
templates/settings.hbs | 4 ----
2 files changed, 2 insertions(+), 7 deletions(-)
diff --git a/module/classes/DevModePerformance.mjs b/module/classes/DevModePerformance.mjs
index fb6259a..62fcc29 100644
--- a/module/classes/DevModePerformance.mjs
+++ b/module/classes/DevModePerformance.mjs
@@ -17,18 +17,17 @@ export class DevModePerformance {
});
}
- static actorCRUDTest = async (type, iterations = 1000, synthetic) => {
+ static actorCRUDTest = async (type, iterations = 1000) => {
if (!game.system.template.Actor.types.includes(type)) return console.error(type, "is invalid actor type");
// Force some defaults
iterations ||= 1000;
- synthetic ??= true;
console.log(`Running CRUD test on "${type}" type with ${iterations} iterations`);
const debugConfig = { ...CONFIG.debug };
this.resetDebug();
const now = performance.now();
for (let x = 0; x <= iterations; x++) {
- const created = await Actor.create({ name: `${x}`, type }, { temporary: synthetic });
+ const created = await Actor.create({ name: `${x}`, type });
await created.update({ name: 'Actor' + x });
await created.delete();
if (x % 10 == 0) SceneNavigation.displayProgressBar({ label: 'Test Progress', pct: (x / iterations) * 100 });
diff --git a/templates/settings.hbs b/templates/settings.hbs
index 57d83b2..f76ac85 100644
--- a/templates/settings.hbs
+++ b/templates/settings.hbs
@@ -100,10 +100,6 @@
-
-
-
-
{{localize 'DEV.configMenu.performance.actorCRUD.hint'}}
From 2e72acae7f9ef6a0e766dfb5e15da14521a6ce51 Mon Sep 17 00:00:00 2001
From: "M.A" <8120158+mkahvi@users.noreply.github.com>
Date: Mon, 21 Mar 2022 02:03:13 +0200
Subject: [PATCH 7/7] Apply suggested changes
---
lang/en.json | 1 -
module/classes/DevModePerformance.mjs | 4 +---
2 files changed, 1 insertion(+), 4 deletions(-)
diff --git a/lang/en.json b/lang/en.json
index dbcfbe3..c86bfbf 100644
--- a/lang/en.json
+++ b/lang/en.json
@@ -1,7 +1,6 @@
{
"DEV": {
"iterations": "Iterations",
- "synthetic": "Synthetic",
"clipboard": {
"copy": "Copy to Clipboard",
"success": "Copied to Clipboard",
diff --git a/module/classes/DevModePerformance.mjs b/module/classes/DevModePerformance.mjs
index 62fcc29..dd8846f 100644
--- a/module/classes/DevModePerformance.mjs
+++ b/module/classes/DevModePerformance.mjs
@@ -17,10 +17,8 @@ export class DevModePerformance {
});
}
- static actorCRUDTest = async (type, iterations = 1000) => {
+ static actorCRUDTest = async ({ type, iterations = 1000 } = {}) => {
if (!game.system.template.Actor.types.includes(type)) return console.error(type, "is invalid actor type");
- // Force some defaults
- iterations ||= 1000;
console.log(`Running CRUD test on "${type}" type with ${iterations} iterations`);
const debugConfig = { ...CONFIG.debug };
this.resetDebug();