{"action":"created","issue":{"url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/4639","labels_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/4639/labels{/name}","comments_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/4639/comments","events_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/4639/events","html_url":"https://github.com/HabitRPG/habitrpg/issues/4639","id":56721332,"number":4639,"title":"Server queries user from DB 7x / page-view","user":{"login":"lefnire","id":195202,"avatar_url":"https://avatars.githubusercontent.com/u/195202?v=3","gravatar_id":"","url":"https://api.github.com/users/lefnire","html_url":"https://github.com/lefnire","followers_url":"https://api.github.com/users/lefnire/followers","following_url":"https://api.github.com/users/lefnire/following{/other_user}","gists_url":"https://api.github.com/users/lefnire/gists{/gist_id}","starred_url":"https://api.github.com/users/lefnire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lefnire/subscriptions","organizations_url":"https://api.github.com/users/lefnire/orgs","repos_url":"https://api.github.com/users/lefnire/repos","events_url":"https://api.github.com/users/lefnire/events{/privacy}","received_events_url":"https://api.github.com/users/lefnire/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/HabitRPG/habitrpg/labels/database","name":"database","color":"5319e7"},{"url":"https://api.github.com/repos/HabitRPG/habitrpg/labels/performance","name":"performance","color":"bfe5bf"},{"url":"https://api.github.com/repos/HabitRPG/habitrpg/labels/priority%20-%20critical","name":"priority - critical","color":"e10c02"},{"url":"https://api.github.com/repos/HabitRPG/habitrpg/labels/ready","name":"ready","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/HabitRPG/habitrpg/milestones/4","labels_url":"https://api.github.com/repos/HabitRPG/habitrpg/milestones/4/labels","id":967636,"number":4,"title":"Backend Perf/Scale","description":"Per Alys:\r\n\r\n>I am getting the impression that the frequency and maybe severity of weird glitches in people's data are increasing. I'm seeing more people with duplicated tasks, and just recently unexplained jumps in level or XP, and of course the \"2 versions\" bug https://github.com/HabitRPG/habitrpg/issues/4313 . Perhaps it's just because we have more users now, but I am worried that the site or database might be becoming less stable. I'm not sure where to start investigating this, and in fact haven't even had time to look into the localStorage problem properly.\r\n\r\nThe site's architecture is poor, causing frequent Dyno upscales and constant request queueing. This milestone will track the critical issues for improving backend scalability","creator":{"login":"lefnire","id":195202,"avatar_url":"https://avatars.githubusercontent.com/u/195202?v=3","gravatar_id":"","url":"https://api.github.com/users/lefnire","html_url":"https://github.com/lefnire","followers_url":"https://api.github.com/users/lefnire/followers","following_url":"https://api.github.com/users/lefnire/following{/other_user}","gists_url":"https://api.github.com/users/lefnire/gists{/gist_id}","starred_url":"https://api.github.com/users/lefnire/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lefnire/subscriptions","organizations_url":"https://api.github.com/users/lefnire/orgs","repos_url":"https://api.github.com/users/lefnire/repos","events_url":"https://api.github.com/users/lefnire/events{/privacy}","received_events_url":"https://api.github.com/users/lefnire/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":0,"state":"open","created_at":"2015-02-05T19:57:02Z","updated_at":"2015-02-05T20:04:10Z","due_on":"2015-02-28T07:00:00Z","closed_at":null},"comments":8,"created_at":"2015-02-05T20:02:03Z","updated_at":"2015-02-05T20:52:49Z","closed_at":null,"body":"Upon page refresh, the server queries (finds) the viewing user from MongoDB 7 separate times, plus 1 update (`{$set:{_v:xxx}}`) https://gist.github.com/lefnire/751483e04fb4a47ca540. Quite unnecessary. I haven't investigated how many loads per operation of an already loaded page (scoring, edits, etc) but I imagine it'll also be unnecessarily high. Fixing this can reduce server load theoretically by ~7x. \r\n\r\n<bountysource-plugin>\r\n\r\n---\r\nWant to back this issue? **[Place a bounty on it!](https://www.bountysource.com/issues/8324270-server-queries-user-from-db-7x-page-view?utm_campaign=plugin&utm_content=tracker%2F68393&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F68393&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/comments/73125352","html_url":"https://github.com/HabitRPG/habitrpg/issues/4639#issuecomment-73125352","issue_url":"https://api.github.com/repos/HabitRPG/habitrpg/issues/4639","id":73125352,"user":{"login":"paglias","id":589911,"avatar_url":"https://avatars.githubusercontent.com/u/589911?v=3","gravatar_id":"","url":"https://api.github.com/users/paglias","html_url":"https://github.com/paglias","followers_url":"https://api.github.com/users/paglias/followers","following_url":"https://api.github.com/users/paglias/following{/other_user}","gists_url":"https://api.github.com/users/paglias/gists{/gist_id}","starred_url":"https://api.github.com/users/paglias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paglias/subscriptions","organizations_url":"https://api.github.com/users/paglias/orgs","repos_url":"https://api.github.com/users/paglias/repos","events_url":"https://api.github.com/users/paglias/events{/privacy}","received_events_url":"https://api.github.com/users/paglias/received_events","type":"User","site_admin":false},"created_at":"2015-02-05T20:52:49Z","updated_at":"2015-02-05T20:52:49Z","body":"@lefnire using your gist as a reference:\r\n\r\n- `0` is query to get party \r\n- `1` session authentication\r\n- `2` no idea (_v update)\r\n- `3` is call to https://github.com/HabitRPG/habitrpg/blob/develop/src/routes/apiv2.coffee#L549 seenMessage \r\n- `4` is auth for ajax call\r\n- `5` is auth for ajax call to get party\r\n- `6` no idea (find by _id)\r\n- `7` no idea (find by _id and apiToken)\r\n- `8` no idea (find by _id)"}}