Skip to content

Commit

Permalink
Merge pull request #78 from filips123/database-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
filips123 committed Aug 26, 2023
2 parents 3ab905d + d777fea commit f15b95d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion API/gimvicurnik/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def _sentry_profiler_sampler(context: dict[str, Any]) -> float | int | bool:
def configure_database(self) -> None:
"""Configure database session."""

self.engine = create_engine(self.config.database, pool_recycle=3600)
self.engine = create_engine(self.config.database, pool_size=10, pool_recycle=14400)
SessionFactory.configure(bind=self.engine)

def create_error_hooks(self) -> None:
Expand Down
11 changes: 7 additions & 4 deletions API/gimvicurnik/blueprints/calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def create_school_calendar(
# Create event and add internal properties
event = Event()
event.add("DTSTAMP", datetime.now())
event.add("CATEGORIES", ["NORMAL"])
event.add("COLOR", "green")
event.add("CATEGORIES", ["Lesson", "Normal"])
event.add("COLOR", "darkgreen")
event.add(
"UID",
sha256(
Expand All @@ -93,6 +93,7 @@ def create_school_calendar(

# Add basic lesson properties
event.add("SUMMARY", subject["subject"])
event.add("ATTENDEE", subject["class"])
event.add("ORGANIZER", subject["teacher"])
event.add("LOCATION", subject["classroom"])
event.add("DURATION", timedelta(minutes=45))
Expand Down Expand Up @@ -132,7 +133,7 @@ def create_school_calendar(
# Create event and add internal properties
event = Event()
event.add("DTSTAMP", datetime.now())
event.add("CATEGORIES", ["SUBSTITUTION"])
event.add("CATEGORIES", ["Lesson", "Substitution"])
event.add("COLOR", "darkred")
event.add(
"UID",
Expand All @@ -154,6 +155,7 @@ def create_school_calendar(
# Add basic substitution properties
event.add("SUMMARY", subject["subject"])
event.add("DESCRIPTION", subject["notes"] or "")
event.add("ATTENDEE", subject["class"])
event.add("ORGANIZER", subject["teacher"])
event.add("LOCATION", subject["classroom"])

Expand Down Expand Up @@ -212,7 +214,7 @@ def create_schedule_calendar(
# Create event and add internal properties
event = Event()
event.add("DTSTAMP", datetime.now())
event.add("CATEGORIES", ["LUNCH"])
event.add("CATEGORIES", ["Lunch"])
event.add("COLOR", "darkblue")
event.add(
"UID",
Expand All @@ -233,6 +235,7 @@ def create_schedule_calendar(
event.add("SUMMARY", "Kosilo")
event.add("DESCRIPTION", model.notes or "")
event.add("LOCATION", model.location or "")
event.add("ATTENDEE", classname)
event.add("DTSTART", start)
event.add("DTEND", end)

Expand Down
6 changes: 3 additions & 3 deletions API/gimvicurnik/database/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Entity:
__tablename__: str

id: Mapped[intpk]
name: Mapped[text]
name: Mapped[text] = mapped_column(unique=True, index=True)

@classmethod
def get_lessons(
Expand Down Expand Up @@ -237,10 +237,10 @@ class Substitution(Base):
subject: Mapped[text | None]
notes: Mapped[text | None]

original_teacher_id: Mapped[teacher_fk | None] = mapped_column()
original_teacher_id: Mapped[teacher_fk | None] = mapped_column(index=True)
original_teacher: Mapped[Teacher | None] = relationship(foreign_keys=[original_teacher_id])

original_classroom_id: Mapped[classroom_fk | None] = mapped_column()
original_classroom_id: Mapped[classroom_fk | None] = mapped_column(index=True)
original_classroom: Mapped[Classroom | None] = relationship(foreign_keys=[original_classroom_id])

class_id: Mapped[class_fk] = mapped_column(index=True)
Expand Down
1 change: 1 addition & 0 deletions API/gimvicurnik/updaters/timetable.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def _parse(self, document: Document | None, raw_data: str, new_hash: str, span:
"classroom_id": get_or_create(self.session, model=Classroom, name=lesson[4])[0].id if lesson[4] else None,
}
for _, lesson in lessons.items()
if lesson[1]
]
# fmt: on

Expand Down

0 comments on commit f15b95d

Please sign in to comment.