-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(study-rooms): serve slots data #75
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, the study room slots start
and end
times being displayed like UTC time while being in PST/PDT could be confusing.
We've resolved to use true UTC time instead 👌
To be precise, I'm going to specify the correct UTC offset in the response. |
Demoting to draft; I've just remembered Postgres supports JSON aggregation and benchmarking should be done to determine whether it is a better (faster) approach. |
previously always null
a9f84cc
to
b0f918b
Compare
Some benchmarking:
Given the following conditions:
We currently used a materialized view for this PR. Promoting out of draft status now that this analysis is complete. |
Wow mindblowing work on this, will dig in to test 😎 👌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! A few format errors but other than that it's good to go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another quick nitpick
packages/db/migrations/0008_study-room-slots-materialized-view.sql
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
## Description Followup to #75, fixing study room slot times being rendered in Postgres's local timezone. We simply set the timezone on the connection acquired by the scraper to `America/Los_Angeles`. ## Related Issue Resolves #84. We both specify the intended behavior from #75 in the example and actually fulfill it. ## Motivation and Context ## How Has This Been Tested? Tested by setting Postgres's timezone to `America/New_York`, running the scraper, then testing the API request. ## Screenshots (if appropriate): Despite forcing Postgres's global timezone to change, the timezone is correct since we set it on the session which takes precedence over the global setting: ![Screenshot_20250115_110206](https://github.com/user-attachments/assets/97c1badd-5c8a-44af-9b1c-8daddf03421e) We know this is effective because setting a different timezone for the scraper's SQL session uses that timezone instead: ![Screenshot_20250115_110404](https://github.com/user-attachments/assets/371a8cda-3751-461b-b2b0-69092e441b55) So if we force `America/Los_Angeles` on the scraper session, it will give the correct offset regardless of Postgres or system timezone. ## Types of changes - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Checklist: - [ ] My code involves a change to the database schema. - [ ] My code requires a change to the documentation.
Description
Adds study room slots and availability to study room endpoint.
As previously implemented in the data pipeline, availability is available in on the days between the day of the current time in UCI's timezone (
America/Los_Angeles
) and exactly 3 days later, inclusive. Data is updated every 2 minutes.This PR simply exposes that data. We use ISO 8601 dates
(most precisely,. We ask Postgres to interpret thez.string().datetime({ local: true })
) which are given with theZ
indicating UTC but should be interpreted as being in UCI's timezoneTIMESTAMP NO TIMEZONE
inAmerica/Los_Angeles
and format as zoned ISO 8601, avoiding adding a JS timezone library.Note: The
slots
field on returned study rooms is now guaranteed to exist. This is not a breaking change.We use a materialized view to precompute the JSON structure of the response. The refreshing of this view is relatively light and is done as part of the study room and slot scraping process every 2 minutes. However, it is not completely trivial; see below demonstrating that it produces a significant speed improvement per request which will accrue over time. This design decision is a database schema change. Since we have this JSON structure beforehand, we need only
SELECT
with conditions when serving a response.Related Issue
Feature update as requested in #46.
Also closes the inconsistency raised in #74 since study room data was one of the offenders and is within the jurisdiction of this PR.It doesn't.Motivation and Context
mfw
How Has This Been Tested?
Tested with Postman on a local deployment.
Screenshots (if appropriate):
Old screenshots (before timezone correction):
REST is functional:
![Screenshot_20250111_192159](https://private-user-images.githubusercontent.com/37320033/402313612-64d72053-79a4-4c39-93b6-5903e0a80e49.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTYyNTUsIm5iZiI6MTczOTAxNTk1NSwicGF0aCI6Ii8zNzMyMDAzMy80MDIzMTM2MTItNjRkNzIwNTMtNzlhNC00YzM5LTkzYjYtNTkwM2UwYTgwZTQ5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDExNTkxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFhOWU5YjU1NmExYjJhYzE4NGZlMWIwYjhlNmUxMzE4YmQyNzY5M2Q4ZjJjZTM0Mjc5Y2I1NmY5NjNlNTgzNTYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.ky1MDIt-xpsUXbcxyB1lNus3h-TfnHP_UBlK8glvHMc)
GraphQL is functional:
![Screenshot_20250111_192242](https://private-user-images.githubusercontent.com/37320033/402313639-576fa5d9-f2cf-4dc1-ab3d-afd638568ca7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkwMTYyNTUsIm5iZiI6MTczOTAxNTk1NSwicGF0aCI6Ii8zNzMyMDAzMy80MDIzMTM2MzktNTc2ZmE1ZDktZjJjZi00ZGMxLWFiM2QtYWZkNjM4NTY4Y2E3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDglMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA4VDExNTkxNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdkYzJhNzgyM2Y4MjFmYzI4ZmZlMjFlNWRlNTVkNGIwMWI0ZWNkZjM1MjZiMjUyZTExM2I5NWE1ZTk4NzdiYTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.y7jxb2JtV6Pr_sDpB7xLlSxt156dB-ap4nCWWHZJj9A)
New screenshots (latest):
Types of changes
Checklist: