{"action":"created","comment":{"url":"https://api.github.com/repos/koding/koding/pulls/comments/87001552","pull_request_review_id":7630656,"id":87001552,"diff_hunk":"@@ -105,71 +120,123 @@ module.exports = class Bongo extends EventEmitter\n \n   bound: require 'koding-bound'\n \n-  defineModel:(name, model)->\n+\n+  defineModel: (name, model) ->\n+\n+    unless model.addBongo? this\n+      return\n+\n+    if @models[name]\n+      console.warn \"Model #{name} defined multiple times!\"\n+      return name\n+\n     @models[name] = model\n-    return  unless model.addBongo? this\n+\n     @emit 'newModel', name, model\n-    model.on 'needsPopulated', (def, path)=>\n-      path = if Array.isArray path then path else path.split '.'\n-      names = JsPath.getAt def, path\n+\n+    model.on 'needsPopulated', (def, _path) =>\n+\n+      _path = if Array.isArray _path then _path else _path.split '.'\n+      names = JsPath.getAt def, _path\n+\n       unless Array.isArray names\n         names = [names]\n-        JsPath.setAt def, path, names\n-      names.forEach (name, i)=>\n+        JsPath.setAt def, _path, names\n+\n+      names.forEach (name, i) =>\n         if target = @models[name]\n-          JsPath.setAt def, path.concat(i), target\n-      @on 'newModel', (newName, newModel)->\n+          JsPath.setAt def, _path.concat(i), target\n+\n+      @on 'newModel', (newName, newModel) ->\n         if newName in names\n-          JsPath.setAt def, path.concat(names.indexOf newName), newModel\n+          JsPath.setAt def, _path.concat(names.indexOf newName), newModel\n+\n+    return name\n+\n+\n+  registerModel: (path) ->\n+\n+    cons = require path\n+\n+    if cons.name? and ('function' is typeof cons)\n+      @defineModel cons.name, cons\n+\n+    else\n+      models = []\n+      for own name, konstructor of cons\n+        models.push @defineModel name, konstructor\n+\n+      models\n+\n \n   findCode = (paths) ->\n-    Promise.map paths, (path) ->\n-      fs.statAsync(path).then (stats) ->\n+    Promise.map paths, (_path) ->\n+      fs.lstatAsync(_path).then (stats) ->\n         # in the case that this is a directory, recurse into it\n         if stats.isDirectory()\n-          fs.readdirAsync(path).map (dir) ->\n-            nodePath.join path, dir\n+          fs.readdirAsync(_path).map (dir) ->\n+            path.join _path, dir\n           .then findCode\n         # otherwise, just collect the path\n-        else [path]\n+        else [_path]\n     # flatten the result\n     .reduce((a, b) -> a.concat b)\n     # if coffee or js file include it\n-    .filter (path) -> return /(\\.coffee|\\.js)$/.test(path)\n+    .filter (_path) -> return /(\\.coffee|\\.js)$/.test(_path)\n     # if test file return false and exclude file\n-    .filter (path) -> return !isTestFile path\n+    .filter (_path) -> return !(/\\.test\\.coffee$/.test _path)\n \n \n-  endsWith = (str, suffix) ->\n+  loadModels: ->\n \n-    return str.toLowerCase().indexOf(suffix.toLowerCase(), str.length - suffix.length) != -1\n+    Promise.map @modelIndexPaths, (modelPath, index) =>\n \n+      fs.lstatSync modelPath\n \n-  isTestFile = (path) ->\n+      cache = JSON.parse(fs.readFileSync(modelPath).toString())\n \n-    return endsWith path, 'test.coffee'\n+      # console.log \"Model list found:\", modelPath","path":"node_modules_koding/bongo/lib/bongo.coffee","position":162,"original_position":162,"commit_id":"a26a6eed2adba741047f5a594afe083c9e6aaf54","original_commit_id":"a26a6eed2adba741047f5a594afe083c9e6aaf54","user":{"login":"gokmen","id":42368,"avatar_url":"https://avatars.githubusercontent.com/u/42368?v=3","gravatar_id":"","url":"https://api.github.com/users/gokmen","html_url":"https://github.com/gokmen","followers_url":"https://api.github.com/users/gokmen/followers","following_url":"https://api.github.com/users/gokmen/following{/other_user}","gists_url":"https://api.github.com/users/gokmen/gists{/gist_id}","starred_url":"https://api.github.com/users/gokmen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gokmen/subscriptions","organizations_url":"https://api.github.com/users/gokmen/orgs","repos_url":"https://api.github.com/users/gokmen/repos","events_url":"https://api.github.com/users/gokmen/events{/privacy}","received_events_url":"https://api.github.com/users/gokmen/received_events","type":"User","site_admin":false},"body":"yes, I'm planning add `debug` package into this for feature developments and I'll convert these to debug messages.","created_at":"2016-11-08T14:44:04Z","updated_at":"2016-11-08T14:44:04Z","html_url":"https://github.com/koding/koding/pull/9495#discussion_r87001552","pull_request_url":"https://api.github.com/repos/koding/koding/pulls/9495","_links":{"self":{"href":"https://api.github.com/repos/koding/koding/pulls/comments/87001552"},"html":{"href":"https://github.com/koding/koding/pull/9495#discussion_r87001552"},"pull_request":{"href":"https://api.github.com/repos/koding/koding/pulls/9495"}}},"pull_request":{"url":"https://api.github.com/repos/koding/koding/pulls/9495","id":92690047,"html_url":"https://github.com/koding/koding/pull/9495","diff_url":"https://github.com/koding/koding/pull/9495.diff","patch_url":"https://github.com/koding/koding/pull/9495.patch","issue_url":"https://api.github.com/repos/koding/koding/issues/9495","number":9495,"state":"open","locked":false,"title":"Bongo/Dev env improvements","user":{"login":"gokmen","id":42368,"avatar_url":"https://avatars.githubusercontent.com/u/42368?v=3","gravatar_id":"","url":"https://api.github.com/users/gokmen","html_url":"https://github.com/gokmen","followers_url":"https://api.github.com/users/gokmen/followers","following_url":"https://api.github.com/users/gokmen/following{/other_user}","gists_url":"https://api.github.com/users/gokmen/gists{/gist_id}","starred_url":"https://api.github.com/users/gokmen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gokmen/subscriptions","organizations_url":"https://api.github.com/users/gokmen/orgs","repos_url":"https://api.github.com/users/gokmen/repos","events_url":"https://api.github.com/users/gokmen/events{/privacy}","received_events_url":"https://api.github.com/users/gokmen/received_events","type":"User","site_admin":false},"body":"With this PR we will have following changes;\r\n\r\n- [x] Caching for compiled coffeescript files on `social`, `auth` and `webserver` workers\r\n- [x] Improvements on `npm` package checker and `run` script for faster booting\r\n- [x] Aggressive Bongo models caching; with `coffee-cache` and importing cached models file we now have **%200 faster loads on Bongo**\r\n- [x] Disabled `NodeJsProfiler` except `production` environment reduces load for development\r\n\r\n## Before\r\n![](http://g.recordit.co/cIdGkIYvpv.gif)\r\n[1m 29sec.](http://recordit.co/cIdGkIYvpv)\r\n## After\r\n![](http://g.recordit.co/R9HNvUBKuw.gif)\r\n[17 sec.](http://recordit.co/R9HNvUBKuw)\r\n\r\nps. Difference in screencast is mostly because `npm install` which was running all the time on each `./run` on current `master`.\r\n\r\n## Bongo load difference\r\n![image](https://cloud.githubusercontent.com/assets/42368/20081510/b65fdb0a-a558-11e6-9183-eda55750c057.png)\r\n\r\n```coffee\r\nrequire 'coffee-cache'\r\nbongo = require './servers/lib/server/bongo'\r\nbongo.on 'apiReady', ->\r\n  console.log 'Loaded models:', Object.keys(bongo.models).length\r\n  process.exit()\r\n```\r\n\r\nps. In current `master` this script will say it's loaded **230~ models** which was also another issue fixed in this PR","created_at":"2016-11-07T23:59:45Z","updated_at":"2016-11-08T14:44:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8cbd5b4bac015f5ef69c55a1d08b3a267679931d","assignee":{"login":"cihangir","id":879660,"avatar_url":"https://avatars.githubusercontent.com/u/879660?v=3","gravatar_id":"","url":"https://api.github.com/users/cihangir","html_url":"https://github.com/cihangir","followers_url":"https://api.github.com/users/cihangir/followers","following_url":"https://api.github.com/users/cihangir/following{/other_user}","gists_url":"https://api.github.com/users/cihangir/gists{/gist_id}","starred_url":"https://api.github.com/users/cihangir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cihangir/subscriptions","organizations_url":"https://api.github.com/users/cihangir/orgs","repos_url":"https://api.github.com/users/cihangir/repos","events_url":"https://api.github.com/users/cihangir/events{/privacy}","received_events_url":"https://api.github.com/users/cihangir/received_events","type":"User","site_admin":false},"assignees":[{"login":"cihangir","id":879660,"avatar_url":"https://avatars.githubusercontent.com/u/879660?v=3","gravatar_id":"","url":"https://api.github.com/users/cihangir","html_url":"https://github.com/cihangir","followers_url":"https://api.github.com/users/cihangir/followers","following_url":"https://api.github.com/users/cihangir/following{/other_user}","gists_url":"https://api.github.com/users/cihangir/gists{/gist_id}","starred_url":"https://api.github.com/users/cihangir/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cihangir/subscriptions","organizations_url":"https://api.github.com/users/cihangir/orgs","repos_url":"https://api.github.com/users/cihangir/repos","events_url":"https://api.github.com/users/cihangir/events{/privacy}","received_events_url":"https://api.github.com/users/cihangir/received_events","type":"User","site_admin":false},{"login":"szkl","id":1136739,"avatar_url":"https://avatars.githubusercontent.com/u/1136739?v=3","gravatar_id":"","url":"https://api.github.com/users/szkl","html_url":"https://github.com/szkl","followers_url":"https://api.github.com/users/szkl/followers","following_url":"https://api.github.com/users/szkl/following{/other_user}","gists_url":"https://api.github.com/users/szkl/gists{/gist_id}","starred_url":"https://api.github.com/users/szkl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/szkl/subscriptions","organizations_url":"https://api.github.com/users/szkl/orgs","repos_url":"https://api.github.com/users/szkl/repos","events_url":"https://api.github.com/users/szkl/events{/privacy}","received_events_url":"https://api.github.com/users/szkl/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/koding/koding/pulls/9495/commits","review_comments_url":"https://api.github.com/repos/koding/koding/pulls/9495/comments","review_comment_url":"https://api.github.com/repos/koding/koding/pulls/comments{/number}","comments_url":"https://api.github.com/repos/koding/koding/issues/9495/comments","statuses_url":"https://api.github.com/repos/koding/koding/statuses/a26a6eed2adba741047f5a594afe083c9e6aaf54","head":{"label":"koding:bongo","ref":"bongo","sha":"a26a6eed2adba741047f5a594afe083c9e6aaf54","user":{"login":"koding","id":1066754,"avatar_url":"https://avatars.githubusercontent.com/u/1066754?v=3","gravatar_id":"","url":"https://api.github.com/users/koding","html_url":"https://github.com/koding","followers_url":"https://api.github.com/users/koding/followers","following_url":"https://api.github.com/users/koding/following{/other_user}","gists_url":"https://api.github.com/users/koding/gists{/gist_id}","starred_url":"https://api.github.com/users/koding/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koding/subscriptions","organizations_url":"https://api.github.com/users/koding/orgs","repos_url":"https://api.github.com/users/koding/repos","events_url":"https://api.github.com/users/koding/events{/privacy}","received_events_url":"https://api.github.com/users/koding/received_events","type":"Organization","site_admin":false},"repo":{"id":21317360,"name":"koding","full_name":"koding/koding","owner":{"login":"koding","id":1066754,"avatar_url":"https://avatars.githubusercontent.com/u/1066754?v=3","gravatar_id":"","url":"https://api.github.com/users/koding","html_url":"https://github.com/koding","followers_url":"https://api.github.com/users/koding/followers","following_url":"https://api.github.com/users/koding/following{/other_user}","gists_url":"https://api.github.com/users/koding/gists{/gist_id}","starred_url":"https://api.github.com/users/koding/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koding/subscriptions","organizations_url":"https://api.github.com/users/koding/orgs","repos_url":"https://api.github.com/users/koding/repos","events_url":"https://api.github.com/users/koding/events{/privacy}","received_events_url":"https://api.github.com/users/koding/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/koding/koding","description":"The Simplest Way to Manage Your Entire Dev Infrastructure!","fork":false,"url":"https://api.github.com/repos/koding/koding","forks_url":"https://api.github.com/repos/koding/koding/forks","keys_url":"https://api.github.com/repos/koding/koding/keys{/key_id}","collaborators_url":"https://api.github.com/repos/koding/koding/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/koding/koding/teams","hooks_url":"https://api.github.com/repos/koding/koding/hooks","issue_events_url":"https://api.github.com/repos/koding/koding/issues/events{/number}","events_url":"https://api.github.com/repos/koding/koding/events","assignees_url":"https://api.github.com/repos/koding/koding/assignees{/user}","branches_url":"https://api.github.com/repos/koding/koding/branches{/branch}","tags_url":"https://api.github.com/repos/koding/koding/tags","blobs_url":"https://api.github.com/repos/koding/koding/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/koding/koding/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/koding/koding/git/refs{/sha}","trees_url":"https://api.github.com/repos/koding/koding/git/trees{/sha}","statuses_url":"https://api.github.com/repos/koding/koding/statuses/{sha}","languages_url":"https://api.github.com/repos/koding/koding/languages","stargazers_url":"https://api.github.com/repos/koding/koding/stargazers","contributors_url":"https://api.github.com/repos/koding/koding/contributors","subscribers_url":"https://api.github.com/repos/koding/koding/subscribers","subscription_url":"https://api.github.com/repos/koding/koding/subscription","commits_url":"https://api.github.com/repos/koding/koding/commits{/sha}","git_commits_url":"https://api.github.com/repos/koding/koding/git/commits{/sha}","comments_url":"https://api.github.com/repos/koding/koding/comments{/number}","issue_comment_url":"https://api.github.com/repos/koding/koding/issues/comments{/number}","contents_url":"https://api.github.com/repos/koding/koding/contents/{+path}","compare_url":"https://api.github.com/repos/koding/koding/compare/{base}...{head}","merges_url":"https://api.github.com/repos/koding/koding/merges","archive_url":"https://api.github.com/repos/koding/koding/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/koding/koding/downloads","issues_url":"https://api.github.com/repos/koding/koding/issues{/number}","pulls_url":"https://api.github.com/repos/koding/koding/pulls{/number}","milestones_url":"https://api.github.com/repos/koding/koding/milestones{/number}","notifications_url":"https://api.github.com/repos/koding/koding/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/koding/koding/labels{/name}","releases_url":"https://api.github.com/repos/koding/koding/releases{/id}","deployments_url":"https://api.github.com/repos/koding/koding/deployments","created_at":"2014-06-29T05:46:24Z","updated_at":"2016-11-08T09:08:18Z","pushed_at":"2016-11-08T13:53:39Z","git_url":"git://github.com/koding/koding.git","ssh_url":"git@github.com:koding/koding.git","clone_url":"https://github.com/koding/koding.git","svn_url":"https://github.com/koding/koding","homepage":"https://www.koding.com","size":806366,"stargazers_count":450,"watchers_count":450,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":57,"mirror_url":null,"open_issues_count":195,"forks":57,"open_issues":195,"watchers":450,"default_branch":"master"}},"base":{"label":"koding:master","ref":"master","sha":"a7b0d13a41bd864a3557048845af5fdf4956bef1","user":{"login":"koding","id":1066754,"avatar_url":"https://avatars.githubusercontent.com/u/1066754?v=3","gravatar_id":"","url":"https://api.github.com/users/koding","html_url":"https://github.com/koding","followers_url":"https://api.github.com/users/koding/followers","following_url":"https://api.github.com/users/koding/following{/other_user}","gists_url":"https://api.github.com/users/koding/gists{/gist_id}","starred_url":"https://api.github.com/users/koding/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koding/subscriptions","organizations_url":"https://api.github.com/users/koding/orgs","repos_url":"https://api.github.com/users/koding/repos","events_url":"https://api.github.com/users/koding/events{/privacy}","received_events_url":"https://api.github.com/users/koding/received_events","type":"Organization","site_admin":false},"repo":{"id":21317360,"name":"koding","full_name":"koding/koding","owner":{"login":"koding","id":1066754,"avatar_url":"https://avatars.githubusercontent.com/u/1066754?v=3","gravatar_id":"","url":"https://api.github.com/users/koding","html_url":"https://github.com/koding","followers_url":"https://api.github.com/users/koding/followers","following_url":"https://api.github.com/users/koding/following{/other_user}","gists_url":"https://api.github.com/users/koding/gists{/gist_id}","starred_url":"https://api.github.com/users/koding/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koding/subscriptions","organizations_url":"https://api.github.com/users/koding/orgs","repos_url":"https://api.github.com/users/koding/repos","events_url":"https://api.github.com/users/koding/events{/privacy}","received_events_url":"https://api.github.com/users/koding/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/koding/koding","description":"The Simplest Way to Manage Your Entire Dev Infrastructure!","fork":false,"url":"https://api.github.com/repos/koding/koding","forks_url":"https://api.github.com/repos/koding/koding/forks","keys_url":"https://api.github.com/repos/koding/koding/keys{/key_id}","collaborators_url":"https://api.github.com/repos/koding/koding/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/koding/koding/teams","hooks_url":"https://api.github.com/repos/koding/koding/hooks","issue_events_url":"https://api.github.com/repos/koding/koding/issues/events{/number}","events_url":"https://api.github.com/repos/koding/koding/events","assignees_url":"https://api.github.com/repos/koding/koding/assignees{/user}","branches_url":"https://api.github.com/repos/koding/koding/branches{/branch}","tags_url":"https://api.github.com/repos/koding/koding/tags","blobs_url":"https://api.github.com/repos/koding/koding/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/koding/koding/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/koding/koding/git/refs{/sha}","trees_url":"https://api.github.com/repos/koding/koding/git/trees{/sha}","statuses_url":"https://api.github.com/repos/koding/koding/statuses/{sha}","languages_url":"https://api.github.com/repos/koding/koding/languages","stargazers_url":"https://api.github.com/repos/koding/koding/stargazers","contributors_url":"https://api.github.com/repos/koding/koding/contributors","subscribers_url":"https://api.github.com/repos/koding/koding/subscribers","subscription_url":"https://api.github.com/repos/koding/koding/subscription","commits_url":"https://api.github.com/repos/koding/koding/commits{/sha}","git_commits_url":"https://api.github.com/repos/koding/koding/git/commits{/sha}","comments_url":"https://api.github.com/repos/koding/koding/comments{/number}","issue_comment_url":"https://api.github.com/repos/koding/koding/issues/comments{/number}","contents_url":"https://api.github.com/repos/koding/koding/contents/{+path}","compare_url":"https://api.github.com/repos/koding/koding/compare/{base}...{head}","merges_url":"https://api.github.com/repos/koding/koding/merges","archive_url":"https://api.github.com/repos/koding/koding/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/koding/koding/downloads","issues_url":"https://api.github.com/repos/koding/koding/issues{/number}","pulls_url":"https://api.github.com/repos/koding/koding/pulls{/number}","milestones_url":"https://api.github.com/repos/koding/koding/milestones{/number}","notifications_url":"https://api.github.com/repos/koding/koding/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/koding/koding/labels{/name}","releases_url":"https://api.github.com/repos/koding/koding/releases{/id}","deployments_url":"https://api.github.com/repos/koding/koding/deployments","created_at":"2014-06-29T05:46:24Z","updated_at":"2016-11-08T09:08:18Z","pushed_at":"2016-11-08T13:53:39Z","git_url":"git://github.com/koding/koding.git","ssh_url":"git@github.com:koding/koding.git","clone_url":"https://github.com/koding/koding.git","svn_url":"https://github.com/koding/koding","homepage":"https://www.koding.com","size":806366,"stargazers_count":450,"watchers_count":450,"language":"CoffeeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":57,"mirror_url":null,"open_issues_count":195,"forks":57,"open_issues":195,"watchers":450,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/koding/koding/pulls/9495"},"html":{"href":"https://github.com/koding/koding/pull/9495"},"issue":{"href":"https://api.github.com/repos/koding/koding/issues/9495"},"comments":{"href":"https://api.github.com/repos/koding/koding/issues/9495/comments"},"review_comments":{"href":"https://api.github.com/repos/koding/koding/pulls/9495/comments"},"review_comment":{"href":"https://api.github.com/repos/koding/koding/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/koding/koding/pulls/9495/commits"},"statuses":{"href":"https://api.github.com/repos/koding/koding/statuses/a26a6eed2adba741047f5a594afe083c9e6aaf54"}}}}
{"actor":{"display_login":"gokmen"}}