Better checking of processor equivalence

This commit is contained in:
Jake Archibald
2020-11-11 16:49:00 +00:00
parent 964390501e
commit eb9d0d186c
3 changed files with 42 additions and 10 deletions

23
package-lock.json generated
View File

@@ -167,9 +167,9 @@
} }
}, },
"@surma/rollup-plugin-off-main-thread": { "@surma/rollup-plugin-off-main-thread": {
"version": "1.4.1", "version": "1.4.2",
"resolved": "https://registry.npmjs.org/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-1.4.1.tgz", "resolved": "https://registry.npmjs.org/@surma/rollup-plugin-off-main-thread/-/rollup-plugin-off-main-thread-1.4.2.tgz",
"integrity": "sha512-ZPBWYQDdO4JZiTmTP3DABsHhIPA7bEJk9Znk7tZsrbPGanoGo8YxMv//WLx5Cvb+lRgS42+6yiOIYYHCKDmkpQ==", "integrity": "sha512-yBMPqmd1yEJo/280PAMkychuaALyQ9Lkb5q1ck3mjJrFuEobIfhnQ4J3mbvBoISmR3SWMWV+cGB/I0lCQee79A==",
"dev": true, "dev": true,
"requires": { "requires": {
"ejs": "^2.6.1", "ejs": "^2.6.1",
@@ -1671,6 +1671,12 @@
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=",
"dev": true "dev": true
}, },
"esm": {
"version": "3.2.25",
"resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz",
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA==",
"dev": true
},
"esprima": { "esprima": {
"version": "4.0.1", "version": "4.0.1",
"resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz",
@@ -2313,10 +2319,13 @@
"dev": true "dev": true
}, },
"linkstate": { "linkstate": {
"version": "1.1.1", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/linkstate/-/linkstate-1.1.1.tgz", "resolved": "https://registry.npmjs.org/linkstate/-/linkstate-2.0.0.tgz",
"integrity": "sha512-5SICdxQG9FpWk44wSEoM2WOCUNuYfClp10t51XAIV5E7vUILF/dTYxf0vJw6bW2dUd2wcQon+LkNtRijpNLrig==", "integrity": "sha512-ti9WqRjpLqUd8wv4vUDjeqMeAObSieeEJA7QHpUKTDr75gkuWTsgm4+Tngg/3uTogSz68hJ/c+676rLfSgqHUg==",
"dev": true "dev": true,
"requires": {
"esm": "^3.2.25"
}
}, },
"lint-staged": { "lint-staged": {
"version": "10.5.1", "version": "10.5.1",

View File

@@ -13,7 +13,7 @@
"@rollup/plugin-commonjs": "^15.1.0", "@rollup/plugin-commonjs": "^15.1.0",
"@rollup/plugin-node-resolve": "^9.0.0", "@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.4", "@rollup/plugin-replace": "^2.3.4",
"@surma/rollup-plugin-off-main-thread": "^1.4.1", "@surma/rollup-plugin-off-main-thread": "^1.4.2",
"@types/node": "^14.14.7", "@types/node": "^14.14.7",
"comlink": "^4.3.0", "comlink": "^4.3.0",
"cssnano": "^4.1.10", "cssnano": "^4.1.10",
@@ -21,7 +21,7 @@
"file-drop-element": "^1.0.1", "file-drop-element": "^1.0.1",
"husky": "^4.3.0", "husky": "^4.3.0",
"idb-keyval": "^3.2.0", "idb-keyval": "^3.2.0",
"linkstate": "^1.1.1", "linkstate": "^2.0.0",
"lint-staged": "^10.5.1", "lint-staged": "^10.5.1",
"lodash.camelcase": "^4.3.0", "lodash.camelcase": "^4.3.0",
"mime-types": "^2.1.27", "mime-types": "^2.1.27",

View File

@@ -230,6 +230,24 @@ async function processSvg(
); );
} }
/**
* If two processors are disabled, they're considered equivalent, otherwise
* equivalence is based on ===
*/
function processorStateEquivalent(a: ProcessorState, b: ProcessorState) {
// Quick exit
if (a === b) return true;
// All processors have the same keys
for (const key of Object.keys(a) as Array<keyof ProcessorState>) {
// If both processors are disabled, they're the same.
if (!a[key].enabled && !b[key].enabled) continue;
if (a !== b) return false;
}
return true;
}
// These are only used in the mobile view // These are only used in the mobile view
const resultTitles = ['Top', 'Bottom'] as const; const resultTitles = ['Top', 'Bottom'] as const;
// These are only used in the desktop view // These are only used in the desktop view
@@ -476,7 +494,11 @@ export default class Compress extends Component<Props, State> {
const sideWorksNeeded = latestSideJobStates.map((latestSideJob, i) => { const sideWorksNeeded = latestSideJobStates.map((latestSideJob, i) => {
const needsProcessing = const needsProcessing =
needsPreprocessing || needsPreprocessing ||
latestSideJob.processorState !== sideJobStates[i].processorState; !latestSideJob.processorState ||
!processorStateEquivalent(
latestSideJob.processorState,
sideJobStates[i].processorState,
);
return { return {
processing: needsProcessing, processing: needsProcessing,
@@ -505,6 +527,7 @@ export default class Compress extends Component<Props, State> {
} }
if (!jobNeeded) return; if (!jobNeeded) return;
console.log('Processing');
const mainSignal = this.mainAbortController.signal; const mainSignal = this.mainAbortController.signal;
const sideSignals = this.sideAbortControllers.map((ac) => ac.signal); const sideSignals = this.sideAbortControllers.map((ac) => ac.signal);