Skip to content

Commit 6bd4062

Browse files
authored
fix(optimiser): read embedded venues.json instead of fetching (#4142)
1 parent 474a42e commit 6bd4062

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

website/api/optimiser/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
_constants/venues.json

website/api/optimiser/_client/client.go

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,18 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7+
"log"
78
"net/http"
89

9-
"github.com/nusmodifications/nusmods/website/api/optimiser/_constants"
10-
"github.com/nusmodifications/nusmods/website/api/optimiser/_models"
10+
constants "github.com/nusmodifications/nusmods/website/api/optimiser/_constants"
11+
models "github.com/nusmodifications/nusmods/website/api/optimiser/_models"
1112
)
1213

1314
func GetVenues() (map[string]models.Location, error) {
1415
venues := make(map[string]models.Location)
15-
url := constants.VenuesURL
16-
res, err := http.Get(url)
17-
if err != nil {
18-
return nil, err
19-
}
20-
defer res.Body.Close()
21-
22-
body, err := io.ReadAll(res.Body)
23-
if err != nil {
24-
return nil, err
25-
}
26-
err = json.Unmarshal(body, &venues)
16+
err := json.Unmarshal(constants.VenuesJson, &venues)
2717
if err != nil {
18+
log.Printf("unable to load venues.json: %v", err)
2819
return nil, err
2920
}
3021

website/api/optimiser/_constants/constants.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package constants
22

3+
import (
4+
_ "embed"
5+
)
6+
37
// Ensure in sync with all E-Venues in NUSMods
48
var E_Venues = map[string]bool{
59
"E-Learn_A": true,
@@ -28,7 +32,8 @@ var LessonTypeAbbrev = map[string]string{
2832
"WORKSHOP": "WS",
2933
}
3034

31-
var VenuesURL = "https://github.nusmods.com/venues"
35+
//go:embed venues.json
36+
var VenuesJson []byte
3237

3338
var ModulesURL = "https://api.nusmods.com/v2/%s/modules/%s.json"
3439

website/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
"scripts": {
66
"start": "cross-env NODE_ENV=development webpack serve --config webpack/webpack.config.dev.js",
77
"start:export": "cross-env NODE_ENV=development OPEN_BROWSER=0 webpack serve --config webpack/webpack.config.timetable-only.js --port 8081",
8-
"start:optimiser": "cd api/optimiser/_test && go run main.go",
9-
"build": "cross-env NODE_ENV=production node scripts/build",
8+
"start:optimiser": "yarn prepare:optimiser && cd api/optimiser/_test && go run main.go",
9+
"prepare:optimiser": "cp src/data/venues.json api/optimiser/_constants",
10+
"build": "yarn prepare:optimiser && cross-env NODE_ENV=production node scripts/build",
1011
"rsync": "rsync -avu dist/",
1112
"rsync:export": "rsync -avu --delete-after dist-timetable/",
1213
"promote-staging": "bash scripts/promote-staging.sh",

website/vercel.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
"api/**/*.ts": {
44
"excludeFiles": "./tsconfig.json",
55
"includeFiles": "{./api/tsconfig.json,./src/serverless/*.xml}"
6+
},
7+
"api/**/*.go": {
8+
"includeFiles": "./api/optimiser/_constants/venues.json"
69
}
710
},
811
"headers": [

0 commit comments

Comments
 (0)