Skip to content

perf(database): optimize N+1 query problem in case fetching#1176

Open
Nikhil-0710 wants to merge 1 commit into
viru0909-dev:mainfrom
Nikhil-0710:perf/issue-831-n-plus-one
Open

perf(database): optimize N+1 query problem in case fetching#1176
Nikhil-0710 wants to merge 1 commit into
viru0909-dev:mainfrom
Nikhil-0710:perf/issue-831-n-plus-one

Conversation

@Nikhil-0710
Copy link
Copy Markdown

Summary

Closes #831

Optimized the case fetching mechanism by implementing JOIN FETCH in CaseRepository to eagerly load associated documents. This eliminates the N+1 query problem where the application was executing redundant database calls for every case to retrieve its documents.

Implementation Details

  • Added findAllWithDocuments() method to CaseRepository.java.
  • Used JPQL LEFT JOIN FETCH c.documents to ensure cases and documents are retrieved in a single optimized database transaction.
  • This change will significantly reduce database load as the number of cases and documents grows.

Testing

  • Verified compilation success (mvn clean compile).
  • Code follows project naming conventions.
  • Validated that existing repository methods remain functional.

Checklist

  • Code follows the project's style guide.
  • No unrelated files are included in this PR.
  • Commit message follows Conventional Commits format.
  • PR is targeting the correct base branch (main).

@Nikhil-0710 Nikhil-0710 requested a review from viru0909-dev as a code owner June 4, 2026 19:05
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 4, 2026

@Nikhil-0710 is attempting to deploy a commit to the CodeBlooded's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

Hi @Nikhil-0710, thanks for contributing to Nyay Setu! 🎉

I have automatically:

  • 👤 Assigned this PR to you.
  • 🏷️ Applied the gssoc:approved label.

Our workflows will now analyze your changes to classify:

  • 📈 PR Difficulty: level:*
  • 🧩 PR Type: type:*
  • 🌟 PR Quality: quality:*

Tip

Ensure your PR description references the issue it resolves (e.g. Closes #123). This allows the bot to inherit any additional labels from that issue!

Happy coding! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Backend] Optimize N+1 query problem in Case Fetching

1 participant