Performance: Service calling repository
MEDIUM IMPACT
This pattern affects backend response time and indirectly impacts frontend load speed and interaction responsiveness.
public class UserService { @Autowired private UserRepository userRepository; public List<User> getAllUsers() { List<Long> ids = getUserIds(); return userRepository.findAllById(ids); } }
public class UserService { @Autowired private UserRepository userRepository; public List<User> getAllUsers() { List<User> users = new ArrayList<>(); for (Long id : getUserIds()) { users.add(userRepository.findById(id).orElse(null)); } return users; } }
| Pattern | Database Queries | Backend Latency | Network Payload | Verdict |
|---|---|---|---|---|
| Multiple repository calls in loop | N queries for N items | High due to query overhead | Normal | [X] Bad |
| Single batch repository call | 1 query for all items | Low due to reduced overhead | Normal | [OK] Good |