Skip to content

Commit

Permalink
fix(database): 🐛 remove storage of students in Unit class
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingPufferFish committed Oct 6, 2024
1 parent 6f01a0d commit d86a3db
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
9 changes: 8 additions & 1 deletion backend/src/main/java/org/acme/domain/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Transient;

import java.time.DayOfWeek;
import java.time.Duration;
Expand Down Expand Up @@ -45,10 +46,13 @@ public class Unit extends PanacheEntity {
public LocalTime startTime;

// TODO: change unit to be the owner, rather than the student being owner
@Transient
@JsonIgnoreProperties("units")
@ManyToMany(mappedBy = "units", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
public List<Student> students;

public int studentSize;

/*
* currently each unit only has 1 'slot' on the timetable, so it can only
* be associated with one room, but in the final product, we would most
Expand Down Expand Up @@ -90,6 +94,7 @@ public Unit(int unitID, String name, String course, Duration duration, List<Stud
this.course = course;
this.duration = duration;
this.students = students;
this.studentSize = this.students.size();
this.setStudentsUnits();
}

Expand All @@ -109,6 +114,7 @@ public Unit(int unitID, String name, String course, Duration duration, List<Stud
this.course = course;
this.duration = duration;
this.students = students;
this.studentSize = this.students.size();
this.wantsLab = wantsLab;
this.setStudentsUnits();
}
Expand All @@ -132,6 +138,7 @@ public Unit(int unitID, String name, String course, DayOfWeek dayOfWeek, LocalTi
this.startTime = startTime;
this.duration = duration;
this.students = students;
this.studentSize = this.students.size();
this.wantsLab = wantsLab;
this.room = room;
}
Expand Down Expand Up @@ -206,7 +213,7 @@ public void setStudentsUnits() {
* @return An int representing the number of students.
*/
public int getStudentSize() {
return students.size();
return this.studentSize;
}

public Room getRoom() {
Expand Down
55 changes: 49 additions & 6 deletions backend/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,58 @@ quarkus.datasource.jdbc.url = ${QUARKUS_DATASOURCE_JDBC_URL}
# drop and create the database at startup (use `update` to only update the schema)
quarkus.hibernate-orm.database.generation = create-drop

# datasource metrics
# transaction timeout
quarkus.transaction-manager.default-transaction-timeout=320s

# set batch size to optimise db transactions
quarkus.hibernate-orm.jdbc.batch_size=100

# Agoral pooling config
quarkus.datasource.jdbc.max-size=20
quarkus.datasource.jdbc.min-size=5
quarkus.datasource.jdbc.initial-size=10
quarkus.datasource.jdbc.idle-removal-interval=5M
quarkus.datasource.jdbc.max-lifetime=30M


# -------------------------------------------
# Debuggers
# -------------------------------------------

# debugger for large/complex db transactions
quarkus.log.category."com.arjuna".level=DEBUG

# TimeFold solver debuggers
quarkus.log.category."ai.tim.sol.cor.imp.sol".level=DEBUG
quarkus.log.category."ai.tim.sol.cor.imp.con".level=DEBUG

# -------------------------------------------
# Loggers
# -------------------------------------------

# log datasource metrics
quarkus.datasource.metrics.enabled=true
quarkus.datasource.jdbc.enable-metrics=true

# datasource log leak
# log datasource leak
quarkus.datasource.jdbc.log-leak-detection=true

# transaction timeout
quarkus.transaction-manager.default-transaction-timeout=320s
# log transactions
quarkus.log.category."org.hibernate.engine.transaction.internal.TransactionImpl".level=DEBUG
quarkus.log.category."org.hibernate.engine.transaction.spi.AbstractTransactionImpl".level=DEBUG
quarkus.log.category."org.hibernate.resource.jdbc.internal.LogicalConnectionImpl".level=DEBUG
quarkus.log.category."org.hibernate.SQL".level=DEBUG
quarkus.log.category."org.jboss.logging".level=DEBUG
quarkus.hibernate-orm.statistics=true
quarkus.hibernate-orm.log-session-metrics=true
quarkus.hibernate-orm.metrics.enabled=true

# debugger for large/complex db transactions
quarkus.log.category."com.arjuna".level=DEBUG
# log sql commands
# quarkus.hibernate-orm.log.sql=true
# quarkus.hibernate-orm.format-sql=true

# enable logfile
quarkus.log.file.enable=true
quarkus.log.file.path=logs/quarkus.log
quarkus.log.file.rotation.max-file-size=10M
quarkus.log.file.rotation.max-backup-index=10

0 comments on commit d86a3db

Please sign in to comment.