{"id":16071487,"url":"https://github.com/backpackerhh/rottenpotatoes-indices-performance","last_synced_at":"2026-05-16T15:01:13.507Z","repository":{"id":18743225,"uuid":"21955069","full_name":"backpackerhh/rottenpotatoes-indices-performance","owner":"backpackerhh","description":"CS169.2x Engineering Software as a Service - Performance Homework","archived":false,"fork":false,"pushed_at":"2014-07-17T19:48:43.000Z","size":160,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-26T07:17:29.536Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/backpackerhh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-17T19:40:22.000Z","updated_at":"2014-07-17T19:40:33.000Z","dependencies_parsed_at":"2022-08-20T18:00:40.943Z","dependency_job_id":null,"html_url":"https://github.com/backpackerhh/rottenpotatoes-indices-performance","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/backpackerhh/rottenpotatoes-indices-performance","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backpackerhh%2Frottenpotatoes-indices-performance","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backpackerhh%2Frottenpotatoes-indices-performance/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backpackerhh%2Frottenpotatoes-indices-performance/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backpackerhh%2Frottenpotatoes-indices-performance/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/backpackerhh","download_url":"https://codeload.github.com/backpackerhh/rottenpotatoes-indices-performance/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/backpackerhh%2Frottenpotatoes-indices-performance/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33107564,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-16T04:41:52.686Z","status":"ssl_error","status_checked_at":"2026-05-16T04:41:52.009Z","response_time":115,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T07:40:45.970Z","updated_at":"2026-05-16T15:01:13.489Z","avatar_url":"https://github.com/backpackerhh.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Overview\n=======\n\nYou have been assigned to improve the database performance of a new version of the Rotten Potatoes site.\n\nSetup:\n----\n\nClone this repository and cd inside it\n\nNow run:\n\n```\nbundle install --without production\nrake db:create\nrake db:migrate\n```\n\nand\n\n```\nrake db:seed\n``` \n\nThe seed command may take a while as it generates roughly 5000 database entries. If the seed command is taking too long, consider lowering the amount of data that it creates by changing the following lines of db/seeds.rb:\n\nmovie_count=250  \nreview_count=20  \n\nThis version of the app has some changes:\n\nReview and Moviegoer models have been added.\nTake a look at the model files in /app/models/ to get a better understanding of the relationship between the models. Note that:\n\n* Movie has many Reviews.\n* Movie has many Moviegoers through Reviews.\n* Moviegoer has many Reviews.\n* Moviegoer has many Movies through Reviews.\n\nNew features for users in various stages of completion:\nImplemented:\n\n* A user can now view the average score for a film. Handled by Moviescontroller#score\n* A user can now view all films reviewed by the reviewers of a given film. Handled by Moviescontroller#viewed_with\n\nPlanned:\n* A user should be able to see all of a Moviegoer's Reviews\n* \nThis will involve a query that looks like moviegoer.reviews\nUnfortunately, the way that the prototype database is set up will prevent these great new features from scaling very well. As the number of Reviews grows, the performance will drop significantly.\n\nTo help you document the performance of the queries the designer has added a benchmarking action that will provide a very rough estimate of query performance. You can get an approximate idea of how long some sample queries take for a small data set by starting up the server and then visiting:\n\nhttp://localhost:3000/benchmark/movies\n\nor\n\nhttp://localhost:3000/benchmark/moviegoers\n\nTake a look at the code in app/controller/movies_controller.rb to see how the preceding commands work. There are a few things to take note of:\n\nThese times are approximations, there is significant overhead caused by loading ActiveRecord objects, so the time spent executing queries is not the same as the time displayed on the page.\nThe database may not contain enough movies for these to show significant improvements after you apply migrations to improve the query performance.\n\nIf you wish to see the time spent running database queries, look at the terminal running the rails server and look for a line that looks like:\nCompleted 200 OK in 423ms \n(Views: 8.0ms | ActiveRecord: 200.0ms)\n\nThe time after ActiveRecord is a better approximation of the actual query time.\nA more qualitative method to evaluate performance is to look at what your database's query planner will use to execute the queries. If you are running the virtual machine you can do this by running commands:\n\n```\ncd db\nsqlite3 development.sqlite3\n```\n\nyou should see a prompt that looks like:\n\nsqlite\u003e\nIf you want to see the plan that sqlite3 expects to use, along with its estimation of the number of rows that it will look through, run:\n\nEXPLAIN QUERY PLAN \u003cquery\u003e;\nwith \u003cquery\u003e replaced by the query you want to investigate. The score action uses\n\n@movie.reviews\nthis gets translated to the query:\n\nSELECT \"reviews\".* FROM \"reviews\" WHERE \"reviews\".\"movie_id\" = 1;\nputting this all together you can see the estimated number of rows viewed by typing in:\n\nexplain query plan SELECT \"reviews\".* FROM \"reviews\" WHERE \"reviews\".\"movie_id\" = 1;\nYou will get a result that looks like:\n\nSCAN TABLE reviews (~# rows)\nThe number of rows is an approximation, but it is useful for comparing performance between different schema. The skeleton code performs a Table Scan to execute this query. This is one of the reasons that the current implementation will lose performance as the amount of Reviews grows.\n\n\nRequirements\n-----\n\n\nYour task is to add a migration, or migrations that will improve the performance by eliminate the use of table scans for the following two queries:\n\nmoviegoer.reviews\n\nand\n\nmovie.reviews\n\nNote: In the previous two queries, moviegoer and movie are instances of the Moviegoer and Movie models. Note: This should not require very much code, in fact adding 2 indices is enough to prevent table scans from occurring for these queries. \n\nTo easily create a migration run the following command:\n\n```\nrails generate migration migrationName\n```\n \nTo read more about migrations visit: http://guides.rubyonrails.org/migrations.html After you have added your migrations, make sure to run\n\n```\nrake db:migrate\n```\n\nto make sure they get applied to the database. Check your results either by using sqlite3, or the benchmark action to see if you are getting better results. If you use the benchmark action It may be necessary to add more Reviews to make this noticeable.You can modify db/seeds.rb to do so. A successful change should eliminate table scans for both of the queries.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbackpackerhh%2Frottenpotatoes-indices-performance","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbackpackerhh%2Frottenpotatoes-indices-performance","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbackpackerhh%2Frottenpotatoes-indices-performance/lists"}