Skip to content

Commit

Permalink
fix: CommonDao.patch _deepJsonEquals comparison was not correct
Browse files Browse the repository at this point in the history
Before:
it did Object.assign(loaded, patch)
and then compared _deepJsonEquals(loaded, bm)

After:
loadedWithPatch = {...loaded, ...patch}
_objectAssignExact(bm, loadedWithPatch)
_deepJsonEquals(loaded, loadedWithPatch)
  • Loading branch information
kirillgroshkov committed Mar 28, 2024
1 parent a02efba commit 72c2e9a
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 84 deletions.
23 changes: 15 additions & 8 deletions src/commondao/common.dao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,25 +669,32 @@ export class CommonDao<BM extends BaseDBEntity, DBM extends BaseDBEntity = BM> {
}

if (opt.skipDBRead) {
const bmBefore = _deepCopy(bm)
Object.assign(bm, patch)
if (_deepJsonEquals(bm, bmBefore)) {
const patched: BM = {
...bm,
...patch,
}

if (_deepJsonEquals(bm, patched)) {
// Skipping the save operation, as data is the same
return bm
}
Object.assign(bm, patch)
} else {
const loaded = await this.getById(bm.id, opt)

if (loaded) {
Object.assign(loaded, patch)
const loadedWithPatch: BM = {
...loaded,
...patch,
}

// Make `bm` exactly the same as `loadedWithPatch`
_objectAssignExact(bm, loadedWithPatch)

if (_deepJsonEquals(loaded, bm)) {
if (_deepJsonEquals(loaded, loadedWithPatch)) {
// Skipping the save operation, as data is the same
return bm
}

// Make `bm` exactly the same as `loaded`
_objectAssignExact(bm, loaded)
} else {
Object.assign(bm, patch)
}
Expand Down
153 changes: 77 additions & 76 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -821,9 +821,9 @@
typescript "^5.0.2"

"@naturalcycles/dev-lib@^13.0.0":
version "13.49.0"
resolved "https://registry.yarnpkg.com/@naturalcycles/dev-lib/-/dev-lib-13.49.0.tgz#8800f1176f2b2f1821a0c657051b14d4c5e53d06"
integrity sha512-aOrsaapT++PJKjZ7J7x8I5DIngGVXeHA0/0l5oT6tfvO4T6SLjf0qgEz0L8g46U4gfIIXJ+Fmoiiv8ta/MP6ug==
version "13.49.2"
resolved "https://registry.yarnpkg.com/@naturalcycles/dev-lib/-/dev-lib-13.49.2.tgz#bf4dabe21002ea71de0ab09dfa3be4a854964340"
integrity sha512-ZCxA5T9r1NV3bikI72b+IizpNPTug2QYV7blBOvrLGmLzrbmZPM2zypvaB0wCGRPEvsEV/jxpEvmbkCcEOdfQg==
dependencies:
"@commitlint/cli" "^19.0.0"
"@commitlint/config-conventional" "^19.0.0"
Expand All @@ -843,7 +843,7 @@
eslint-plugin-unicorn "^51.0.1"
eslint-plugin-unused-imports "^3.0.0"
eslint-plugin-vue "^9.0.0"
expect-type "^0.16.0"
expect-type "^0.19.0"
husky "^9.0.2"
jest-junit "^16.0.0"
lint-staged "^15.0.1"
Expand All @@ -856,9 +856,9 @@
yargs "^17.0.0"

"@naturalcycles/js-lib@^14.0.0", "@naturalcycles/js-lib@^14.116.0":
version "14.212.0"
resolved "https://registry.yarnpkg.com/@naturalcycles/js-lib/-/js-lib-14.212.0.tgz#4a61e3b045034fe3cbb1cbabf006aa0712c43ed4"
integrity sha512-Oel7hzcZ4nqPgbP9GBdGUsxZHecX/wa0FcBvPcpZ9YADt+p+h25mwsyA76nCU8YWbSjAtYNhjJPiOX09mhzTwA==
version "14.215.0"
resolved "https://registry.yarnpkg.com/@naturalcycles/js-lib/-/js-lib-14.215.0.tgz#7618086c6659420e2392c2b372daeed207d80eac"
integrity sha512-DsQcXVQniSG/IUxjmN6bBaDEiysPBdsHmWY+L4TR/v2uUtPlpeh1C+NJ6ZcWBn9zzs5pL5TofCqQ/FxL++opSg==
dependencies:
tslib "^2.0.0"
zod "^3.20.2"
Expand Down Expand Up @@ -946,9 +946,9 @@
"@sinonjs/commons" "^3.0.0"

"@tsconfig/node10@^1.0.7":
version "1.0.10"
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.10.tgz#b7ebd3adfa7750628d100594f6726b054d2c33b2"
integrity sha512-PiaIWIoPvO6qm6t114ropMCagj6YAF24j9OkCA2mJDXFnlionEwhsBCJ8yek4aib575BI3OkART/90WsgHgLWw==
version "1.0.11"
resolved "https://registry.yarnpkg.com/@tsconfig/node10/-/node10-1.0.11.tgz#6ee46400685f130e278128c7b38b7e031ff5b2f2"
integrity sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==

"@tsconfig/node12@^1.0.7":
version "1.0.11"
Expand Down Expand Up @@ -1118,15 +1118,15 @@
"@types/yargs-parser" "*"

"@typescript-eslint/eslint-plugin@^7.0.1":
version "7.3.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.3.1.tgz#0d8f38a6c8a1802139e62184ee7a68ed024f30a1"
integrity sha512-STEDMVQGww5lhCuNXVSQfbfuNII5E08QWkvAw5Qwf+bj2WT+JkG1uc+5/vXA3AOYMDHVOSpL+9rcbEUiHIm2dw==
version "7.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.4.0.tgz#de61c3083842fc6ac889d2fc83c9a96b55ab8328"
integrity sha512-yHMQ/oFaM7HZdVrVm/M2WHaNPgyuJH4WelkSVEWSSsir34kxW2kDJCxlXRhhGWEsMN0WAW/vLpKfKVcm8k+MPw==
dependencies:
"@eslint-community/regexpp" "^4.5.1"
"@typescript-eslint/scope-manager" "7.3.1"
"@typescript-eslint/type-utils" "7.3.1"
"@typescript-eslint/utils" "7.3.1"
"@typescript-eslint/visitor-keys" "7.3.1"
"@typescript-eslint/scope-manager" "7.4.0"
"@typescript-eslint/type-utils" "7.4.0"
"@typescript-eslint/utils" "7.4.0"
"@typescript-eslint/visitor-keys" "7.4.0"
debug "^4.3.4"
graphemer "^1.4.0"
ignore "^5.2.4"
Expand All @@ -1135,14 +1135,14 @@
ts-api-utils "^1.0.1"

"@typescript-eslint/parser@^7.0.1":
version "7.3.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.3.1.tgz#c4ba7dc2744318a5e4506596cbc3a0086255c526"
integrity sha512-Rq49+pq7viTRCH48XAbTA+wdLRrB/3sRq4Lpk0oGDm0VmnjBrAOVXH/Laalmwsv2VpekiEfVFwJYVk6/e8uvQw==
dependencies:
"@typescript-eslint/scope-manager" "7.3.1"
"@typescript-eslint/types" "7.3.1"
"@typescript-eslint/typescript-estree" "7.3.1"
"@typescript-eslint/visitor-keys" "7.3.1"
version "7.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-7.4.0.tgz#540f4321de1e52b886c0fa68628af1459954c1f1"
integrity sha512-ZvKHxHLusweEUVwrGRXXUVzFgnWhigo4JurEj0dGF1tbcGh6buL+ejDdjxOQxv6ytcY1uhun1p2sm8iWStlgLQ==
dependencies:
"@typescript-eslint/scope-manager" "7.4.0"
"@typescript-eslint/types" "7.4.0"
"@typescript-eslint/typescript-estree" "7.4.0"
"@typescript-eslint/visitor-keys" "7.4.0"
debug "^4.3.4"

"@typescript-eslint/[email protected]":
Expand All @@ -1153,21 +1153,21 @@
"@typescript-eslint/types" "5.62.0"
"@typescript-eslint/visitor-keys" "5.62.0"

"@typescript-eslint/scope-manager@7.3.1":
version "7.3.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-7.3.1.tgz#73fd0cb4211a7be23e49e5b6efec8820caa6ec36"
integrity sha512-fVS6fPxldsKY2nFvyT7IP78UO1/I2huG+AYu5AMjCT9wtl6JFiDnsv4uad4jQ0GTFzcUV5HShVeN96/17bTBag==
"@typescript-eslint/scope-manager@7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-7.4.0.tgz#acfc69261f10ece7bf7ece1734f1713392c3655f"
integrity sha512-68VqENG5HK27ypafqLVs8qO+RkNc7TezCduYrx8YJpXq2QGZ30vmNZGJJJC48+MVn4G2dCV8m5ZTVnzRexTVtw==
dependencies:
"@typescript-eslint/types" "7.3.1"
"@typescript-eslint/visitor-keys" "7.3.1"
"@typescript-eslint/types" "7.4.0"
"@typescript-eslint/visitor-keys" "7.4.0"

"@typescript-eslint/type-utils@7.3.1":
version "7.3.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-7.3.1.tgz#cbf90d3d7e788466aa8a5c0ab3f46103f098aa0d"
integrity sha512-iFhaysxFsMDQlzJn+vr3OrxN8NmdQkHks4WaqD4QBnt5hsq234wcYdyQ9uquzJJIDAj5W4wQne3yEsYA6OmXGw==
"@typescript-eslint/type-utils@7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-7.4.0.tgz#cfcaab21bcca441c57da5d3a1153555e39028cbd"
integrity sha512-247ETeHgr9WTRMqHbbQdzwzhuyaJ8dPTuyuUEMANqzMRB1rj/9qFIuIXK7l0FX9i9FXbHeBQl/4uz6mYuCE7Aw==
dependencies:
"@typescript-eslint/typescript-estree" "7.3.1"
"@typescript-eslint/utils" "7.3.1"
"@typescript-eslint/typescript-estree" "7.4.0"
"@typescript-eslint/utils" "7.4.0"
debug "^4.3.4"
ts-api-utils "^1.0.1"

Expand All @@ -1176,10 +1176,10 @@
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.62.0.tgz#258607e60effa309f067608931c3df6fed41fd2f"
integrity sha512-87NVngcbVXUahrRTqIK27gD2t5Cu1yuCXxbLcFtCzZGlfyVWWh8mLHkoxzjsB6DDNnvdL+fW8MiwPEJyGJQDgQ==

"@typescript-eslint/types@7.3.1":
version "7.3.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.3.1.tgz#ae104de8efa4227a462c0874d856602c5994413c"
integrity sha512-2tUf3uWggBDl4S4183nivWQ2HqceOZh1U4hhu4p1tPiIJoRRXrab7Y+Y0p+dozYwZVvLPRI6r5wKe9kToF9FIw==
"@typescript-eslint/types@7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-7.4.0.tgz#ee9dafa75c99eaee49de6dcc9348b45d354419b6"
integrity sha512-mjQopsbffzJskos5B4HmbsadSJQWaRK0UxqQ7GuNA9Ga4bEKeiO6b2DnB6cM6bpc8lemaPseh0H9B/wyg+J7rw==

"@typescript-eslint/[email protected]":
version "5.62.0"
Expand All @@ -1194,31 +1194,31 @@
semver "^7.3.7"
tsutils "^3.21.0"

"@typescript-eslint/typescript-estree@7.3.1":
version "7.3.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.3.1.tgz#598848195fad34c7aa73f548bd00a4d4e5f5e2bb"
integrity sha512-tLpuqM46LVkduWP7JO7yVoWshpJuJzxDOPYIVWUUZbW+4dBpgGeUdl/fQkhuV0A8eGnphYw3pp8d2EnvPOfxmQ==
"@typescript-eslint/typescript-estree@7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-7.4.0.tgz#12dbcb4624d952f72c10a9f4431284fca24624f4"
integrity sha512-A99j5AYoME/UBQ1ucEbbMEmGkN7SE0BvZFreSnTd1luq7yulcHdyGamZKizU7canpGDWGJ+Q6ZA9SyQobipePg==
dependencies:
"@typescript-eslint/types" "7.3.1"
"@typescript-eslint/visitor-keys" "7.3.1"
"@typescript-eslint/types" "7.4.0"
"@typescript-eslint/visitor-keys" "7.4.0"
debug "^4.3.4"
globby "^11.1.0"
is-glob "^4.0.3"
minimatch "9.0.3"
semver "^7.5.4"
ts-api-utils "^1.0.1"

"@typescript-eslint/utils@7.3.1":
version "7.3.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-7.3.1.tgz#fc28fd508ccf89495012561b7c02a6fdad162460"
integrity sha512-jIERm/6bYQ9HkynYlNZvXpzmXWZGhMbrOvq3jJzOSOlKXsVjrrolzWBjDW6/TvT5Q3WqaN4EkmcfdQwi9tDjBQ==
"@typescript-eslint/utils@7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-7.4.0.tgz#d889a0630cab88bddedaf7c845c64a00576257bd"
integrity sha512-NQt9QLM4Tt8qrlBVY9lkMYzfYtNz8/6qwZg8pI3cMGlPnj6mOpRxxAm7BMJN9K0AiY+1BwJ5lVC650YJqYOuNg==
dependencies:
"@eslint-community/eslint-utils" "^4.4.0"
"@types/json-schema" "^7.0.12"
"@types/semver" "^7.5.0"
"@typescript-eslint/scope-manager" "7.3.1"
"@typescript-eslint/types" "7.3.1"
"@typescript-eslint/typescript-estree" "7.3.1"
"@typescript-eslint/scope-manager" "7.4.0"
"@typescript-eslint/types" "7.4.0"
"@typescript-eslint/typescript-estree" "7.4.0"
semver "^7.5.4"

"@typescript-eslint/utils@^5.10.0":
Expand All @@ -1243,12 +1243,12 @@
"@typescript-eslint/types" "5.62.0"
eslint-visitor-keys "^3.3.0"

"@typescript-eslint/visitor-keys@7.3.1":
version "7.3.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.3.1.tgz#6ddef14a3ce2a79690f01176f5305c34d7b93d8c"
integrity sha512-9RMXwQF8knsZvfv9tdi+4D/j7dMG28X/wMJ8Jj6eOHyHWwDW4ngQJcqEczSsqIKKjFiLFr40Mnr7a5ulDD3vmw==
"@typescript-eslint/visitor-keys@7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-7.4.0.tgz#0c8ff2c1f8a6fe8d7d1a57ebbd4a638e86a60a94"
integrity sha512-0zkC7YM0iX5Y41homUUeW1CHtZR01K3ybjM1l6QczoMuay0XKtrb93kv95AxUGwdjGr64nNqnOCwmEl616N8CA==
dependencies:
"@typescript-eslint/types" "7.3.1"
"@typescript-eslint/types" "7.4.0"
eslint-visitor-keys "^3.4.1"

"@ungap/structured-clone@^1.2.0":
Expand Down Expand Up @@ -2172,9 +2172,9 @@ [email protected]:
integrity sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==

electron-to-chromium@^1.4.668:
version "1.4.715"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.715.tgz#bb16bcf2a3537962fccfa746b5c98c5f7404ff46"
integrity sha512-XzWNH4ZSa9BwVUQSDorPWAUQ5WGuYz7zJUNpNif40zFCiCl20t8zgylmreNmn26h5kiyw2lg7RfTmeMBsDklqg==
version "1.4.719"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.719.tgz#22a94ce7a5150511ba88e900836039e159efe22c"
integrity sha512-FbWy2Q2YgdFzkFUW/W5jBjE9dj+804+98E4Pup78JBPnbdb3pv6IneY2JCPKdeKLh3AOKHQeYf+KwLr7mxGh6Q==

emittery@^0.13.1:
version "0.13.1"
Expand Down Expand Up @@ -2381,9 +2381,9 @@ eslint-plugin-jest@^27.0.1:
"@typescript-eslint/utils" "^5.10.0"

eslint-plugin-jsdoc@^48.0.1:
version "48.2.1"
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-48.2.1.tgz#9334a05555a95fdc192980627142177963b668b4"
integrity sha512-iUvbcyDZSO/9xSuRv2HQBw++8VkV/pt3UWtX9cpPH0l7GKPq78QC/6+PmyQHHvNZaTjAce6QVciEbnc6J/zH5g==
version "48.2.2"
resolved "https://registry.yarnpkg.com/eslint-plugin-jsdoc/-/eslint-plugin-jsdoc-48.2.2.tgz#eefdc5e3bb3cea957b66dd4817e9de30930b5270"
integrity sha512-S0Gk+rpT5w/ephKCncUY7kUsix9uE4B9XI8D/fS1/26d8okE+vZsuG1IvIt4B6sJUdQqsnzi+YXfmh+HJG11CA==
dependencies:
"@es-joy/jsdoccomment" "~0.42.0"
are-docs-informative "^0.0.2"
Expand Down Expand Up @@ -2425,11 +2425,12 @@ eslint-plugin-unused-imports@^3.0.0:
eslint-rule-composer "^0.3.0"

eslint-plugin-vue@^9.0.0:
version "9.23.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-vue/-/eslint-plugin-vue-9.23.0.tgz#1354a33b0cd21e0cb373557ff73c5d7a6698fbcd"
integrity sha512-Bqd/b7hGYGrlV+wP/g77tjyFmp81lh5TMw0be9093X02SyelxRRfCI6/IsGq/J7Um0YwB9s0Ry0wlFyjPdmtUw==
version "9.24.0"
resolved "https://registry.yarnpkg.com/eslint-plugin-vue/-/eslint-plugin-vue-9.24.0.tgz#71209f4652ee767f18c0bf56f25991b7cdc5aa46"
integrity sha512-9SkJMvF8NGMT9aQCwFc5rj8Wo1XWSMSHk36i7ZwdI614BU7sIOR28ZjuFPKp8YGymZN12BSEbiSwa7qikp+PBw==
dependencies:
"@eslint-community/eslint-utils" "^4.4.0"
globals "^13.24.0"
natural-compare "^1.4.0"
nth-check "^2.1.1"
postcss-selector-parser "^6.0.15"
Expand Down Expand Up @@ -2595,10 +2596,10 @@ exit@^0.1.2:
resolved "https://registry.yarnpkg.com/exit/-/exit-0.1.2.tgz#0632638f8d877cc82107d30a0fff1a17cba1cd0c"
integrity sha512-Zk/eNKV2zbjpKzrsQ+n1G6poVbErQxJ0LBOJXaKZ1EViLzH+hrLu9cdXI4zw9dBQJslwBEpbQ2P1oS7nDxs6jQ==

expect-type@^0.16.0:
version "0.16.0"
resolved "https://registry.yarnpkg.com/expect-type/-/expect-type-0.16.0.tgz#8e2d5134dbbd7a3dc009e42c87fcc84fd5671a76"
integrity sha512-wCpFeVBiAPGiYkQZzaqvGuuBnNCHbtnowMOBpBGY8a27XbG8VAit3lklWph1r8VmgsH61mOZqI3NuGm8bZnUlw==
expect-type@^0.19.0:
version "0.19.0"
resolved "https://registry.yarnpkg.com/expect-type/-/expect-type-0.19.0.tgz#72eca0ea90f34fa793c70f44adc1974c0e031914"
integrity sha512-piv9wz3IrAG4Wnk2A+n2VRCHieAyOSxrRLU872Xo6nyn39kYXKDALk4OcqnvLRnFvkz659CnWC8MWZLuuQnoqg==

expect@^29.0.0, expect@^29.7.0:
version "29.7.0"
Expand All @@ -2612,9 +2613,9 @@ expect@^29.0.0, expect@^29.7.0:
jest-util "^29.7.0"

express@^4.17.1:
version "4.19.1"
resolved "https://registry.yarnpkg.com/express/-/express-4.19.1.tgz#4700635795e911600a45596138cf5b0320e78256"
integrity sha512-K4w1/Bp7y8iSiVObmCrtq8Cs79XjJc/RU2YYkZQ7wpUu5ZyZ7MtPHkqoMz4pf+mgXfNvo2qft8D9OnrH2ABk9w==
version "4.19.2"
resolved "https://registry.yarnpkg.com/express/-/express-4.19.2.tgz#e25437827a3aa7f2a827bc8171bbbb664a356465"
integrity sha512-5T6nhjsT+EOMzuck8JjBHARTHfMht0POzlA60WV2pMD3gyXw2LZnZ+ueGdNxG+0calOJcWKbpFcuzLZ91YWq9Q==
dependencies:
accepts "~1.3.8"
array-flatten "1.1.1"
Expand Down Expand Up @@ -2907,7 +2908,7 @@ globals@^11.1.0:
resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e"
integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==

globals@^13.19.0:
globals@^13.19.0, globals@^13.24.0:
version "13.24.0"
resolved "https://registry.yarnpkg.com/globals/-/globals-13.24.0.tgz#8432a19d78ce0c1e833949c36adb345400bb1171"
integrity sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==
Expand Down

0 comments on commit 72c2e9a

Please sign in to comment.