Suggestions with implemention
I am working on the implementation where I am creating football games on a schedule. The web application that I am building is for pickup games where players can view the available games and register for available ones. For that purpose, I have implemented as follows, @Transactional private void createNewGames(LocalDate localDate, Games games){ List allVenues = venueRepository.findAll(); // Prepare to collect all games to save in batch List gamesToSave = new ArrayList(); DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("H:mm"); for(Venue venue: allVenues){ HashMap timeSlots = venue.getTimeSlots(); if(timeSlots!=null){ for (Map.Entry entry : timeSlots.entrySet()) { String day_ = entry.getKey().toString(); // Access the key List availableTimes = entry.getValue(); // Access the value for(String time: availableTimes){ try { LocalTime time_ = LocalTime.parse(time, timeFormatter); LocalDateTime dateTime = localDate.with(java.time.DayOfWeek.valueOf(day_)).atTime(time_); log.info("Local Date Time: {}", dateTime); gamesToSave.add(Games.builder().localDateTime(dateTime).isAvailable(true).venue(venue).build()); }catch(Exception ex){ log.error("Failed to create game for time slot = {} with exception = {}", time, ex.getLocalizedMessage()); } } } } } // Save all games in batch after processing all venues and time slots if (!gamesToSave.isEmpty()) { gameRepository.saveAll(gamesToSave); // Assuming saveAll supports batch saving } } So as per my understanding this implementation has ON^3 time complexity which I believe in software engineering is not a good practice. But on the second thought, this method is triggered on a schedule every midnight. So user does not directly interact with this method. However I just wanted to have some idea whether I should leave this implementation as it is right now or try to improve the time complexity of this implementation by possibly redesigning the database. The game entity class currently looks like this, public class Games implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private LocalDateTime localDateTime; @ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY) @JoinTable( name = "game_users", joinColumns = @JoinColumn(name = "game_id"), inverseJoinColumns = @JoinColumn(name = "user_id") ) private List users; @ManyToOne(fetch = FetchType.LAZY) // Many games can be associated with one venue @JoinColumn(name = "venue_id", nullable = false) // Creates a foreign key column in the "games" table private Venue venue; private boolean isAvailable; } Please let me know if I have been clear in my questioning. To summarize I just want to understand the best practices in the industry and possibly any suggestions on improving my current implementations.

I am working on the implementation where I am creating football games on a schedule. The web application that I am building is for pickup games where players can view the available games and register for available ones. For that purpose, I have implemented as follows,
@Transactional
private void createNewGames(LocalDate localDate, Games games){
List allVenues = venueRepository.findAll();
// Prepare to collect all games to save in batch
List gamesToSave = new ArrayList<>();
DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("H:mm");
for(Venue venue: allVenues){
HashMap> timeSlots = venue.getTimeSlots();
if(timeSlots!=null){
for (Map.Entry> entry : timeSlots.entrySet()) {
String day_ = entry.getKey().toString(); // Access the key
List availableTimes = entry.getValue(); // Access the value
for(String time: availableTimes){
try {
LocalTime time_ = LocalTime.parse(time, timeFormatter);
LocalDateTime dateTime = localDate.with(java.time.DayOfWeek.valueOf(day_)).atTime(time_);
log.info("Local Date Time: {}", dateTime);
gamesToSave.add(Games.builder().localDateTime(dateTime).isAvailable(true).venue(venue).build());
}catch(Exception ex){
log.error("Failed to create game for time slot = {} with exception = {}", time, ex.getLocalizedMessage());
}
}
}
}
}
// Save all games in batch after processing all venues and time slots
if (!gamesToSave.isEmpty()) {
gameRepository.saveAll(gamesToSave); // Assuming saveAll supports batch saving
}
}
So as per my understanding this implementation has ON^3 time complexity which I believe in software engineering is not a good practice. But on the second thought, this method is triggered on a schedule every midnight. So user does not directly interact with this method. However I just wanted to have some idea whether I should leave this implementation as it is right now or try to improve the time complexity of this implementation by possibly redesigning the database.
The game entity class currently looks like this,
public class Games implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private LocalDateTime localDateTime;
@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
@JoinTable(
name = "game_users",
joinColumns = @JoinColumn(name = "game_id"),
inverseJoinColumns = @JoinColumn(name = "user_id")
)
private List users;
@ManyToOne(fetch = FetchType.LAZY) // Many games can be associated with one venue
@JoinColumn(name = "venue_id", nullable = false) // Creates a foreign key column in the "games" table
private Venue venue;
private boolean isAvailable;
}
Please let me know if I have been clear in my questioning. To summarize I just want to understand the best practices in the industry and possibly any suggestions on improving my current implementations.