Performance: Database and app orchestration
This concept affects how quickly the app communicates with the database and manages data flow, impacting page load and interaction speed.
public List<User> getUsers() {
return userRepository.findAllById(IntStream.range(0, 100).boxed().collect(Collectors.toList()));
}public List<User> getUsers() {
List<User> users = new ArrayList<>();
for (int i = 0; i < 100; i++) {
users.add(userRepository.findById(i).orElse(null));
}
return users;
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Multiple individual DB calls | N/A | N/A | Blocks rendering until data arrives | [X] Bad |
| Batch DB calls with async processing | N/A | N/A | Faster data delivery enables quicker paint | [OK] Good |
User with primary key type Long?Optional<User> user = userRepository.findById(5L);
user.isPresent() return if no user with ID 5 exists in the database?public interface ProductRepository extends JpaRepository {
List<Product> findByName(String name);
}findByName(null)?1. Retrieve user by ID
2. Change user's email
3. Save updated user back to database
Pass the test and this pattern moves unknown