feat:#22 refactor to cache room schedule and webworker config

This commit is contained in:
survellow
2024-08-02 23:55:58 +02:00
parent e4bde20397
commit 4fcfa76e1c
14 changed files with 164 additions and 83 deletions

View File

@@ -68,16 +68,11 @@ func GetRoomSchedule(app *pocketbase.PocketBase, room string, from string, to st
* @return room occupancy list
* @return error if the database query fails
*/
func GetRoomOccupancyList(app *pocketbase.PocketBase, from string, to string, granularity int) (model.RoomOccupancyList, error) {
// try parsing the time strings
fromTime, err := time.Parse(time.RFC3339, from)
if err != nil {
return model.RoomOccupancyList{}, err
}
toTime, err := time.Parse(time.RFC3339, to)
if err != nil {
return model.RoomOccupancyList{}, err
}
func GetRoomOccupancyList(app *pocketbase.PocketBase, granularity int) (model.RoomOccupancyList, error) {
now := time.Now()
fromTime := functions.GetSemesterStart(now)
toTime := functions.GetSemesterStart(now.AddDate(0, 6, 0))
// calculate the number of blocks for the given time range and granularity
timeDifference := toTime.Sub(fromTime)
@@ -142,6 +137,7 @@ func getRelevantRooms(app *pocketbase.PocketBase) ([]string, error) {
func emptyRoomOccupancyList(from time.Time, granularity int, blockCount int) model.RoomOccupancyList {
return model.RoomOccupancyList{
Start: from,
Updated: time.Now(),
Granularity: granularity,
Blocks: blockCount,
Rooms: []model.RoomOccupancy{},