Improve webpack - Reduced filesize by 18% by converting from node-object-hash to object-hash (#2768) rizwanmustafa

* Refreshed the PR

* not sending stringified result anymore

* removed length check

Co-authored-by: Miodec <bartnikjack@gmail.com>
This commit is contained in:
Rizwan Mustafa 2022-03-25 19:36:04 +05:00 committed by GitHub
parent ed1d248ab6
commit 47c7fd42c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 58 additions and 67 deletions

View file

@ -3,7 +3,7 @@ import UserDAO from "../../dao/user";
import PublicStatsDAO from "../../dao/public-stats";
import BotDAO from "../../dao/bot";
import { roundTo2, stdDev } from "../../utils/misc";
import node_object_hash from "node-object-hash";
import objectHash from "object-hash";
import Logger from "../../utils/logger";
import "dotenv/config";
import { MonkeyResponse } from "../../utils/monkey-response";
@ -18,8 +18,6 @@ import MonkeyStatusCodes from "../../constants/monkey-status-codes";
import { incrementResult } from "../../utils/prometheus";
import George from "../../tasks/george";
const objecthash = node_object_hash().hash;
try {
if (anticheatImplemented() === false) throw new Error("undefined");
console.log("Anticheat module loaded");
@ -80,12 +78,9 @@ class ResultController {
const resulthash = result.hash;
delete result.hash;
delete result.stringified;
if (
req.ctx.configuration.resultObjectHashCheck.enabled &&
resulthash.length === 64
) {
if (req.ctx.configuration.resultObjectHashCheck.enabled) {
//if its not 64 that means client is still using old hashing package
const serverhash = objecthash(result);
const serverhash = objectHash(result);
if (serverhash !== resulthash) {
Logger.log(
"incorrect_result_hash",

View file

@ -23,8 +23,8 @@
"lodash": "4.17.21",
"mongodb": "4.4.0",
"node-fetch": "2.6.7",
"node-object-hash": "2.3.10",
"nodemon": "2.0.7",
"object-hash": "^3.0.0",
"path": "0.12.7",
"prom-client": "14.0.1",
"simple-git": "2.45.1",
@ -3574,14 +3574,6 @@
"node-gyp-build-test": "build-test.js"
}
},
"node_modules/node-object-hash": {
"version": "2.3.10",
"resolved": "https://registry.npmjs.org/node-object-hash/-/node-object-hash-2.3.10.tgz",
"integrity": "sha512-jY5dPJzw6NHd/KPSfPKJ+IHoFS81/tJ43r34ZeNMXGzCOM8jwQDCD12HYayKIB6MuznrnqIYy2e891NA2g0ibA==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/nodemon": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.7.tgz",
@ -3683,7 +3675,6 @@
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
"optional": true,
"engines": {
"node": ">= 6"
}
@ -8005,11 +7996,6 @@
"integrity": "sha512-iWjXZvmboq0ja1pUGULQBexmxq8CV4xBhX7VDOTbL7ZR4FOowwY/VOtRxBN/yKxmdGoIp4j5ysNT4u3S2pDQ3Q==",
"optional": true
},
"node-object-hash": {
"version": "2.3.10",
"resolved": "https://registry.npmjs.org/node-object-hash/-/node-object-hash-2.3.10.tgz",
"integrity": "sha512-jY5dPJzw6NHd/KPSfPKJ+IHoFS81/tJ43r34ZeNMXGzCOM8jwQDCD12HYayKIB6MuznrnqIYy2e891NA2g0ibA=="
},
"nodemon": {
"version": "2.0.7",
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.7.tgz",
@ -8082,8 +8068,7 @@
"object-hash": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
"optional": true
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw=="
},
"object-inspect": {
"version": "1.12.0",

View file

@ -29,8 +29,8 @@
"lodash": "4.17.21",
"mongodb": "4.4.0",
"node-fetch": "2.6.7",
"node-object-hash": "2.3.10",
"nodemon": "2.0.7",
"object-hash": "^3.0.0",
"path": "0.12.7",
"prom-client": "14.0.1",
"simple-git": "2.45.1",

View file

@ -20,7 +20,7 @@
"firebase": "9.6.0",
"howler": "^2.2.1",
"html2canvas": "1.4.1",
"node-object-hash": "2.3.10",
"object-hash": "^3.0.0",
"stemmer": "2.0.0"
},
"devDependencies": {
@ -8601,14 +8601,6 @@
"node": ">= 6.13.0"
}
},
"node_modules/node-object-hash": {
"version": "2.3.10",
"resolved": "https://registry.npmjs.org/node-object-hash/-/node-object-hash-2.3.10.tgz",
"integrity": "sha512-jY5dPJzw6NHd/KPSfPKJ+IHoFS81/tJ43r34ZeNMXGzCOM8jwQDCD12HYayKIB6MuznrnqIYy2e891NA2g0ibA==",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/node-releases": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.2.tgz",
@ -8799,6 +8791,14 @@
"node": ">=0.10.0"
}
},
"node_modules/object-hash": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
"engines": {
"node": ">= 6"
}
},
"node_modules/object-is": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.5.tgz",
@ -20387,11 +20387,6 @@
"integrity": "sha512-08ARB91bUi6zNKzVmaj3QO7cr397uiDT2nJ63cHjyNtCTWIgvS47j3eT0WfzUwS9+6Z5YshRaoasFkXCKrIYbA==",
"dev": true
},
"node-object-hash": {
"version": "2.3.10",
"resolved": "https://registry.npmjs.org/node-object-hash/-/node-object-hash-2.3.10.tgz",
"integrity": "sha512-jY5dPJzw6NHd/KPSfPKJ+IHoFS81/tJ43r34ZeNMXGzCOM8jwQDCD12HYayKIB6MuznrnqIYy2e891NA2g0ibA=="
},
"node-releases": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.2.tgz",
@ -20540,6 +20535,11 @@
}
}
},
"object-hash": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw=="
},
"object-is": {
"version": "1.1.5",
"resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.5.tgz",

View file

@ -60,7 +60,7 @@
"firebase": "9.6.0",
"howler": "^2.2.1",
"html2canvas": "1.4.1",
"node-object-hash": "2.3.10",
"object-hash": "^3.0.0",
"stemmer": "2.0.0"
}
}

