{"action":"created","issue":{"url":"https://api.github.com/repos/rubygems/rubygems.org/issues/1154","labels_url":"https://api.github.com/repos/rubygems/rubygems.org/issues/1154/labels{/name}","comments_url":"https://api.github.com/repos/rubygems/rubygems.org/issues/1154/comments","events_url":"https://api.github.com/repos/rubygems/rubygems.org/issues/1154/events","html_url":"https://github.com/rubygems/rubygems.org/pull/1154","id":123934500,"number":1154,"title":"Add runtime/dev dependencies counts to Version","user":{"login":"olivierlacan","id":65950,"avatar_url":"https://avatars.githubusercontent.com/u/65950?v=3","gravatar_id":"","url":"https://api.github.com/users/olivierlacan","html_url":"https://github.com/olivierlacan","followers_url":"https://api.github.com/users/olivierlacan/followers","following_url":"https://api.github.com/users/olivierlacan/following{/other_user}","gists_url":"https://api.github.com/users/olivierlacan/gists{/gist_id}","starred_url":"https://api.github.com/users/olivierlacan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olivierlacan/subscriptions","organizations_url":"https://api.github.com/users/olivierlacan/orgs","repos_url":"https://api.github.com/users/olivierlacan/repos","events_url":"https://api.github.com/users/olivierlacan/events{/privacy}","received_events_url":"https://api.github.com/users/olivierlacan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-12-26T15:20:58Z","updated_at":"2016-01-01T17:16:41Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/rubygems/rubygems.org/pulls/1154","html_url":"https://github.com/rubygems/rubygems.org/pull/1154","diff_url":"https://github.com/rubygems/rubygems.org/pull/1154.diff","patch_url":"https://github.com/rubygems/rubygems.org/pull/1154.patch"},"body":"Addresses #1115\r\n\r\nExample gem show page: /gems/astrolabe\r\n![image](https://cloud.githubusercontent.com/assets/65950/12006947/ac40c392-abed-11e5-84fb-77fee6d47e5a.png)\r\n\r\nExample return from `/api/v1/versions/actionmailer.json`\r\n\r\n```json\r\n[\r\n  {\r\n    \"authors\": \"David Heinemeier Hansson\",\r\n    \"built_at\": \"2015-11-12T00:00:00.000Z\",\r\n    \"created_at\": \"2015-12-26T13:38:45.153Z\",\r\n    \"description\": \"Email on Rails. Compose, deliver, receive, and test emails using the familiar controller/view pattern. First-class support for multipart email and attachments.\",\r\n    \"downloads_count\": 0,\r\n    \"metadata\": {},\r\n    \"number\": \"4.2.5\",\r\n    \"summary\": \"Email composition, delivery, and receiving framework (part of Rails).\",\r\n    \"platform\": \"ruby\",\r\n    \"ruby_version\": \">= 1.9.3\",\r\n    \"prerelease\": false,\r\n    \"licenses\": [\r\n      \"MIT\"\r\n    ],\r\n    \"requirements\": [\r\n      \"none\"\r\n    ],\r\n    \"sha\": \"60f8b5c8ba4ea98a08469626e0ecd4fbc41b2393df888da8f3afe4c034edffcc\",\r\n    \"runtime_dependencies_count\": 5,\r\n    \"development_dependencies_count\": 0\r\n  }\r\n]\r\n```\r\n\r\nFor now I'm dynamically calling `count` on the two scopes of the dependencies association on Version.\r\n\r\nThis generates the following extra query:\r\n\r\n```sql\r\nSELECT COUNT(DISTINCT \"dependencies\".\"id\") FROM \"dependencies\" LEFT OUTER JOIN \"rubygems\" ON \"rubygems\".\"id\" = \"dependencies\".\"rubygem_id\" WHERE \"dependencies\".\"version_id\" = $1 AND \"dependencies\".\"scope\" = $2  [[\"version_id\", 125], [\"scope\", \"runtime\"]]\r\n```\r\n\r\nOne is triggered per dependencies scope (runtime, development) and none if the gem's version has neither runtime nor development dependencies.\r\n\r\nI'm not sure the cost of that query is worth the added latency so it would probably be a good idea to calculate these counts when a version is created and just use a counter cache column on the version\r\ntable or in Redis. That's assuming we're okay adding two new columns (or Redis keys): `runtime_dependencies_count` and `development_dependencies_count` to the `versions` table. \r\n\r\nLet me know if the above is palatable and what the preferred way to hook in to the version creation lifecycle is: ActiveRecord callbacks, Redis, or something fancier?\r\n\r\n/cc @dwradcliffe "},"comment":{"url":"https://api.github.com/repos/rubygems/rubygems.org/issues/comments/168317649","html_url":"https://github.com/rubygems/rubygems.org/pull/1154#issuecomment-168317649","issue_url":"https://api.github.com/repos/rubygems/rubygems.org/issues/1154","id":168317649,"user":{"login":"balasankarc","id":2379271,"avatar_url":"https://avatars.githubusercontent.com/u/2379271?v=3","gravatar_id":"","url":"https://api.github.com/users/balasankarc","html_url":"https://github.com/balasankarc","followers_url":"https://api.github.com/users/balasankarc/followers","following_url":"https://api.github.com/users/balasankarc/following{/other_user}","gists_url":"https://api.github.com/users/balasankarc/gists{/gist_id}","starred_url":"https://api.github.com/users/balasankarc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/balasankarc/subscriptions","organizations_url":"https://api.github.com/users/balasankarc/orgs","repos_url":"https://api.github.com/users/balasankarc/repos","events_url":"https://api.github.com/users/balasankarc/events{/privacy}","received_events_url":"https://api.github.com/users/balasankarc/received_events","type":"User","site_admin":false},"created_at":"2016-01-01T17:16:40Z","updated_at":"2016-01-01T17:16:40Z","body":"@olivierlacan Is there any way you can solve my issue #1157 also along with this? Instead of the counts, can we have the actual dependencies and their versions required in the /versions API call? Finding count is only a matter of calculating the length of the arrays, right?"}}