Skip to content

Commit

Permalink
perf($MyBatisPlus): data source loading improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnymillergh committed Jul 19, 2021
1 parent 8a3bd31 commit 254674b
Show file tree
Hide file tree
Showing 38 changed files with 151 additions and 289 deletions.
2 changes: 1 addition & 1 deletion api-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>muscle-and-fitness-server</artifactId>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>
</parent>

<!-- Build Settings -->
Expand Down
2 changes: 1 addition & 1 deletion auth-center/auto-run-windows.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ SET skipMavenBuild=true
SET minimalJavaMajorVersion=11
SET javaExe=C:\Users\Johnny\.sdkman\candidates\java\11.0.10.hs-adpt\bin\java.exe
SET mavenActiveProfile="development-local"
SET javaParameter=-Xms256m -Xmx256m -Dfile.encoding=UTF-8 -Dspring.cloud.consul.host=localhost
SET javaParameter=-Xms256m -Xmx256m -Dfile.encoding=UTF-8 -Dspring.cloud.consul.host=localhost -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:2345

GOTO:MAIN

Expand Down
2 changes: 1 addition & 1 deletion auth-center/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>muscle-and-fitness-server</artifactId>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>
</parent>

<!-- Build Settings -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us

@Override
public GetUserByLoginTokenResponse getUserByLoginToken(@NotBlank String loginToken) {
val key = String.format(mafProjectProperty.getProjectParentArtifactId()
+ UserRedisKey.GET_USER_BY_LOGIN_TOKEN.getKeyInfixFormat(), loginToken);
val hasKey = redisTemplate.hasKey(key);
val key = String.format(String.format("%s%s", this.mafProjectProperty.getProjectParentArtifactId(),
UserRedisKey.GET_USER_BY_LOGIN_TOKEN.getKeyInfixFormat()), loginToken);
val hasKey = this.redisTemplate.hasKey(key);
if (BooleanUtil.isTrue(hasKey)) {
return JSONUtil.toBean(redisTemplate.opsForValue().get(key), GetUserByLoginTokenResponse.class);
return JSONUtil.toBean(this.redisTemplate.opsForValue().get(key), GetUserByLoginTokenResponse.class);
}
val wrapper = Wrappers.lambdaQuery(User.class);
wrapper.and(queryWrapper -> queryWrapper.eq(User::getUsername, loginToken)
Expand All @@ -84,7 +84,8 @@ public GetUserByLoginTokenResponse getUserByLoginToken(@NotBlank String loginTok
}
val response = new GetUserByLoginTokenResponse();
BeanUtil.copyProperties(userPersistence, response);
redisTemplate.opsForValue().set(key, JSONUtil.toJsonStr(response), RandomUtil.randomLong(1, 7), TimeUnit.DAYS);
this.redisTemplate.opsForValue().set(key, JSONUtil.toJsonStr(response), RandomUtil.randomLong(1, 7),
TimeUnit.DAYS);
return response;
}

Expand All @@ -94,11 +95,11 @@ public SignupResponse saveUserForSignup(@Valid SignupPayload payload) {
val user = new User();
user.setUsername(payload.getUsername());
user.setEmail(payload.getEmail());
user.setPassword(bCryptPasswordEncoder.encode(payload.getPassword()));
user.setPassword(this.bCryptPasswordEncoder.encode(payload.getPassword()));
user.setStatus(UserStatus.ENABLED.getValue());
this.save(user);
log.warn("Saved user for signup, going to assign guest role to user. {}", user);
userRoleService.assignRoleByRoleName(user, mafConfiguration.getGuestUserRole());
this.userRoleService.assignRoleByRoleName(user, this.mafConfiguration.getGuestUserRole());
val response = new SignupResponse();
response.setUserId(user.getId());
return response;
Expand All @@ -111,20 +112,20 @@ public LoginResponse login(@Valid LoginPayload payload) throws SecurityException
throw new SecurityException(HttpStatus.UNAUTHORIZED);
}
log.info("User login: {}", user);
val matched = bCryptPasswordEncoder.matches(payload.getPassword(), user.getPassword());
val matched = this.bCryptPasswordEncoder.matches(payload.getPassword(), user.getPassword());
if (!matched) {
throw new SecurityException(HttpStatus.UNAUTHORIZED);
}
val jwt = jwtService.createJwt(payload.getRememberMe(), user.getId(), user.getUsername(), null, null);
val jwt = this.jwtService.createJwt(payload.getRememberMe(), user.getId(), user.getUsername(), null, null);
val response = new LoginResponse();
response.setGreeting(messageSource.getMessage(("greeting"), null, LocaleContextHolder.getLocale()));
response.setGreeting(this.messageSource.getMessage(("greeting"), null, LocaleContextHolder.getLocale()));
response.setJwt(jwt);
return response;
}

