Skip to content

Commit 0924da8

Browse files
committed
feat: bundle Hoagie requirements data locally and serve at page load
1 parent 97787ca commit 0924da8

126 files changed

Lines changed: 22345 additions & 22 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frontend/src/components/App.jsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ export default function App() {
7070
);
7171

7272
useEffect(() => {
73-
fetchProfile();
74-
fetchRequirements();
75-
}, [fetchProfile, fetchRequirements]);
73+
fetchProfile();
74+
if (window.__TIGERPATH_PRELOADED_REQUIREMENTS__) {
75+
handleRequirementData(window.__TIGERPATH_PRELOADED_REQUIREMENTS__);
76+
} else {
77+
fetchRequirements();
78+
}
79+
}, [fetchProfile, fetchRequirements, handleRequirementData]);
7680

7781
const prevScheduleRef = React.useRef(null);
7882
useEffect(() => {

tigerpath/majors_and_certificates/scripts/verifier.py

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,15 @@
1111

1212
# Allow overriding the data repo base via env var for easy testing
1313
# Must end with a trailing slash and point to a raw.githubusercontent.com base
14-
REMOTE_DATA_REPO_URL = os.getenv(
15-
"DEPT_DATA_URL",
16-
"https://raw.githubusercontent.com/TigerAppsOrg/Princeton-Departmental-Data/old/",
17-
)
18-
19-
# connect/read timeouts so requests never hang workers indefinitely
20-
_HTTP_TIMEOUT = (3.05, 7)
14+
import pathlib
2115

16+
_LOCAL_DATA_DIR = pathlib.Path(__file__).resolve().parent.parent.parent / "requirements_data"
2217

2318
@lru_cache(maxsize=256)
24-
def _fetch_remote_yaml(path: str):
25-
"""
26-
Fetch and parse YAML from the remote requirements repository with a timeout.
27-
28-
Results are cached in-process to avoid repeated network requests on hot paths.
29-
"""
30-
resp = requests.get(REMOTE_DATA_REPO_URL + path, timeout=_HTTP_TIMEOUT)
31-
resp.raise_for_status()
32-
return yaml.safe_load(resp.text)
19+
def _load_yaml(path: str):
20+
"""Load and parse YAML from the local requirements data directory."""
21+
filepath = _LOCAL_DATA_DIR / path
22+
return yaml.safe_load(filepath.read_text())
3323

3424

3525
MAJORS_LOCATION = "majors/" # relative path to folder containing the major requirements JSONs
@@ -149,7 +139,7 @@ def check_requirements(req_file, courses, year):
149139
:returns: A simplified json with info about how much of each requirement is satisfied
150140
:rtype: (bool, dict, dict)
151141
"""
152-
req = _fetch_remote_yaml(req_file)
142+
req = _load_yaml(req_file)
153143
courses = _init_courses(courses, req, year)
154144
req = _init_req(req, year)
155145
_mark_possible_reqs(req, courses)
@@ -205,7 +195,7 @@ def get_courses_by_path(path):
205195
req_filepath = os.path.join(DEGREES_LOCATION, filename)
206196
else:
207197
raise ValueError("Path malformatted.")
208-
req = _fetch_remote_yaml(req_filepath)
198+
req = _load_yaml(req_filepath)
209199
_init_year_switch(req, year)
210200
subreq = _get_req_by_path(req, path, year)
211201
if not subreq:

0 commit comments

Comments
 (0)