Skip to content

Conversation

Copy link

Copilot AI commented Dec 23, 2025

Student lookup operations were executing multiple separate queries (N+1 problem), fetching user, student info, fixed rooms, and attendance data in separate database round trips.

Changes

  • Added StudentQueryRepository with QueryDSL methods that fetch all student data in single queries using joins:

    • findAllInfoByStatusAndRoomAndType() - fetch by room and attendance type
    • findAllInfoByStatusAndGradeAndCls() - fetch by grade and class
    • findAllInfoByRoomTypeStatusAndRole() - fetch by room type and status
  • Refactored service layer to use new repository methods:

    • GetStudentService now calls findAllInfoByStatusAndRoomAndType() and findAllInfoByStatusAndGradeAndCls()
    • GetNotAttendedStudentService leverages same methods with status filtering

Query Example

Before: Multiple queries executed per student

// Separate queries for each entity
students.forEach { student ->
    studentInfo = findStudentInfo(student.id)
    fixedRooms = findFixedRooms(student.id)
    attendance = findAttendance(student.id)
}

After: Single query with joins

queryFactory.from(userEntity)
    .innerJoin(studentInfoEntity).on(...)
    .innerJoin(fixedRoomEntity).on(...)
    .leftJoin(attendanceEntity).on(...)
    .transform(groupBy(userEntity.id).list(...))

The new queries use groupBy with transform() to aggregate related entities and return a List<StudentQueryDto> containing all necessary data from a single database query.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Improve student search performance with QueryDSL Optimize student queries with QueryDSL to reduce N+1 queries Dec 23, 2025
Copilot AI requested a review from Finefinee December 23, 2025 06:06
@Finefinee Finefinee closed this Dec 23, 2025
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