Skip to content

feat: fix backend issues with state and memory leak#23

Merged
RMCampos merged 4 commits intomainfrom
fix/memory-leak
Mar 2, 2026
Merged

feat: fix backend issues with state and memory leak#23
RMCampos merged 4 commits intomainfrom
fix/memory-leak

Conversation

@RMCampos
Copy link
Owner

@RMCampos RMCampos commented Mar 2, 2026

Description

These changes addressed the memory leak issue, where it's possible to notice more memory RAM being consumed by the backend container.

The changes include:

  • Add Spring Security property to make it stateless
  • Change Hibernate behavior to not create session for lazy loading (enableAssociationManagement)
  • Address entities and mappings accordingly to meet the new session definitions
  • Small improvements

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to reduce backend memory usage/leak risk by enforcing stateless security and disabling Hibernate’s Open Session in View / association management, then updating the note/URL persistence model and service/controller DTO mapping accordingly.

Changes:

  • Configure Spring Security to be stateless and disable spring.jpa.open-in-view.
  • Refactor note URL handling to avoid relying on lazy-loaded entity associations (fetch URL via repository instead).
  • Improve operational safety: cap login-attempt queries to the most recent 3 rows; add RestTemplate timeouts for Mailgun; adjust tests.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
server/src/test/java/br/com/tasknoteapp/server/service/NoteServiceTest.java Adjust test expectations to new createNote return type (NoteResponse).
server/src/test/java/br/com/tasknoteapp/server/service/MailgunEmailServiceTest.java Update mocks to reflect RestTemplateBuilder timeout configuration.
server/src/test/java/br/com/tasknoteapp/server/service/AuthServiceTest.java Update tests to use new findTop3...OrderBy...Desc repository method.
server/src/test/java/br/com/tasknoteapp/server/controller/NoteControllerTest.java Align controller tests with NoteResponse-returning service/controller flow.
server/src/main/resources/application.yml Disable Open Session in View; turn off SQL logging.
server/src/main/resources/application-native.yml Disable Open Session in View; turn off SQL logging (native profile).
server/src/main/java/br/com/tasknoteapp/server/service/impl/UserServiceImpl.java Cache UserDetailsService instance rather than recreating it each call.
server/src/main/java/br/com/tasknoteapp/server/service/NoteService.java Refactor note CRUD/DTO mapping to fetch URL via repository and avoid entity association reliance.
server/src/main/java/br/com/tasknoteapp/server/service/MailgunEmailService.java Add connect/read timeouts to RestTemplate.
server/src/main/java/br/com/tasknoteapp/server/service/AuthService.java Limit failed-login-attempt query to most recent 3 entries.
server/src/main/java/br/com/tasknoteapp/server/response/NoteResponse.java Update fromEntity to accept URL as an explicit argument.
server/src/main/java/br/com/tasknoteapp/server/repository/UserPwdLimitRepository.java Add findTop3ByUser_idOrderByWhenHappenedDesc.
server/src/main/java/br/com/tasknoteapp/server/repository/NoteUrlRepository.java Add findByNote_id to support explicit URL lookup.
server/src/main/java/br/com/tasknoteapp/server/entity/UserEntity.java Remove unused tasks relationship.
server/src/main/java/br/com/tasknoteapp/server/entity/NoteEntity.java Remove noteUrl relationship to avoid lazy-loading reliance.
server/src/main/java/br/com/tasknoteapp/server/controller/NoteController.java Return NoteResponse directly from service for POST create.
server/src/main/java/br/com/tasknoteapp/server/config/SecurityConfig.java Set session creation policy to STATELESS.
server/pom.xml Disable Hibernate enhancer association management.
docker-compose.dev.yml Bump Maven container image version used for dev.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@RMCampos RMCampos merged commit 5041ebe into main Mar 2, 2026
1 check passed
@RMCampos RMCampos deleted the fix/memory-leak branch March 2, 2026 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants