perf: 优化内存占用

This commit is contained in:
xiaojunnuo
2024-08-28 14:40:50 +08:00
parent 42a56b581d
commit db61033633
15 changed files with 98 additions and 80 deletions
@@ -11,10 +11,10 @@ import { PermissionService } from './permission-service.js';
import { UserRoleService } from './user-role-service.js';
import { Constants } from '../../../basic/constants.js';
import { UserRoleEntity } from '../entity/user-role.js';
import { randomText } from 'svg-captcha';
import bcrypt from 'bcryptjs';
import { SysSettingsService } from '../../system/service/sys-settings-service.js';
import { SysInstallInfo } from '../../system/service/models.js';
import { RandomUtil } from '../../../utils/random.js';
/**
* 系统用户
@@ -64,7 +64,7 @@ export class UserService extends BaseService<UserEntity> {
if (!_.isEmpty(exists)) {
throw new CommonException('用户名已经存在');
}
const plainPassword = param.password ?? randomText(6);
const plainPassword = param.password ?? RandomUtil.randomStr(6);
param.passwordVersion = 2;
param.password = await this.genPassword(plainPassword, param.passwordVersion); // 默认密码 建议未改密码不能登陆
await super.add(param);
@@ -156,7 +156,7 @@ export class UserService extends BaseService<UserEntity> {
passwordVersion: 2,
});
if (!newUser.password) {
newUser.password = randomText(6);
newUser.password = RandomUtil.randomStr(6);
}
newUser.password = await this.genPassword(newUser.password, newUser.passwordVersion);
@@ -1,6 +1,5 @@
import { Inject, Provide } from '@midwayjs/core';
import { CacheManager } from '@midwayjs/cache';
import svgCaptcha from 'svg-captcha';
// {data: '<svg.../svg>', text: 'abcd'}
/**
@@ -14,6 +13,7 @@ export class CodeService {
*/
async generateCaptcha(randomStr) {
console.assert(randomStr < 10, 'randomStr 过长');
const svgCaptcha = await import('svg-captcha');
const c = svgCaptcha.create();
//{data: '<svg.../svg>', text: 'abcd'}
const imgCode = c.text; // = RandomUtil.randomStr(4, true);