View file

@ -49,12 +49,10 @@ import * as ConfigEvent from "../observables/config-event";
import * as TimerEvent from "../observables/timer-event";
import * as Last10Average from "../elements/last-10-average";
import * as Monkey from "./monkey";
import NodeObjectHash from "node-object-hash";
import objectHash from "object-hash";
import * as AnalyticsController from "../controllers/analytics-controller";
import { Auth } from "../firebase";
const objecthash = NodeObjectHash().hash;
let failReason = "";
export let notSignedInLastResult: MonkeyTypes.Result<MonkeyTypes.Mode> | null =
@ -68,7 +66,7 @@ export function setNotSignedInUid(uid: string): void {
if (notSignedInLastResult === null) return;
notSignedInLastResult.uid = uid;
delete notSignedInLastResult.hash;
notSignedInLastResult.hash = objecthash(notSignedInLastResult);
notSignedInLastResult.hash = objectHash(notSignedInLastResult);
}
let spanishSentenceTracker = "";
@ -1488,15 +1486,7 @@ export async function finish(difficultyFailed = false): Promise<void> {
completedEvent.challenge = ChallengeContoller.verify(completedEvent);
if (completedEvent.challenge === null) delete completedEvent?.challenge;
completedEvent.hash = objecthash(completedEvent);
if (
(completedEvent.mode === "words" && completedEvent.mode2 == 10) ||
completedEvent.mode === "custom"
) {
//@ts-ignore
completedEvent.stringified = JSON.stringify(completedEvent);
}
completedEvent.hash = objectHash(completedEvent);
const response = await Ape.results.save(completedEvent);

View file

@ -10,7 +10,8 @@
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"types": [
"jquery",
"select2"
"select2",
"node"
] /* Specify type package names to be included without being referenced in a source file. */,
"allowUmdGlobalAccess": true /* Allow accessing UMD globals from modules. */,
"resolveJsonModule": true /* Enable importing .json files */,

View file

@ -11,18 +11,7 @@ const BASE_CONFIG = {
entry: {
monkeytype: resolve(__dirname, "../src/scripts/index.ts"),
},
resolve: {
fallback: {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
buffer: require.resolve("buffer"),
"bn.js": require.resolve("bn.js"),
},
alias: {
"bn.js": resolve(__dirname, "node_modules/bn.js/lib/bn.js"),
},
extensions: [".ts", ".js"],
},
resolve: { extensions: [".ts", ".js"] },
output: {
filename: "./js/[name].[chunkhash:8].js",
path: resolve(__dirname, "../public/"),

27
package-lock.json generated
View file

@ -8,6 +8,10 @@
"name": "monkeytype",
"version": "1.5.6",
"license": "GPL-3.0",
"dependencies": {
"@types/object-hash": "^2.2.1",
"object-hash": "^3.0.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.11.0",
"@typescript-eslint/parser": "^5.11.0",
@ -218,6 +222,11 @@
"integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==",
"dev": true
},
"node_modules/@types/object-hash": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@types/object-hash/-/object-hash-2.2.1.tgz",
"integrity": "sha512-i/rtaJFCsPljrZvP/akBqEwUP2y5cZLOmvO+JaYnz01aPknrQ+hB5MRcO7iqCUsFaYfTG8kGfKUyboA07xeDHQ=="
},
"node_modules/@types/parse-json": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz",
@ -1878,6 +1887,14 @@
"node": ">=8"
}
},
"node_modules/object-hash": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw==",
"engines": {
"node": ">= 6"
}
},
"node_modules/once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
@ -3054,6 +3071,11 @@
"integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==",
"dev": true
},
"@types/object-hash": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/@types/object-hash/-/object-hash-2.2.1.tgz",
"integrity": "sha512-i/rtaJFCsPljrZvP/akBqEwUP2y5cZLOmvO+JaYnz01aPknrQ+hB5MRcO7iqCUsFaYfTG8kGfKUyboA07xeDHQ=="
},
"@types/parse-json": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz",
@ -4298,6 +4320,11 @@
"path-key": "^3.0.0"
}
},
"object-hash": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/object-hash/-/object-hash-3.0.0.tgz",
"integrity": "sha512-RSn9F68PjH9HqtltsSnqYC1XXoWe9Bju5+213R98cNGttag9q9yAOTzdbsqvIa7aNm5WffBZFpWYr2aWrklWAw=="
},
"once": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",

View file

@ -41,5 +41,9 @@
"hooks": {
"pre-commit": "pretty-quick --staged && npm run lint"
}
},
"dependencies": {
"@types/object-hash": "^2.2.1",
"object-hash": "^3.0.0"
}
}