From 7f677a985faa6e2be622a108adb60fdb42ecdae1 Mon Sep 17 00:00:00 2001 From: William Mikal Ruud Schmidt Date: Tue, 17 Nov 2026 21:33:57 +0100 Subject: [PATCH] Fixed ESLint issues Full X-Wines (100 646 wines, 21 013 536 ratings) is loaded on the VM. The README and vm.md describe the import and show the VM's timings, and the scaling task is ticked. Also fixes the ESLint error in AuthForm (one ref per input) and skips the generated coverage folder, so npm run check passes. --- README.md | 53 ++++++++-------- docs/tasks.md | 2 +- docs/vm.md | 60 ++++++++++++++----- frontend/eslint.config.js | 2 +- .../src/features/auth/components/AuthForm.tsx | 13 ++-- 5 files changed, 83 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 69cb764..972db5e 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ yet, depending on when the review is made. | «Mine anmeldelser» page | Done | Shows the «Vil prøve» list. Own reviews come with login in the interface | | User accounts | Done | Register, log in and log out at `/konto`, with sessions in PostgreSQL and an `httpOnly` cookie | | Reviews tied to accounts | Done | Writing a review requires login, and the username is shown as the author. Older anonymous reviews are kept as «Anonym student» | -| Larger dataset on the VM | Done | Slim version: 1 007 wines and 150 000 ratings | +| Larger dataset on the VM | Done | Full version: 100 646 wines and 21 013 536 ratings | | Continuous integration (CI) | Not yet started | Needs a self-hosted runner | ### What we want feedback on @@ -161,44 +161,47 @@ We use the [X-Wines](https://github.com/rogerioxavier/X-Wines) dataset. It is re | Version | Wines | Ratings | Used for | |---|---|---|---| | Test | 100 | 1 000 | Local development and automated tests | -| Slim | 1 007 | 150 000 | The VM | -| Full | 100 646 | 21 013 536 | Load test locally, see the numbers below | +| Slim | 1 007 | 150 000 | The VM until 17 November 2026 | +| Full | 100 646 | 21 013 536 | The VM, and the load test below | -Local development uses the Test version. The VM uses the Slim version, because it gives -enough wines to make search, filters and pagination meaningful, and it imports in a few seconds. -The Slim files are not in the repository. Download them from -[Kaggle](https://www.kaggle.com/datasets/rogerioxavier/x-wines-slim-version) and see the -[VM guide](docs/vm.md) for how to load them. +Local development uses the Test version. The VM uses the Full version, so anyone testing the site +can see that search, filters and pagination stay fast with 100 000 wines and 21 million ratings. +The Full files are not in the repository. The [VM guide](docs/vm.md) explains where to download +them and how to load them. ### Load test with the Full dataset -We loaded the Full version locally to show that the solution scales. Search, filtering, sorting and -pagination run in PostgreSQL with indexes (a trigram index for text search and B-tree and GIN indexes -for sorting and filters), and the average and count are stored on the wine, so no query ever counts -21 million rows. The frontend never loads more than one page of results. +We loaded the Full version locally and on the VM to show that the solution scales. Search, filtering, +sorting and pagination run in PostgreSQL with indexes (a trigram index for text search and B-tree and +GIN indexes for sorting and filters), and the average and count are stored on the wine, so no query +ever counts 21 million rows. The frontend never loads more than one page of results. -Measured on 16 November 2026, on a MacBook Air M4 with PostgreSQL 17: +Measured locally on 16 November 2026, on a MacBook Air M4 with PostgreSQL 17, and on the VM on +17 November 2026, on one core of an AMD EPYC 7742 with PostgreSQL 18: -| Step | Rows | Time | +| Step | Rows | Local | VM | +|---|---|---|---| +| Import of wines | 100 646 | 4.8 s | 14.1 s | +| Import of ratings | 21 013 536 | 228.8 s | 443.0 s | +| Recalculating every average | 100 646 wines | 15.3 s | 13.4 s | + +| Request | Local | VM | |---|---|---| -| Import of wines | 100 646 | 4.8 s | -| Import of ratings | 21 013 536 | 228.8 s | -| Recalculating every average | 100 646 wines | 15.3 s | +| First page, sorted by rating | 55 ms | 12 ms | +| Search for "pinot noir" | 49 ms | 32 ms | +| Red wine from Italy, rating 4+, sorted by name | 23 ms | 15 ms | +| Counts for every filter group | 57 ms | 344 ms | -| Request | Time | -|---|---| -| First page, sorted by rating | 55 ms | -| Search for "pinot noir" | 49 ms | -| Red wine from Italy, rating 4+, sorted by name | 23 ms | -| Counts for every filter group | 57 ms | +On the VM, each request was sent with `curl` through Apache, and the table shows the median of three +runs after one warm-up. The filter counts go through every wine that matches, and the VM has only one +CPU core, so that request is the slowest there. The database is 2.4 GB in total: 2.2 GB of ratings and 156 MB of wines. +After the import, the VM has 2.7 GB of disk left. The ratings file is 1 GB, which is larger as one string than Node allows, so the import reads it line by line and writes it in batches of 5 000. That keeps the memory use flat, whichever version is loaded. -The VM uses the Slim version, because the Full dataset needs more disk than the VM has to spare. - This is subject to change as needed. Citation: de Azambuja, R.X.; Morais, A.J.; Filipe, V. X-Wines: A Wine Dataset for Recommender Systems and Machine Learning. *Big Data Cogn. Comput.* 2023, 7, 20. https://doi.org/10.3390/bdcc7010020 diff --git a/docs/tasks.md b/docs/tasks.md index 6c8798c..8776f53 100644 --- a/docs/tasks.md +++ b/docs/tasks.md @@ -24,7 +24,7 @@ Apollo Server and PostgreSQL. - [x] Keep pagination consistent with search and filters. - [x] Sort the complete result set by rating, name and alcohol percentage. - [x] Perform search, filtering, sorting and pagination in the backend/database. -- [ ] Test with the Full dataset (100 000 wines, 21 million ratings) to show that it scales. +- [x] Test with the Full dataset (100 000 wines, 21 million ratings) to show that it scales. ## Reviews and usability diff --git a/docs/vm.md b/docs/vm.md index ce7b4c4..36e88b3 100644 --- a/docs/vm.md +++ b/docs/vm.md @@ -241,32 +241,64 @@ ProxyPassReverse "/project2/graphql" "http://127.0.0.1:3001/graphql" 3. Install the backend dependencies and start it using the `nohup` instructions above. 4. Check the backend log, API response, and application in the browser. -## Load the Slim dataset +## Load the Full dataset -The VM uses the Slim version of X-Wines (1 007 wines, 150 000 ratings). -The files are not in the repository. +The VM uses the Full version of X-Wines (100 646 wines, 21 013 536 ratings), loaded on 17 November 2026. +The files are not in the repository. The X-Wines authors share them in a +[Google Drive folder](https://drive.google.com/drive/folders/1LqguJNV-aKh1PuWMVx5ELA61LPfGfuu_), +linked from the [X-Wines repository](https://github.com/rogerioxavier/X-Wines). The two files are in +its `last` folder: `XWines_Full_100K_wines.csv` (36 MB) and `XWines_Full_21M_ratings.csv` (1.1 GB). -1. Download the Slim version from - [Kaggle](https://www.kaggle.com/datasets/rogerioxavier/x-wines-slim-version) and unzip it. -2. Copy the two CSV files to the VM. Run this on your own computer: +The database grows to about 2.4 GB. Check that `df -h /` shows at least 4 GB free before you start. + +1. Back up the database first. The VM has no backup, and student reviews and user accounts cannot be downloaded again: ```bash - ssh @it2810-18.idi.ntnu.no 'mkdir -p ~/xwines-slim' - scp XWines_Slim_1K_wines.csv XWines_Slim_150K_ratings.csv @it2810-18.idi.ntnu.no:~/xwines-slim/ + sudo -u postgres pg_dump -Fc vinmonopolet > ~/vinmonopolet-$(date +%F).dump ``` -3. Import them on the VM: +2. Download the files on the VM into `/tmp`. `/tmp` is kept in memory, so the files do not use disk space, + and it is emptied when the VM restarts: + + ```bash + mkdir -p /tmp/xwines-full && cd /tmp/xwines-full + curl -fL -o XWines_Full_100K_wines.csv 'https://drive.usercontent.google.com/download?id=1uEEipmKNxdiKUAhjH-K14JOSQ2BLRFss&export=download&confirm=t' + curl -fL -o XWines_Full_21M_ratings.csv 'https://drive.usercontent.google.com/download?id=15mwSBmGv-FY3-gJzL0wd1grav6CpYw8j&export=download&confirm=t' + wc -l XWines_Full_21M_ratings.csv + ``` + + The ratings file has 21 013 537 lines, including the header. + +3. Import them with `nohup`, so the import continues if SSH disconnects. It takes about 8 minutes: ```bash cd ~/ntnuhome/T18-Project-2/backend - npx tsx src/scripts/seed-xwines.ts ~/xwines-slim/XWines_Slim_1K_wines.csv ~/xwines-slim/XWines_Slim_150K_ratings.csv + mkdir -p logs + nohup npx tsx src/scripts/seed-xwines.ts /tmp/xwines-full/XWines_Full_100K_wines.csv /tmp/xwines-full/XWines_Full_21M_ratings.csv >> logs/seed-full.log 2>&1 < /dev/null & + tail -f logs/seed-full.log + ``` + + The log reports progress every 500 000 ratings and ends with `Updated average ratings`. + Until then, the site shows old or missing averages. + +4. Update the query statistics, then delete the files: + + ```bash + psql -h localhost -U vinmonopolet_app -d vinmonopolet -c 'VACUUM (ANALYZE) wine' -c 'VACUUM (ANALYZE) community_rating' + rm -rf /tmp/xwines-full ``` -The same script loads the Full version (100 646 wines, 21 million ratings), but that needs about -2.4 GB of database and more disk than the VM has to spare, so we only use Full locally. +The import is safe to run more than once. Existing wines are updated and existing ratings are skipped. +Student reviews and user accounts are not touched. The backend does not need a restart. -The import is safe to run more than once. The Test wines are part of Slim, so they are updated, not duplicated. -The backend does not need a restart. +To load the Slim version instead, use the same script with the Slim files from +[Kaggle](https://www.kaggle.com/datasets/rogerioxavier/x-wines-slim-version). Slim does not remove +Full wines that are already in the database. To go back to Slim, restore a backup taken before the +Full import. Reviews and accounts created after the backup are lost: + +```bash +sudo -u postgres pg_restore --clean --if-exists -d vinmonopolet ~/vinmonopolet-.dump +``` ## Command reference diff --git a/frontend/eslint.config.js b/frontend/eslint.config.js index 8d061c7..de58e29 100644 --- a/frontend/eslint.config.js +++ b/frontend/eslint.config.js @@ -7,7 +7,7 @@ import { defineConfig, globalIgnores } from 'eslint/config'; import prettier from 'eslint-config-prettier'; export default defineConfig([ - globalIgnores(['dist']), + globalIgnores(['dist', 'coverage']), { files: ['**/*.{ts,tsx}'], extends: [ diff --git a/frontend/src/features/auth/components/AuthForm.tsx b/frontend/src/features/auth/components/AuthForm.tsx index 0958fc3..44b50cb 100644 --- a/frontend/src/features/auth/components/AuthForm.tsx +++ b/frontend/src/features/auth/components/AuthForm.tsx @@ -37,15 +37,16 @@ export function AuthForm({ mode, onSubmit }: AuthFormProps) { const [formError, setFormError] = useState(''); const [working, setWorking] = useState(false); const id = useId(); - const inputs = { - username: useRef(null), - password: useRef(null), - }; + // Separate refs, not an object of refs: React's lint rules treat `ref={inputs.password}` in + // the JSX as reading a ref during render. + const usernameInput = useRef(null); + const passwordInput = useRef(null); const isRegister = mode === 'register'; /** Shows the messages and moves focus to the first field that has one. */ function showFieldErrors(errors: FieldErrors) { setFieldErrors(errors); + const inputs = { username: usernameInput, password: passwordInput }; const first = FIELDS.find((field) => errors[field]); if (first) inputs[first].current?.focus(); } @@ -102,7 +103,7 @@ export function AuthForm({ mode, onSubmit }: AuthFormProps) {

)} )}