@Override
public boolean logout(HttpServletRequest request) throws SecurityException {
jwtService.invalidateJwt(request);
this.jwtService.invalidateJwt(request);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://maf-mysql-server-master:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://maf-mysql-server-slave:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://localhost:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://localhost:3307/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand All @@ -31,12 +31,11 @@ spring:
username: maf_rabbitmq_su
password: maf@rabbitmq

# Configure logging level for the environment
logging:
# Configure logging level for SFTP/JSCH
level:
com.jcraft.jsch: INFO
com.baomidou: INFO

maf:
configuration:
web-request-log-enabled: true
swagger-enabled: true
4 changes: 2 additions & 2 deletions auth-center/src/main/resources/application-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://maf-mysql-server-master:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://maf-mysql-server-slave:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand Down
4 changes: 2 additions & 2 deletions auth-center/src/main/resources/application-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://maf-mysql-server-master:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://maf-mysql-server-slave:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand Down
4 changes: 2 additions & 2 deletions auth-center/src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://maf-mysql-server-master:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://maf-mysql-server-slave:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand Down
29 changes: 16 additions & 13 deletions auth-center/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,24 @@ spring:
health-check-critical-timeout: 15s
datasource:
type: com.alibaba.druid.pool.DruidDataSource
dynamic:
primary: master_1
druid:
initial-size: 5
max-active: 20
min-idle: 2
max-wait: 60000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
keep-alive: true
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
initial-size: 5
minIdle: 10
max-active: 20
max-wait: 60000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
max-open-prepared-statements: 20
keep-alive: true
filters: stat,wall,log4j2
filter:
stat:
Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>muscle-and-fitness-server</artifactId>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>
</parent>

<!-- Scoped Dependencies Management -->
Expand Down
2 changes: 1 addition & 1 deletion maf-mis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>muscle-and-fitness-server</artifactId>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>
</parent>

<!-- Build Settings -->
Expand Down
4 changes: 2 additions & 2 deletions maf-mis/src/main/resources/application-development-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://maf-mysql-server-master:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://maf-mysql-server-slave:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand Down
4 changes: 2 additions & 2 deletions maf-mis/src/main/resources/application-development-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://localhost:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://localhost:3307/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand Down
4 changes: 2 additions & 2 deletions maf-mis/src/main/resources/application-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://maf-mysql-server-master:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://maf-mysql-server-slave:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand Down
4 changes: 2 additions & 2 deletions maf-mis/src/main/resources/application-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://maf-mysql-server-master:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://maf-mysql-server-slave:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand Down
4 changes: 2 additions & 2 deletions maf-mis/src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://maf-mysql-server-master:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://maf-mysql-server-slave:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand Down
29 changes: 16 additions & 13 deletions maf-mis/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,24 @@ spring:
health-check-critical-timeout: 15s
datasource:
type: com.alibaba.druid.pool.DruidDataSource
dynamic:
primary: master_1
druid:
initial-size: 5
max-active: 20
min-idle: 2
max-wait: 60000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
max-pool-prepared-statement-per-connection-size: 20
keep-alive: true
druid:
driver-class-name: com.mysql.cj.jdbc.Driver
initial-size: 5
minIdle: 10
max-active: 20
max-wait: 60000
min-evictable-idle-time-millis: 600000
max-evictable-idle-time-millis: 900000
validation-query: SELECT 1
test-while-idle: true
test-on-borrow: false
test-on-return: false
pool-prepared-statements: true
max-open-prepared-statements: 20
keep-alive: true
filters: stat,wall,log4j2
filter:
stat:
Expand Down
2 changes: 1 addition & 1 deletion oss-center/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.jmsoftware.maf</groupId>
<artifactId>muscle-and-fitness-server</artifactId>
<version>0.0.2</version>
<version>0.0.3-SNAPSHOT</version>
</parent>

<!-- Build Settings -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://maf-mysql-server-master:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://maf-mysql-server-slave:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ spring:
datasource:
dynamic:
datasource:
master:
master_1:
url: jdbc:mysql://localhost:3306/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_rw
password: maf@mysql
driver-class-name: com.mysql.cj.jdbc.Driver
slave1:
slave_1:
url: jdbc:mysql://localhost:3307/muscle_and_fitness?useSSL=true&useUnicode=true
username: maf_mysql_r
password: maf@mysql
Expand Down
Loading

0 comments on commit 254674b

Please sign in to comment.