Skip to content

Commit

Permalink
feat: [390] - Purge non-confirmed users periodically
Browse files Browse the repository at this point in the history
  • Loading branch information
lucifercr07 committed Jun 6, 2024
1 parent 8690f97 commit eaf77af
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/nonononoki/alovoa/repo/UserRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ default List<User> usersSearch(UserSearchRequest request, Pageable page) {
request.getLikeIds(), request.getHideIds(), request.getBlockIds(), request.getGenderIds(), page);
}

List<User> findByConfirmedIsFalse();

@Query(value = "SELECT u FROM User u WHERE u.disabled = FALSE AND u.admin = FALSE AND u.confirmed = TRUE AND u.intention IS NOT NULL AND "
+ "u.locationLatitude IS NOT NULL AND u.locationLongitude IS NOT NULL AND u.profilePicture IS NOT NULL "
+ "AND TIMESTAMPDIFF(YEAR, u.dates.dateOfBirth, CURDATE()) + u.preferedMaxAge >= :age AND TIMESTAMPDIFF(YEAR, u.dates.dateOfBirth, CURDATE()) + u.preferedMinAge <= :age AND u.dates.dateOfBirth >= :minDate AND u.dates.dateOfBirth <= :maxDate "
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/com/nonononoki/alovoa/service/ScheduleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public class ScheduleService {
@Value("${app.schedule.delay.contact}")
private long contactDelay;

@Value("${app.schedule.delay.user.cleanup:}")
private long nonConfirmedUsersCleanupDelay;

private static final int HIDE_MAX = 20;

@Scheduled(fixedDelayString = "${app.schedule.short}")
Expand All @@ -63,9 +66,23 @@ public void scheduleLong() {
if (enableSchedules) {
Date date = new Date();
cleanContact(date);
cleanNonConfirmedUsers(date);
}
}

private void cleanNonConfirmedUsers(final Date date) {
long ms = date.getTime();
ms -= nonConfirmedUsersCleanupDelay;
Date d = new Date(ms);

List<User> users = userRepo.findByConfirmedIsFalse().stream()
.filter(user -> (user.getDates() != null && user.getDates().getCreationDate().before(d)))
.toList();

userRepo.deleteAll(users);
userRepo.flush();
}

public void cleanCaptcha(Date date) {
long ms = date.getTime();
ms -= captchaDelay;
Expand Down
25 changes: 16 additions & 9 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ spring.datasource.url=jdbc:mariadb://localhost:3306/alovoa?createDatabaseIfNotEx
#spring.datasource.hikari.maxLifetime=1800000

#Insert your oauth2 ids and secrets here
spring.security.oauth2.client.registration.google.client-id=test
spring.security.oauth2.client.registration.google.client-secret=test
spring.security.oauth2.client.registration.facebook.client-id=test
spring.security.oauth2.client.registration.facebook.client-secret=test
#spring.security.oauth2.client.registration.google.client-id=<your client id>
#spring.security.oauth2.client.registration.google.client-secret=<your client secret>
#spring.security.oauth2.client.registration.facebook.client-id=<your client id>
Expand Down Expand Up @@ -60,25 +64,26 @@ spring.jpa.properties.hibernate.plan_parameter_metadata_max_size=16
spring.jpa.properties.hibernate.query.in_clause_parameter_padding=true

### KEYS AND CREDENTIALS ###
#spring.datasource.password=
#spring.datasource.username=
spring.datasource.password=mypass
spring.datasource.username=root
#keys for transparent database encryption
#app.text.key= #key must be 16, 24 or 32 bytes long
#app.text.salt= #salt must be 16 bytes long
#app.admin.email=
app.text.key=bqupWgmhCj3fedLxYdNAy2QFA2bS9XJX
app.text.salt=sFRKQAhwdrZq44FQ#app.admin.email=
app.admin.email=admin@alovoa.com
app.admin.key=password
#app.admin.key=
#spring.mail.password=<login password to smtp server>
spring.mail.host=mail.gmx.net
spring.mail.password=5550f635c82e7e
spring.mail.host=sandbox.smtp.mailtrap.io
spring.mail.port=587
spring.mail.username=nonononoki@gmx.de
spring.mail.username=e81ae4ff934777
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.test-connection=true
spring.mail.properties.mail.smtp.ssl.checkserveridentity=false

# logging
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n
logging.level.org.springframework.web=INFO
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate.SQL=ERROR
logging.level.org.hibernate=ERROR
logging.file.name=./logs/spring.log
Expand Down Expand Up @@ -304,3 +309,5 @@ app.schedule.delay.captcha=300000
app.schedule.delay.hide=9720000000
#90 days
app.schedule.delay.contact=9720000000
#14 days
app.schedule.delay.user.cleanup=1209600000

0 comments on commit eaf77af

Please sign in to comment.