https://github.com/shin4488/n-1-problem-solution
https://github.com/shin4488/n-1-problem-solution
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/shin4488/n-1-problem-solution
- Owner: shin4488
- Created: 2025-03-29T15:40:13.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-03-29T18:21:00.000Z (9 months ago)
- Last Synced: 2025-03-29T18:28:02.655Z (9 months ago)
- Language: Ruby
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# README
This README would normally document whatever steps are necessary to get the
application up and running.
Things you may want to cover:
* Ruby version
* System dependencies
* Configuration
* Database creation
* Database initialization
* How to run the test suite
* Services (job queues, cache servers, search engines, etc.)
* Deployment instructions
* ...
# note
docker compose build
docker compose run app rails new . --force --database=postgresql --skip-javascript
docker compose up -d app
docker compose exec app rails db:create
docker compose exec app rails db:migrate
docker compose exec app rails console
## Compare eager_load and preload
To see the SQL queries generated by `preload` and `eager_load` and measure
their execution time, run the following commands:
```bash
# run with a small dataset
bin/rails runner script/compare_load_methods.rb small
# run with a larger dataset
bin/rails runner script/compare_load_methods.rb large
```
The script sets up data using `DevDataStore`. For the small dataset, it
creates a handful of sample teams and players. For the large dataset it
generates **10,000 teams with 10,000 players each**, so be prepared for a long
runtime. Querying logic is provided by `Player.get_players_by_preload`,
`Player.get_players_by_eagerload`, `MlbTeam.get_teams_by_preload`, and
`MlbTeam.get_teams_by_eagerload`.