{"action":"opened","number":52,"pull_request":{"url":"https://api.github.com/repos/typicode/lowdb/pulls/52","id":38713705,"html_url":"https://github.com/typicode/lowdb/pull/52","diff_url":"https://github.com/typicode/lowdb/pull/52.diff","patch_url":"https://github.com/typicode/lowdb/pull/52.patch","issue_url":"https://api.github.com/repos/typicode/lowdb/issues/52","number":52,"state":"open","locked":false,"title":"Refactor initial data load","user":{"login":"etiktin","id":4381579,"avatar_url":"https://avatars.githubusercontent.com/u/4381579?v=3","gravatar_id":"","url":"https://api.github.com/users/etiktin","html_url":"https://github.com/etiktin","followers_url":"https://api.github.com/users/etiktin/followers","following_url":"https://api.github.com/users/etiktin/following{/other_user}","gists_url":"https://api.github.com/users/etiktin/gists{/gist_id}","starred_url":"https://api.github.com/users/etiktin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etiktin/subscriptions","organizations_url":"https://api.github.com/users/etiktin/orgs","repos_url":"https://api.github.com/users/etiktin/repos","events_url":"https://api.github.com/users/etiktin/events{/privacy}","received_events_url":"https://api.github.com/users/etiktin/received_events","type":"User","site_admin":false},"body":"disk.read returns a Buffer. JSON.parse (used through low.parse) expects a string, so if given something that is not a string, such as a Buffer, it implicitly converts it to string using toString.\r\nIn the former code, we would have 2 conversions from Buffer to string. The first conversion is due the data.trim in the condition (line 105) and the second conversion is when calling JSON.parse (through low.parse in line 107).\r\nIn this commit we change it to a single conversion (we trim the Buffer which implicitly converts it to a string and assign the output directly into the data variable, so there's no need for a second conversion on JSON.parse).\r\n\r\nThis is a small change that can make loading big db files a bit more efficient.\r\nThe code remains readable and it's arguably clearer what the data variable holds.","created_at":"2015-06-27T18:43:00Z","updated_at":"2015-06-27T18:43:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/typicode/lowdb/pulls/52/commits","review_comments_url":"https://api.github.com/repos/typicode/lowdb/pulls/52/comments","review_comment_url":"https://api.github.com/repos/typicode/lowdb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/typicode/lowdb/issues/52/comments","statuses_url":"https://api.github.com/repos/typicode/lowdb/statuses/746c57f8afc1b2139c4ecd63123564045eb570e6","head":{"label":"etiktin:refactor_initial_data_load","ref":"refactor_initial_data_load","sha":"746c57f8afc1b2139c4ecd63123564045eb570e6","user":{"login":"etiktin","id":4381579,"avatar_url":"https://avatars.githubusercontent.com/u/4381579?v=3","gravatar_id":"","url":"https://api.github.com/users/etiktin","html_url":"https://github.com/etiktin","followers_url":"https://api.github.com/users/etiktin/followers","following_url":"https://api.github.com/users/etiktin/following{/other_user}","gists_url":"https://api.github.com/users/etiktin/gists{/gist_id}","starred_url":"https://api.github.com/users/etiktin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etiktin/subscriptions","organizations_url":"https://api.github.com/users/etiktin/orgs","repos_url":"https://api.github.com/users/etiktin/repos","events_url":"https://api.github.com/users/etiktin/events{/privacy}","received_events_url":"https://api.github.com/users/etiktin/received_events","type":"User","site_admin":false},"repo":{"id":36574915,"name":"lowdb","full_name":"etiktin/lowdb","owner":{"login":"etiktin","id":4381579,"avatar_url":"https://avatars.githubusercontent.com/u/4381579?v=3","gravatar_id":"","url":"https://api.github.com/users/etiktin","html_url":"https://github.com/etiktin","followers_url":"https://api.github.com/users/etiktin/followers","following_url":"https://api.github.com/users/etiktin/following{/other_user}","gists_url":"https://api.github.com/users/etiktin/gists{/gist_id}","starred_url":"https://api.github.com/users/etiktin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etiktin/subscriptions","organizations_url":"https://api.github.com/users/etiktin/orgs","repos_url":"https://api.github.com/users/etiktin/repos","events_url":"https://api.github.com/users/etiktin/events{/privacy}","received_events_url":"https://api.github.com/users/etiktin/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/etiktin/lowdb","description":"Flat JSON file database","fork":true,"url":"https://api.github.com/repos/etiktin/lowdb","forks_url":"https://api.github.com/repos/etiktin/lowdb/forks","keys_url":"https://api.github.com/repos/etiktin/lowdb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/etiktin/lowdb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/etiktin/lowdb/teams","hooks_url":"https://api.github.com/repos/etiktin/lowdb/hooks","issue_events_url":"https://api.github.com/repos/etiktin/lowdb/issues/events{/number}","events_url":"https://api.github.com/repos/etiktin/lowdb/events","assignees_url":"https://api.github.com/repos/etiktin/lowdb/assignees{/user}","branches_url":"https://api.github.com/repos/etiktin/lowdb/branches{/branch}","tags_url":"https://api.github.com/repos/etiktin/lowdb/tags","blobs_url":"https://api.github.com/repos/etiktin/lowdb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/etiktin/lowdb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/etiktin/lowdb/git/refs{/sha}","trees_url":"https://api.github.com/repos/etiktin/lowdb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/etiktin/lowdb/statuses/{sha}","languages_url":"https://api.github.com/repos/etiktin/lowdb/languages","stargazers_url":"https://api.github.com/repos/etiktin/lowdb/stargazers","contributors_url":"https://api.github.com/repos/etiktin/lowdb/contributors","subscribers_url":"https://api.github.com/repos/etiktin/lowdb/subscribers","subscription_url":"https://api.github.com/repos/etiktin/lowdb/subscription","commits_url":"https://api.github.com/repos/etiktin/lowdb/commits{/sha}","git_commits_url":"https://api.github.com/repos/etiktin/lowdb/git/commits{/sha}","comments_url":"https://api.github.com/repos/etiktin/lowdb/comments{/number}","issue_comment_url":"https://api.github.com/repos/etiktin/lowdb/issues/comments{/number}","contents_url":"https://api.github.com/repos/etiktin/lowdb/contents/{+path}","compare_url":"https://api.github.com/repos/etiktin/lowdb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/etiktin/lowdb/merges","archive_url":"https://api.github.com/repos/etiktin/lowdb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/etiktin/lowdb/downloads","issues_url":"https://api.github.com/repos/etiktin/lowdb/issues{/number}","pulls_url":"https://api.github.com/repos/etiktin/lowdb/pulls{/number}","milestones_url":"https://api.github.com/repos/etiktin/lowdb/milestones{/number}","notifications_url":"https://api.github.com/repos/etiktin/lowdb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/etiktin/lowdb/labels{/name}","releases_url":"https://api.github.com/repos/etiktin/lowdb/releases{/id}","created_at":"2015-05-30T20:43:05Z","updated_at":"2015-05-30T20:43:06Z","pushed_at":"2015-06-27T18:18:58Z","git_url":"git://github.com/etiktin/lowdb.git","ssh_url":"git@github.com:etiktin/lowdb.git","clone_url":"https://github.com/etiktin/lowdb.git","svn_url":"https://github.com/etiktin/lowdb","homepage":"","size":215,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"typicode:master","ref":"master","sha":"6fc51fabef2db981e968f25994311306b0870a64","user":{"login":"typicode","id":5502029,"avatar_url":"https://avatars.githubusercontent.com/u/5502029?v=3","gravatar_id":"","url":"https://api.github.com/users/typicode","html_url":"https://github.com/typicode","followers_url":"https://api.github.com/users/typicode/followers","following_url":"https://api.github.com/users/typicode/following{/other_user}","gists_url":"https://api.github.com/users/typicode/gists{/gist_id}","starred_url":"https://api.github.com/users/typicode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/typicode/subscriptions","organizations_url":"https://api.github.com/users/typicode/orgs","repos_url":"https://api.github.com/users/typicode/repos","events_url":"https://api.github.com/users/typicode/events{/privacy}","received_events_url":"https://api.github.com/users/typicode/received_events","type":"User","site_admin":false},"repo":{"id":18351848,"name":"lowdb","full_name":"typicode/lowdb","owner":{"login":"typicode","id":5502029,"avatar_url":"https://avatars.githubusercontent.com/u/5502029?v=3","gravatar_id":"","url":"https://api.github.com/users/typicode","html_url":"https://github.com/typicode","followers_url":"https://api.github.com/users/typicode/followers","following_url":"https://api.github.com/users/typicode/following{/other_user}","gists_url":"https://api.github.com/users/typicode/gists{/gist_id}","starred_url":"https://api.github.com/users/typicode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/typicode/subscriptions","organizations_url":"https://api.github.com/users/typicode/orgs","repos_url":"https://api.github.com/users/typicode/repos","events_url":"https://api.github.com/users/typicode/events{/privacy}","received_events_url":"https://api.github.com/users/typicode/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/typicode/lowdb","description":"Flat JSON file database","fork":false,"url":"https://api.github.com/repos/typicode/lowdb","forks_url":"https://api.github.com/repos/typicode/lowdb/forks","keys_url":"https://api.github.com/repos/typicode/lowdb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/typicode/lowdb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/typicode/lowdb/teams","hooks_url":"https://api.github.com/repos/typicode/lowdb/hooks","issue_events_url":"https://api.github.com/repos/typicode/lowdb/issues/events{/number}","events_url":"https://api.github.com/repos/typicode/lowdb/events","assignees_url":"https://api.github.com/repos/typicode/lowdb/assignees{/user}","branches_url":"https://api.github.com/repos/typicode/lowdb/branches{/branch}","tags_url":"https://api.github.com/repos/typicode/lowdb/tags","blobs_url":"https://api.github.com/repos/typicode/lowdb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/typicode/lowdb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/typicode/lowdb/git/refs{/sha}","trees_url":"https://api.github.com/repos/typicode/lowdb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/typicode/lowdb/statuses/{sha}","languages_url":"https://api.github.com/repos/typicode/lowdb/languages","stargazers_url":"https://api.github.com/repos/typicode/lowdb/stargazers","contributors_url":"https://api.github.com/repos/typicode/lowdb/contributors","subscribers_url":"https://api.github.com/repos/typicode/lowdb/subscribers","subscription_url":"https://api.github.com/repos/typicode/lowdb/subscription","commits_url":"https://api.github.com/repos/typicode/lowdb/commits{/sha}","git_commits_url":"https://api.github.com/repos/typicode/lowdb/git/commits{/sha}","comments_url":"https://api.github.com/repos/typicode/lowdb/comments{/number}","issue_comment_url":"https://api.github.com/repos/typicode/lowdb/issues/comments{/number}","contents_url":"https://api.github.com/repos/typicode/lowdb/contents/{+path}","compare_url":"https://api.github.com/repos/typicode/lowdb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/typicode/lowdb/merges","archive_url":"https://api.github.com/repos/typicode/lowdb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/typicode/lowdb/downloads","issues_url":"https://api.github.com/repos/typicode/lowdb/issues{/number}","pulls_url":"https://api.github.com/repos/typicode/lowdb/pulls{/number}","milestones_url":"https://api.github.com/repos/typicode/lowdb/milestones{/number}","notifications_url":"https://api.github.com/repos/typicode/lowdb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/typicode/lowdb/labels{/name}","releases_url":"https://api.github.com/repos/typicode/lowdb/releases{/id}","created_at":"2014-04-02T02:16:06Z","updated_at":"2015-06-27T16:14:18Z","pushed_at":"2015-06-27T18:43:00Z","git_url":"git://github.com/typicode/lowdb.git","ssh_url":"git@github.com:typicode/lowdb.git","clone_url":"https://github.com/typicode/lowdb.git","svn_url":"https://github.com/typicode/lowdb","homepage":"","size":768,"stargazers_count":2241,"watchers_count":2241,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":70,"mirror_url":null,"open_issues_count":8,"forks":70,"open_issues":8,"watchers":2241,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/typicode/lowdb/pulls/52"},"html":{"href":"https://github.com/typicode/lowdb/pull/52"},"issue":{"href":"https://api.github.com/repos/typicode/lowdb/issues/52"},"comments":{"href":"https://api.github.com/repos/typicode/lowdb/issues/52/comments"},"review_comments":{"href":"https://api.github.com/repos/typicode/lowdb/pulls/52/comments"},"review_comment":{"href":"https://api.github.com/repos/typicode/lowdb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/typicode/lowdb/pulls/52/commits"},"statuses":{"href":"https://api.github.com/repos/typicode/lowdb/statuses/746c57f8afc1b2139c4ecd63123564045eb570e6"}},"merged":false,"mergeable":null,"mergeable_state":"unknown","merged_by":null,"comments":0,"review_comments":0,"commits":2,"additions":2,"deletions":2,"changed_files":1}}