Merge branch 'master' into master

This commit is contained in:
SashaXser 2024-01-20 07:07:03 +04:00 committed by GitHub
commit a8010b553d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 376 additions and 22 deletions

347
package-lock.json generated
View file

@ -17,6 +17,7 @@
"express-rate-limit": "^6.7.0",
"form-data": "^4.0.0",
"lodash": "^4.17.21",
"lz4-napi": "^2.2.0",
"pg": "^8.8.0",
"rate-limit-redis": "^3.0.1",
"redis": "^4.5.0",
@ -62,6 +63,201 @@
"node": ">=6.0.0"
}
},
"node_modules/@antoniomuso/lz4-napi-android-arm-eabi": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-android-arm-eabi/-/lz4-napi-android-arm-eabi-2.2.0.tgz",
"integrity": "sha512-9PBt0UhmahcQamcD+eHVB2u38Ae1z7Sqb2zBLExj9DRGT9tRj3RavdgAjRewsShp+k+J2hxfinXp8gLil3rZwg==",
"cpu": [
"arm"
],
"optional": true,
"os": [
"android"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-android-arm64": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-android-arm64/-/lz4-napi-android-arm64-2.2.0.tgz",
"integrity": "sha512-zW0EPEuSBxjjP9MZUyXmDYAXLpS/TeVEq/la+nJIvM5XtGg1rwvuNdEErO977QI0zRc1jIQBMzE25B/wwP/Bwg==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"android"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-darwin-arm64": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-darwin-arm64/-/lz4-napi-darwin-arm64-2.2.0.tgz",
"integrity": "sha512-KVE5F+fOmVIXADkgSTgA+J3Hv7l2QEaj4iBbLQfuDSZjm5qMDrXUfBJBJv6xKYpu9/ikMZRKvjfU/krhVMqWXw==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-darwin-x64": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-darwin-x64/-/lz4-napi-darwin-x64-2.2.0.tgz",
"integrity": "sha512-K2jRtXU+9qldL6vK7K4VT3UClZZb87nLqMlwkMVS2eaoofqFdrkSAgJP5oSHN9bkE7u3OCLgOUZfFFSi/UNz7w==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"darwin"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-freebsd-x64": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-freebsd-x64/-/lz4-napi-freebsd-x64-2.2.0.tgz",
"integrity": "sha512-KKXiaQ8g0UxwDsfCBH/ARo5FCnoFtoPLDAxz72QLWuuTxfK0epg3ZChb2l1n95bUvSZKRSVQaa7sHJsl+d+ffg==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"freebsd"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-linux-arm-gnueabihf": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-linux-arm-gnueabihf/-/lz4-napi-linux-arm-gnueabihf-2.2.0.tgz",
"integrity": "sha512-p0WkyFmWSaveGPNolSxH23/NksbhORj7D1dxyHdtZKdY1xMUVxQ/aIrD/Vfn35hO01KFI1LVh6nTpybez7Empg==",
"cpu": [
"arm"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-linux-arm64-gnu": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-linux-arm64-gnu/-/lz4-napi-linux-arm64-gnu-2.2.0.tgz",
"integrity": "sha512-a1C4u+dnS8wP+Lu6fUKGOeVm0tFw8gt0VK+3aCCB9AYu8u2NdfYqqpceu9snNk04Rzp3MNJSryWvHtoVOdUtMQ==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-linux-arm64-musl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-linux-arm64-musl/-/lz4-napi-linux-arm64-musl-2.2.0.tgz",
"integrity": "sha512-+YlKffM2n5/zLJ3JYpzbnwTLj/aiOAM9rEJlDg7LR0YK5o0dbcsCq8fK/fapDkzoLl8BMO6ObJtuZ/6Vi3Targ==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-linux-x64-gnu": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-linux-x64-gnu/-/lz4-napi-linux-x64-gnu-2.2.0.tgz",
"integrity": "sha512-pPJVppGpV+La0tb34GMTbiUTLsSqIJGzxIdPM2XjJ23u6ytnog2DQiyylMENhY20X7oHG2oQlCW9J+W8sCNh3Q==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-linux-x64-musl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-linux-x64-musl/-/lz4-napi-linux-x64-musl-2.2.0.tgz",
"integrity": "sha512-KSWJ5TZVLlOA+hzy7gnYytb7xhD6jeoYqno72Zp/jY1fV5xHk71YJppvzOzVpX4mbRFdu5DMQU8GcvTxsmS2zg==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"linux"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-win32-arm64-msvc": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-win32-arm64-msvc/-/lz4-napi-win32-arm64-msvc-2.2.0.tgz",
"integrity": "sha512-bfk4rNPE5Al1aozsRm4oWfMjxS2qDaoYilFzSDWxToFg7DFlAkjBsVLnB9cV+W6oZ/+jowlK8IGFlNhUG+uatw==",
"cpu": [
"arm64"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-win32-ia32-msvc": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-win32-ia32-msvc/-/lz4-napi-win32-ia32-msvc-2.2.0.tgz",
"integrity": "sha512-xu7XMe1KyLDP2wzOxTE9eibFGP+Ut1Sl3GbW1zW3wjV4RIXyJqZRvwIOsZ0P0lfXJmykmzN6yIzs1QksOzgMog==",
"cpu": [
"ia32"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@antoniomuso/lz4-napi-win32-x64-msvc": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-win32-x64-msvc/-/lz4-napi-win32-x64-msvc-2.2.0.tgz",
"integrity": "sha512-sJZjXEIjtK7upjh1oHpDELAH45jL/dNdg/mzYg61ljprtfjsza40h8e/Sq0IQOCmJc6IR746bGcttPM297nhzQ==",
"cpu": [
"x64"
],
"optional": true,
"os": [
"win32"
],
"engines": {
"node": ">= 10"
}
},
"node_modules/@babel/code-frame": {
"version": "7.22.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz",
@ -792,6 +988,19 @@
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"node_modules/@napi-rs/triples": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@napi-rs/triples/-/triples-1.2.0.tgz",
"integrity": "sha512-HAPjR3bnCsdXBsATpDIP5WCrw0JcACwhhrwIAQhiR46n+jm+a2F8kBsfseAuWtSyQ+H3Yebt2k43B5dy+04yMA=="
},
"node_modules/@node-rs/helper": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/@node-rs/helper/-/helper-1.5.0.tgz",
"integrity": "sha512-4E1laLlg532nkrvUohZzl/wFos3bsHExSDw/guaoLekMcTKtD3ZsH6Vc4/qIRzOzAhQv5LLRnTE+vOeJ6C9Z8w==",
"dependencies": {
"@napi-rs/triples": "^1.2.0"
}
},
"node_modules/@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@ -3514,6 +3723,32 @@
"node": "*"
}
},
"node_modules/lz4-napi": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/lz4-napi/-/lz4-napi-2.2.0.tgz",
"integrity": "sha512-n2xx3j7rILyd7OXxQoFXmyEpEJywfAXSnK6br2woep7j/7RV86gc7xLTITaM5/KZnQJb5exSvpcz+lTZ8npXgg==",
"dependencies": {
"@node-rs/helper": "^1.3.3"
},
"engines": {
"node": ">= 10"
},
"optionalDependencies": {
"@antoniomuso/lz4-napi-android-arm-eabi": "2.2.0",
"@antoniomuso/lz4-napi-android-arm64": "2.2.0",
"@antoniomuso/lz4-napi-darwin-arm64": "2.2.0",
"@antoniomuso/lz4-napi-darwin-x64": "2.2.0",
"@antoniomuso/lz4-napi-freebsd-x64": "2.2.0",
"@antoniomuso/lz4-napi-linux-arm-gnueabihf": "2.2.0",
"@antoniomuso/lz4-napi-linux-arm64-gnu": "2.2.0",
"@antoniomuso/lz4-napi-linux-arm64-musl": "2.2.0",
"@antoniomuso/lz4-napi-linux-x64-gnu": "2.2.0",
"@antoniomuso/lz4-napi-linux-x64-musl": "2.2.0",
"@antoniomuso/lz4-napi-win32-arm64-msvc": "2.2.0",
"@antoniomuso/lz4-napi-win32-ia32-msvc": "2.2.0",
"@antoniomuso/lz4-napi-win32-x64-msvc": "2.2.0"
}
},
"node_modules/make-dir": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",
@ -5729,6 +5964,84 @@
"@jridgewell/trace-mapping": "^0.3.9"
}
},
"@antoniomuso/lz4-napi-android-arm-eabi": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-android-arm-eabi/-/lz4-napi-android-arm-eabi-2.2.0.tgz",
"integrity": "sha512-9PBt0UhmahcQamcD+eHVB2u38Ae1z7Sqb2zBLExj9DRGT9tRj3RavdgAjRewsShp+k+J2hxfinXp8gLil3rZwg==",
"optional": true
},
"@antoniomuso/lz4-napi-android-arm64": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-android-arm64/-/lz4-napi-android-arm64-2.2.0.tgz",
"integrity": "sha512-zW0EPEuSBxjjP9MZUyXmDYAXLpS/TeVEq/la+nJIvM5XtGg1rwvuNdEErO977QI0zRc1jIQBMzE25B/wwP/Bwg==",
"optional": true
},
"@antoniomuso/lz4-napi-darwin-arm64": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-darwin-arm64/-/lz4-napi-darwin-arm64-2.2.0.tgz",
"integrity": "sha512-KVE5F+fOmVIXADkgSTgA+J3Hv7l2QEaj4iBbLQfuDSZjm5qMDrXUfBJBJv6xKYpu9/ikMZRKvjfU/krhVMqWXw==",
"optional": true
},
"@antoniomuso/lz4-napi-darwin-x64": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-darwin-x64/-/lz4-napi-darwin-x64-2.2.0.tgz",
"integrity": "sha512-K2jRtXU+9qldL6vK7K4VT3UClZZb87nLqMlwkMVS2eaoofqFdrkSAgJP5oSHN9bkE7u3OCLgOUZfFFSi/UNz7w==",
"optional": true
},
"@antoniomuso/lz4-napi-freebsd-x64": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-freebsd-x64/-/lz4-napi-freebsd-x64-2.2.0.tgz",
"integrity": "sha512-KKXiaQ8g0UxwDsfCBH/ARo5FCnoFtoPLDAxz72QLWuuTxfK0epg3ZChb2l1n95bUvSZKRSVQaa7sHJsl+d+ffg==",
"optional": true
},
"@antoniomuso/lz4-napi-linux-arm-gnueabihf": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-linux-arm-gnueabihf/-/lz4-napi-linux-arm-gnueabihf-2.2.0.tgz",
"integrity": "sha512-p0WkyFmWSaveGPNolSxH23/NksbhORj7D1dxyHdtZKdY1xMUVxQ/aIrD/Vfn35hO01KFI1LVh6nTpybez7Empg==",
"optional": true
},
"@antoniomuso/lz4-napi-linux-arm64-gnu": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-linux-arm64-gnu/-/lz4-napi-linux-arm64-gnu-2.2.0.tgz",
"integrity": "sha512-a1C4u+dnS8wP+Lu6fUKGOeVm0tFw8gt0VK+3aCCB9AYu8u2NdfYqqpceu9snNk04Rzp3MNJSryWvHtoVOdUtMQ==",
"optional": true
},
"@antoniomuso/lz4-napi-linux-arm64-musl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-linux-arm64-musl/-/lz4-napi-linux-arm64-musl-2.2.0.tgz",
"integrity": "sha512-+YlKffM2n5/zLJ3JYpzbnwTLj/aiOAM9rEJlDg7LR0YK5o0dbcsCq8fK/fapDkzoLl8BMO6ObJtuZ/6Vi3Targ==",
"optional": true
},
"@antoniomuso/lz4-napi-linux-x64-gnu": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-linux-x64-gnu/-/lz4-napi-linux-x64-gnu-2.2.0.tgz",
"integrity": "sha512-pPJVppGpV+La0tb34GMTbiUTLsSqIJGzxIdPM2XjJ23u6ytnog2DQiyylMENhY20X7oHG2oQlCW9J+W8sCNh3Q==",
"optional": true
},
"@antoniomuso/lz4-napi-linux-x64-musl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-linux-x64-musl/-/lz4-napi-linux-x64-musl-2.2.0.tgz",
"integrity": "sha512-KSWJ5TZVLlOA+hzy7gnYytb7xhD6jeoYqno72Zp/jY1fV5xHk71YJppvzOzVpX4mbRFdu5DMQU8GcvTxsmS2zg==",
"optional": true
},
"@antoniomuso/lz4-napi-win32-arm64-msvc": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-win32-arm64-msvc/-/lz4-napi-win32-arm64-msvc-2.2.0.tgz",
"integrity": "sha512-bfk4rNPE5Al1aozsRm4oWfMjxS2qDaoYilFzSDWxToFg7DFlAkjBsVLnB9cV+W6oZ/+jowlK8IGFlNhUG+uatw==",
"optional": true
},
"@antoniomuso/lz4-napi-win32-ia32-msvc": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-win32-ia32-msvc/-/lz4-napi-win32-ia32-msvc-2.2.0.tgz",
"integrity": "sha512-xu7XMe1KyLDP2wzOxTE9eibFGP+Ut1Sl3GbW1zW3wjV4RIXyJqZRvwIOsZ0P0lfXJmykmzN6yIzs1QksOzgMog==",
"optional": true
},
"@antoniomuso/lz4-napi-win32-x64-msvc": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/@antoniomuso/lz4-napi-win32-x64-msvc/-/lz4-napi-win32-x64-msvc-2.2.0.tgz",
"integrity": "sha512-sJZjXEIjtK7upjh1oHpDELAH45jL/dNdg/mzYg61ljprtfjsza40h8e/Sq0IQOCmJc6IR746bGcttPM297nhzQ==",
"optional": true
},
"@babel/code-frame": {
"version": "7.22.13",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.13.tgz",
@ -6296,6 +6609,19 @@
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"@napi-rs/triples": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@napi-rs/triples/-/triples-1.2.0.tgz",
"integrity": "sha512-HAPjR3bnCsdXBsATpDIP5WCrw0JcACwhhrwIAQhiR46n+jm+a2F8kBsfseAuWtSyQ+H3Yebt2k43B5dy+04yMA=="
},
"@node-rs/helper": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/@node-rs/helper/-/helper-1.5.0.tgz",
"integrity": "sha512-4E1laLlg532nkrvUohZzl/wFos3bsHExSDw/guaoLekMcTKtD3ZsH6Vc4/qIRzOzAhQv5LLRnTE+vOeJ6C9Z8w==",
"requires": {
"@napi-rs/triples": "^1.2.0"
}
},
"@nodelib/fs.scandir": {
"version": "2.1.5",
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
@ -8287,6 +8613,27 @@
"resolved": "https://registry.npmjs.org/luxon/-/luxon-1.28.1.tgz",
"integrity": "sha512-gYHAa180mKrNIUJCbwpmD0aTu9kV0dREDrwNnuyFAsO1Wt0EVYSZelPnJlbj9HplzXX/YWXHFTL45kvZ53M0pw=="
},
"lz4-napi": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/lz4-napi/-/lz4-napi-2.2.0.tgz",
"integrity": "sha512-n2xx3j7rILyd7OXxQoFXmyEpEJywfAXSnK6br2woep7j/7RV86gc7xLTITaM5/KZnQJb5exSvpcz+lTZ8npXgg==",
"requires": {
"@antoniomuso/lz4-napi-android-arm-eabi": "2.2.0",
"@antoniomuso/lz4-napi-android-arm64": "2.2.0",
"@antoniomuso/lz4-napi-darwin-arm64": "2.2.0",
"@antoniomuso/lz4-napi-darwin-x64": "2.2.0",
"@antoniomuso/lz4-napi-freebsd-x64": "2.2.0",
"@antoniomuso/lz4-napi-linux-arm-gnueabihf": "2.2.0",
"@antoniomuso/lz4-napi-linux-arm64-gnu": "2.2.0",
"@antoniomuso/lz4-napi-linux-arm64-musl": "2.2.0",
"@antoniomuso/lz4-napi-linux-x64-gnu": "2.2.0",
"@antoniomuso/lz4-napi-linux-x64-musl": "2.2.0",
"@antoniomuso/lz4-napi-win32-arm64-msvc": "2.2.0",
"@antoniomuso/lz4-napi-win32-ia32-msvc": "2.2.0",
"@antoniomuso/lz4-napi-win32-x64-msvc": "2.2.0",
"@node-rs/helper": "^1.3.3"
}
},
"make-dir": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz",

