N+1 fixed
|
@ -9,6 +9,11 @@
|
||||||
<module name="spring-petclinic.main" />
|
<module name="spring-petclinic.main" />
|
||||||
<option name="PROGRAM_PARAMETERS" value="--warning-mode all" />
|
<option name="PROGRAM_PARAMETERS" value="--warning-mode all" />
|
||||||
<option name="VM_PARAMETERS" value="-Dotel.instrumentation.jdbc-datasource.enabled=true" />
|
<option name="VM_PARAMETERS" value="-Dotel.instrumentation.jdbc-datasource.enabled=true" />
|
||||||
|
<extension name="software.aws.toolkits.jetbrains.core.execution.JavaAwsConnectionExtension">
|
||||||
|
<option name="credential" />
|
||||||
|
<option name="region" />
|
||||||
|
<option name="useCurrentConnection" value="false" />
|
||||||
|
</extension>
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="Gradle.BeforeRunTask" enabled="true" tasks="bootJar" externalProjectPath="$PROJECT_DIR$" vmOptions="" scriptParameters="" />
|
<option name="Gradle.BeforeRunTask" enabled="true" tasks="bootJar" externalProjectPath="$PROJECT_DIR$" vmOptions="" scriptParameters="" />
|
||||||
</method>
|
</method>
|
||||||
|
|
Before Width: | Height: | Size: 172 KiB After Width: | Height: | Size: 172 KiB |
BIN
AfterOverview.png
Normal file
After Width: | Height: | Size: 480 KiB |
BIN
AfterTrace.png
Before Width: | Height: | Size: 111 KiB After Width: | Height: | Size: 265 KiB |
Before Width: | Height: | Size: 485 KiB After Width: | Height: | Size: 485 KiB |
Before Width: | Height: | Size: 793 KiB After Width: | Height: | Size: 793 KiB |
|
@ -20,6 +20,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import io.opentelemetry.instrumentation.annotations.WithSpan;
|
import io.opentelemetry.instrumentation.annotations.WithSpan;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.PageImpl;
|
||||||
import org.springframework.data.domain.PageRequest;
|
import org.springframework.data.domain.PageRequest;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
@ -104,9 +105,8 @@ class OwnerController {
|
||||||
// empty owner search for all records without n+1 queries
|
// empty owner search for all records without n+1 queries
|
||||||
if (StringUtils.isEmpty(owner.getLastName())){
|
if (StringUtils.isEmpty(owner.getLastName())){
|
||||||
List<Owner> ownerList = owners.findAllWithPetsAndVisits();
|
List<Owner> ownerList = owners.findAllWithPetsAndVisits();
|
||||||
//model.addAttribute("owners", ownerList);
|
Page<Owner> ownerPageNP1 = new PageImpl<>(ownerList);
|
||||||
//need to figure out displaying owners without n+1.
|
return addPaginationModel(0, model, ownerPageNP1);
|
||||||
return "owners/ownersList";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// find owners by last name
|
// find owners by last name
|
||||||
|
@ -139,7 +139,7 @@ class OwnerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Page<Owner> findPaginatedForOwnersLastName(int page, String lastname) {
|
private Page<Owner> findPaginatedForOwnersLastName(int page, String lastname) {
|
||||||
int pageSize = 12;
|
int pageSize = 5;
|
||||||
Pageable pageable = PageRequest.of(page - 1, pageSize);
|
Pageable pageable = PageRequest.of(page - 1, pageSize);
|
||||||
return owners.findByLastName(lastname, pageable);
|
return owners.findByLastName(lastname, pageable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,6 @@ public interface OwnerRepository extends Repository<Owner, Integer> {
|
||||||
* Retrieve {@link Owner}s all owners including their pets and visitations
|
* Retrieve {@link Owner}s all owners including their pets and visitations
|
||||||
* @return a Collection of {@link Owner}s
|
* @return a Collection of {@link Owner}s
|
||||||
*/
|
*/
|
||||||
/*@Query("SELECT DISTINCT owner FROM Owner owner LEFT JOIN FETCH owner.pets pet LEFT JOIN FETCH visits WHERE pet.id = visits.petId")
|
|
||||||
List<Owner> findAllWithPetsAndVisits();*/
|
|
||||||
@Query("SELECT DISTINCT owner FROM Owner owner LEFT JOIN FETCH owner.pets LEFT JOIN FETCH pets.visits")
|
@Query("SELECT DISTINCT owner FROM Owner owner LEFT JOIN FETCH owner.pets LEFT JOIN FETCH pets.visits")
|
||||||
List<Owner> findAllWithPetsAndVisits();
|
List<Owner> findAllWithPetsAndVisits();
|
||||||
|
|
||||||
|
|