baja-lite 1.8.2 → 1.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/sql.d.ts +1 -1
- package/sql.js +22 -9
package/package.json
CHANGED
package/sql.d.ts
CHANGED
|
@@ -2139,7 +2139,7 @@ export declare function clearMethodCache(key: string): Promise<void>;
|
|
|
2139
2139
|
*/
|
|
2140
2140
|
export declare function excuteWithCache<T>(config: {
|
|
2141
2141
|
/** 返回缓存key,参数=方法的参数+当前用户对象,可以用来清空缓存。 */
|
|
2142
|
-
key: string;
|
|
2142
|
+
key: ((...args: any[]) => string) | string;
|
|
2143
2143
|
/** 返回缓存清除key,参数=方法的参数+当前用户对象,可以用来批量清空缓存 */
|
|
2144
2144
|
clearKey?: string[];
|
|
2145
2145
|
/** 自动清空缓存的时间,单位分钟 */
|
package/sql.js
CHANGED
|
@@ -1916,7 +1916,11 @@ function P(skipConn = false) {
|
|
|
1916
1916
|
resolve(result);
|
|
1917
1917
|
}
|
|
1918
1918
|
catch (error) {
|
|
1919
|
-
|
|
1919
|
+
let args = '';
|
|
1920
|
+
if (args.length > 0 && args[0].params) {
|
|
1921
|
+
args = JSON.stringify(args[0].params);
|
|
1922
|
+
}
|
|
1923
|
+
console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${args}`);
|
|
1920
1924
|
reject(error);
|
|
1921
1925
|
}
|
|
1922
1926
|
finally {
|
|
@@ -1946,7 +1950,11 @@ function P(skipConn = false) {
|
|
|
1946
1950
|
resolve(result);
|
|
1947
1951
|
}
|
|
1948
1952
|
catch (error) {
|
|
1949
|
-
|
|
1953
|
+
let args = '';
|
|
1954
|
+
if (args.length > 0 && args[0].params) {
|
|
1955
|
+
args = JSON.stringify(args[0].params);
|
|
1956
|
+
}
|
|
1957
|
+
console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${args}`);
|
|
1950
1958
|
reject(error);
|
|
1951
1959
|
}
|
|
1952
1960
|
finally {
|
|
@@ -1976,7 +1984,11 @@ function P(skipConn = false) {
|
|
|
1976
1984
|
resolve(result);
|
|
1977
1985
|
}
|
|
1978
1986
|
catch (error) {
|
|
1979
|
-
|
|
1987
|
+
let args = '';
|
|
1988
|
+
if (args.length > 0 && args[0].params) {
|
|
1989
|
+
args = JSON.stringify(args[0].params);
|
|
1990
|
+
}
|
|
1991
|
+
console.error(`${option.sqlId ?? option.tableName} service ${propertyKey} have an error:${error}, it's argumens: ${args}`);
|
|
1980
1992
|
reject(error);
|
|
1981
1993
|
}
|
|
1982
1994
|
finally {
|
|
@@ -5154,7 +5166,7 @@ export async function GetRedisLock(key, lockMaxActive) {
|
|
|
5154
5166
|
;
|
|
5155
5167
|
/** 对FN加锁、缓存执行 */
|
|
5156
5168
|
export async function excuteWithLock(config, fn__) {
|
|
5157
|
-
const key = `[lock]${typeof config.key === 'function' ? config.key() : config.key}`;
|
|
5169
|
+
const key = config.key_real ? `[lock]${config.key_real}` : `[lock]${typeof config.key === 'function' ? config.key() : config.key}`;
|
|
5158
5170
|
const db = getRedisDB();
|
|
5159
5171
|
let wait_time = 0;
|
|
5160
5172
|
const fn = async () => {
|
|
@@ -5190,7 +5202,7 @@ export function MethodLock(config) {
|
|
|
5190
5202
|
return function (target, _propertyKey, descriptor) {
|
|
5191
5203
|
const fn__ = descriptor.value;
|
|
5192
5204
|
descriptor.value = async function (...args) {
|
|
5193
|
-
config.
|
|
5205
|
+
config.key_real = typeof config.key === 'function' ? config.key.call(target, ...args) : config.key;
|
|
5194
5206
|
return await excuteWithLock(config, async () => await fn__.call(this, ...args));
|
|
5195
5207
|
};
|
|
5196
5208
|
};
|
|
@@ -5271,16 +5283,17 @@ async function clearParent(clearKey) {
|
|
|
5271
5283
|
*/
|
|
5272
5284
|
export async function excuteWithCache(config, fn) {
|
|
5273
5285
|
const db = getRedisDB();
|
|
5274
|
-
const
|
|
5286
|
+
const key = typeof config.key === 'function' ? config.key() : config.key;
|
|
5287
|
+
const cache = await db.get(`[cache]${key}`);
|
|
5275
5288
|
if (cache) {
|
|
5276
|
-
globalThis[_LoggerService].debug?.(`cache ${
|
|
5289
|
+
globalThis[_LoggerService].debug?.(`cache ${key} hit!`);
|
|
5277
5290
|
return JSON.parse(cache);
|
|
5278
5291
|
}
|
|
5279
5292
|
else {
|
|
5280
|
-
globalThis[_LoggerService].debug?.(`cache ${config.key} miss!`);
|
|
5281
5293
|
const result = await fn();
|
|
5294
|
+
globalThis[_LoggerService].debug?.(`cache ${key} miss!`);
|
|
5282
5295
|
await setMethodCache({
|
|
5283
|
-
key
|
|
5296
|
+
key,
|
|
5284
5297
|
clearKey: config.clearKey,
|
|
5285
5298
|
autoClearTime: config.autoClearTime,
|
|
5286
5299
|
result
|