View file

@ -27,6 +27,7 @@
"express-rate-limit": "^6.7.0",
"form-data": "^4.0.0",
"lodash": "^4.17.21",
"lz4-napi": "^2.2.0",
"pg": "^8.8.0",
"rate-limit-redis": "^3.0.1",
"redis": "^4.5.0",

View file

@ -7,7 +7,7 @@ import { config } from "../config";
async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
try {
const reply = await redis.get(key);
const reply = await redis.getCompressed(key);
if (reply) {
Logger.debug(`Got data from redis: ${reply}`);
@ -21,7 +21,7 @@ async function get<T>(fetchFromDB: () => Promise<T>, key: string): Promise<T> {
const data = await fetchFromDB();
redis.setEx(key, config.redis?.expiryTime, JSON.stringify(data)).catch((err) => Logger.error(err));
redis.setExCompressed(key, config.redis?.expiryTime, JSON.stringify(data)).catch((err) => Logger.error(err));
return data;
}
@ -36,7 +36,7 @@ async function getTraced<T>(fetchFromDB: () => Promise<T>, key: string): Promise
const startTime = Date.now();
try {
const reply = await redis.get(key);
const reply = await redis.getCompressed(key);
if (reply) {
Logger.debug(`Got data from redis: ${reply}`);
@ -55,7 +55,7 @@ async function getTraced<T>(fetchFromDB: () => Promise<T>, key: string): Promise
const dbStartTime = Date.now();
const data = await fetchFromDB();
redis.setEx(key, config.redis?.expiryTime, JSON.stringify(data)).catch((err) => Logger.error(err));
redis.setExCompressed(key, config.redis?.expiryTime, JSON.stringify(data)).catch((err) => Logger.error(err));
return {
data,

View file

@ -53,7 +53,7 @@ const writeResponseTime: number[] = [];
let lastResponseTimeLimit = 0;
const maxStoredTimes = 200;
export class TooManyActiveConnectionsError extends Error { }
export class TooManyActiveConnectionsError extends Error {}
export let connectionPromise = Promise.resolve();
@ -106,7 +106,7 @@ if (config.redis?.enabled) {
readResponseTime.push(responseTime);
if (readResponseTime.length > maxStoredTimes) readResponseTime.shift();
if (config.redis.stopWritingAfterResponseTime
&& responseTime > config.redis.stopWritingAfterResponseTime) {
&& responseTime > config.redis.stopWritingAfterResponseTime) {
Logger.error(`Hit response time limit at ${responseTime}ms`);
lastResponseTimeLimit = Date.now();
}
@ -126,7 +126,7 @@ if (config.redis?.enabled) {
new Promise((resolve, reject) => {
if ((config.redis.maxWriteConnections && activeRequests > config.redis.maxWriteConnections)
|| (config.redis.responseTimePause
&& Date.now() - lastResponseTimeLimit < config.redis.responseTimePause)) {
&& Date.now() - lastResponseTimeLimit < config.redis.responseTimePause)) {
reject(`Too many active requests to write due to ${activeRequests} requests and ${Date.now() - lastResponseTimeLimit}ms since last limit. ${(db as Postgres)?.getStats?.()?.activeRequests} active db requests with ${(db as Postgres)?.getStats?.()?.avgReadTime}ms`);
return;
}
@ -162,7 +162,7 @@ if (config.redis?.enabled) {
.catch((err) => reject(err))
);
/* istanbul ignore next */
client.on("error", function (error) {
client.on("error", function(error) {
lastClientFail = Date.now();
Logger.error(`Redis Error: ${error}`);
});
@ -171,7 +171,7 @@ if (config.redis?.enabled) {
Logger.info("Redis: trying to reconnect");
});
/* istanbul ignore next */
readClient?.on("error", function (error) {
readClient?.on("error", function(error) {
lastReadFail = Date.now();
Logger.error(`Redis Read-Only Error: ${error}`);
});
@ -186,7 +186,7 @@ function pickChoice<T>(client: T, readClient: T): T {
const ignoreReadDueToFailure = lastReadFail > Date.now() - 1000 * 30;
const readDueToFailure = lastClientFail > Date.now() - 1000 * 30;
if (readAvailable && !ignoreReadDueToFailure && (readDueToFailure ||
Math.random() > 1 / (config.redisRead?.weight + 1))) {
Math.random() > 1 / (config.redisRead?.weight + 1))) {
return readClient;
} else {
return client;

View file

@ -5,43 +5,43 @@ import { Logger } from "./logger";
import { BrandingUUID } from "../types/branding.model";
export const skipSegmentsKey = (videoID: VideoID, service: Service): string =>
`segments.v4.${service}.videoID.${videoID}`;
`segments.v6.${service}.videoID.${videoID}`;
export const skipSegmentGroupsKey = (videoID: VideoID, service: Service): string =>
`segments.groups.v3.${service}.videoID.${videoID}`;
`segments.groups.v5.${service}.videoID.${videoID}`;
export function skipSegmentsHashKey(hashedVideoIDPrefix: VideoIDHash, service: Service): string {
hashedVideoIDPrefix = hashedVideoIDPrefix.substring(0, 4) as VideoIDHash;
if (hashedVideoIDPrefix.length !== 4) Logger.warn(`Redis skip segment hash-prefix key is not length 4! ${hashedVideoIDPrefix}`);
return `segments.v4.${service}.${hashedVideoIDPrefix}`;
return `segments.v6.${service}.${hashedVideoIDPrefix}`;
}
export const brandingKey = (videoID: VideoID, service: Service): string =>
`branding.v2.${service}.videoID.${videoID}`;
`branding.v4.${service}.videoID.${videoID}`;
export function brandingHashKey(hashedVideoIDPrefix: VideoIDHash, service: Service): string {
hashedVideoIDPrefix = hashedVideoIDPrefix.substring(0, 4) as VideoIDHash;
if (hashedVideoIDPrefix.length !== 4) Logger.warn(`Redis skip segment hash-prefix key is not length 4! ${hashedVideoIDPrefix}`);
return `branding.v2.${service}.${hashedVideoIDPrefix}`;
return `branding.v4.${service}.${hashedVideoIDPrefix}`;
}
export const brandingIPKey = (uuid: BrandingUUID): string =>
`branding.shadow.${uuid}`;
`branding.v2.shadow.${uuid}`;
export const shadowHiddenIPKey = (videoID: VideoID, timeSubmitted: number, service: Service): string =>
`segments.${service}.videoID.${videoID}.shadow.${timeSubmitted}`;
`segments.v2.${service}.videoID.${videoID}.shadow.${timeSubmitted}`;
export const reputationKey = (userID: UserID): string =>
`reputation.user.${userID}`;
`reputation.v2.user.${userID}`;
export function ratingHashKey(hashPrefix: VideoIDHash, service: Service): string {
hashPrefix = hashPrefix.substring(0, 4) as VideoIDHash;
if (hashPrefix.length !== 4) Logger.warn(`Redis rating hash-prefix key is not length 4! ${hashPrefix}`);
return `rating.${service}.${hashPrefix}`;
return `rating.v2.${service}.${hashPrefix}`;
}
export function shaHashKey(singleIter: HashedValue): string {
@ -54,15 +54,15 @@ export const tempVIPKey = (userID: HashedUserID): string =>
`vip.temp.${userID}`;
export const videoLabelsKey = (videoID: VideoID, service: Service): string =>
`labels.v1.${service}.videoID.${videoID}`;
`labels.v3.${service}.videoID.${videoID}`;
export function videoLabelsHashKey(hashedVideoIDPrefix: VideoIDHash, service: Service): string {
hashedVideoIDPrefix = hashedVideoIDPrefix.substring(0, 3) as VideoIDHash;
if (hashedVideoIDPrefix.length !== 3) Logger.warn(`Redis video labels hash-prefix key is not length 3! ${hashedVideoIDPrefix}`);
return `labels.v1.${service}.${hashedVideoIDPrefix}`;
return `labels.v3.${service}.${hashedVideoIDPrefix}`;
}
export function userFeatureKey (userID: HashedUserID, feature: Feature): string {
return `user.${userID}.feature.${feature}`;
return `user.v2.${userID}.feature.${feature}`;
}

View file

@ -37,6 +37,12 @@ export async function acquireLock(key: string, timeout = defaultTimeout): Promis
}
} catch (e) {
Logger.error(e as string);
// Fallback to allowing
return {
status: true,
unlock: () => void 0
};
}
return {