{"action":"created","issue":{"url":"https://api.github.com/repos/holidayextras/jsonapi-server/issues/63","labels_url":"https://api.github.com/repos/holidayextras/jsonapi-server/issues/63/labels{/name}","comments_url":"https://api.github.com/repos/holidayextras/jsonapi-server/issues/63/comments","events_url":"https://api.github.com/repos/holidayextras/jsonapi-server/issues/63/events","html_url":"https://github.com/holidayextras/jsonapi-server/pull/63","id":120626526,"number":63,"title":"More Efficient Inclusions","user":{"login":"hxoliverrumbelow","id":3088374,"avatar_url":"https://avatars.githubusercontent.com/u/3088374?v=3","gravatar_id":"","url":"https://api.github.com/users/hxoliverrumbelow","html_url":"https://github.com/hxoliverrumbelow","followers_url":"https://api.github.com/users/hxoliverrumbelow/followers","following_url":"https://api.github.com/users/hxoliverrumbelow/following{/other_user}","gists_url":"https://api.github.com/users/hxoliverrumbelow/gists{/gist_id}","starred_url":"https://api.github.com/users/hxoliverrumbelow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hxoliverrumbelow/subscriptions","organizations_url":"https://api.github.com/users/hxoliverrumbelow/orgs","repos_url":"https://api.github.com/users/hxoliverrumbelow/repos","events_url":"https://api.github.com/users/hxoliverrumbelow/events{/privacy}","received_events_url":"https://api.github.com/users/hxoliverrumbelow/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-12-06T11:04:40Z","updated_at":"2015-12-06T11:26:23Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/holidayextras/jsonapi-server/pulls/63","html_url":"https://github.com/holidayextras/jsonapi-server/pull/63","diff_url":"https://github.com/holidayextras/jsonapi-server/pull/63.diff","patch_url":"https://github.com/holidayextras/jsonapi-server/pull/63.patch"},"body":"I've had a go at heavily optimising the postProcessing inclusion module. This PR is a work-in-progress, it needs a serious refactor, but the performance is there. Instead of blindly following `related` links to glue together a complex inclusion, `jsonapi-server` now groups id's together and makes custom search requests to reduce the load on the server:\r\n\r\nBefore:\r\n```\r\nhttp://localhost:16006/rest/articles/d850ea75-4427-4f81-8595-039990aeede5/author?& +0ms\r\nhttp://localhost:16006/rest/articles/d850ea75-4427-4f81-8595-039990aeede5/photos?& +1ms\r\nhttp://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/author?& +0ms\r\nhttp://localhost:16006/rest/articles/fa2a073f-8c64-4cbb-9158-b8f67a4ab9f5/photos?& +0ms\r\nhttp://localhost:16006/rest/photos/?relationships[photographer]=cc5cca2e-0dd8-4b95-8cfc-a11230e73116& +39ms\r\nhttp://localhost:16006/rest/photos/?relationships[photographer]=d850ea75-4427-4f81-8595-039990aeede5& +0ms\r\nhttp://localhost:16006/rest/photos/?relationships[photographer]=32fb0105-acaa-4adb-9ec4-8b49633695e1& +1ms\r\nhttp://localhost:16006/rest/photos/?relationships[photographer]=ad3aa89e-9c5b-4ac9-a652-6670f9f27587& +0ms\r\n```\r\n\r\nAfter:\r\n```\r\nhttp://localhost:16006/rest/people/?&filter[id]=cc5cca2e-0dd8-4b95-8cfc-a11230e73116&filter[id]=d850ea75-4427-4f81-8595-039990aeede5&filter[id]=32fb0105-acaa-4adb-9ec4-8b49633695e1&filter[id]=ad3aa89e-9c5b-4ac9-a652-6670f9f27587\r\nhttp://localhost:16006/rest/photos/?&relationships[photographer]=cc5cca2e-0dd8-4b95-8cfc-a11230e73116&relationships[photographer]=32fb0105-acaa-4adb-9ec4-8b49633695e1&relationships[photographer]=d850ea75-4427-4f81-8595-039990aeede5&relationships[photographer]=ad3aa89e-9c5b-4ac9-a652-6670f9f27587\r\n```\r\n\r\nHere's the performance in master right now. The test server responds to 155 requests for data and the test suite passes in 860ms:\r\n```\r\n/repos/jsonapi-server$ npm test\r\n  ...\r\n  Testing jsonapi-server\r\n    Searching for resources\r\n      applying includes\r\n        ✓ unknown attribute should error\r\n        ✓ include author (31ms)\r\n        ✓ include author and photos (67ms)\r\n        ✓ include author.photos and photos (55ms)\r\n        ✓ include author.photos (39ms)\r\n        ✓ include author.photos with filter (29ms)\r\n  ...\r\n  jsonApi:requestCounter 155 +8ms /rest/photos/dfb689d7-3899-4e1d-a0bf-30298ebac6da\r\n\r\n  86 passing (860ms)\r\n```\r\nAnd here's the performance in this branch. The test server responds to 99 requests for data and the test suite passes in 755ms:\r\n```\r\n/repos/jsonapi-server$ npm test\r\n  ...\r\n  Testing jsonapi-server\r\n    Searching for resources\r\n      applying includes\r\n        ✓ unknown attribute should error\r\n        ✓ include author (14ms)\r\n        ✓ include author and photos (25ms)\r\n        ✓ include author.photos and photos (32ms)\r\n        ✓ include author.photos (30ms)\r\n        ✓ include author.photos with filter (18ms)\r\n  ...\r\n  jsonApi:requestCounter 99 +8ms /rest/photos/dfb689d7-3899-4e1d-a0bf-30298ebac6da\r\n  \r\n  86 passing (755ms)\r\n```\r\n\r\nThere's a new debug helper, `DEBUG=jsonApi:requestCounter` to help identify requests.\r\n"},"comment":{"url":"https://api.github.com/repos/holidayextras/jsonapi-server/issues/comments/162304744","html_url":"https://github.com/holidayextras/jsonapi-server/pull/63#issuecomment-162304744","issue_url":"https://api.github.com/repos/holidayextras/jsonapi-server/issues/63","id":162304744,"user":{"login":"hxoliverrumbelow","id":3088374,"avatar_url":"https://avatars.githubusercontent.com/u/3088374?v=3","gravatar_id":"","url":"https://api.github.com/users/hxoliverrumbelow","html_url":"https://github.com/hxoliverrumbelow","followers_url":"https://api.github.com/users/hxoliverrumbelow/followers","following_url":"https://api.github.com/users/hxoliverrumbelow/following{/other_user}","gists_url":"https://api.github.com/users/hxoliverrumbelow/gists{/gist_id}","starred_url":"https://api.github.com/users/hxoliverrumbelow/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hxoliverrumbelow/subscriptions","organizations_url":"https://api.github.com/users/hxoliverrumbelow/orgs","repos_url":"https://api.github.com/users/hxoliverrumbelow/repos","events_url":"https://api.github.com/users/hxoliverrumbelow/events{/privacy}","received_events_url":"https://api.github.com/users/hxoliverrumbelow/received_events","type":"User","site_admin":false},"created_at":"2015-12-06T11:26:23Z","updated_at":"2015-12-06T11:26:23Z","body":"Addresses #61 "}}