GitHub PullRequestReviewCommentEvent at 2014-12-09 09:16:52
Repository: refile
Actor: jnicklas
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/elabs/refile/pulls/comments/21514845","id":21514845,"diff_hunk":"@@ -0,0 +1,127 @@\n+require_relative \"./postgres/reader\"\n+\n+module Refile\n+  module Backend\n+    class Postgres\n+      BACKEND_TABLE_NAME = \"refile_backend_lo_oids\"\n+      def initialize(connection, max_size: nil, namepace: 'default')\n+        @connection = connection\n+        @namespace = namespace\n+        @max_size = max_size\n+      end\n+\n+      def create_backlog_table!\n+        connection.exec %{\n+          CREATE TABLE IF NOT EXISTS #{BACKEND_TABLE_NAME}\n+          (\n+            id serial NOT NULL,\n+            namespace character varying(255),\n+            CONSTRAINT refile_backend_lo_oids_pkey PRIMARY KEY (id)\n+          )\n+          WITH(\n+            OIDS=FALSE\n+          );\n+        }\n+      end\n+\n+      def ready?\n+        connection.exec %{\n+        SELECT count(*) from pg_catalog.pg_tables\n+        WHERE tablename = '#{BACKEND_TABLE_NAME}';\n+        } do |result|\n+          result[0][\"count\"].to_i > 0\n+        end\n+      end\n+\n+      attr_reader :connection, :namespace\n+\n+      def upload(uploadable)\n+        Refile.verify_uploadable(uploadable, @max_size)\n+        begin\n+          oid = connection.lo_creat\n+          connection.transaction do\n+            begin\n+              handle = connection.lo_open(oid, PG::INV_WRITE)\n+              connection.lo_truncate(handle, 0)\n+              buffer = \"\" # reuse the same buffer\n+              until uploadable.eof?\n+                uploadable.read(Refile.read_chunk_size, buffer)\n+                connection.lo_write(handle, buffer)\n+              end\n+              uploadable.close\n+              connection.exec %{\n+                INSERT INTO #{BACKEND_TABLE_NAME} VALUES (#{oid}, '#{namespace}');\n+              }\n+              Refile::File.new(self, oid.to_s)\n+            ensure\n+              connection.lo_close(handle)\n+            end\n+          end\n+        rescue => error\n+          raise error\n+        end\n+      end\n+\n+      def open(id)\n+        Reader.new(connection, id)\n+      end\n+\n+      def read(id)\n+        if exists?(id)\n+          open(id).read\n+        else\n+          nil\n+        end\n+      end\n+\n+      def get(id)\n+        Refile::File.new(self, id)\n+      end\n+\n+      def exists?(id)","path":"lib/refile/backend/postgres.rb","position":81,"original_position":81,"commit_id":"a0a6684f47a42e860ce913369ab199de1793a9ab","original_commit_id":"a0a6684f47a42e860ce913369ab199de1793a9ab","user":{"login":"jnicklas","id":134,"avatar_url":"https://avatars.githubusercontent.com/u/134?v=3","gravatar_id":"","url":"https://api.github.com/users/jnicklas","html_url":"https://github.com/jnicklas","followers_url":"https://api.github.com/users/jnicklas/followers","following_url":"https://api.github.com/users/jnicklas/following{/other_user}","gists_url":"https://api.github.com/users/jnicklas/gists{/gist_id}","starred_url":"https://api.github.com/users/jnicklas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnicklas/subscriptions","organizations_url":"https://api.github.com/users/jnicklas/orgs","repos_url":"https://api.github.com/users/jnicklas/repos","events_url":"https://api.github.com/users/jnicklas/events{/privacy}","received_events_url":"https://api.github.com/users/jnicklas/received_events","type":"User","site_admin":false},"body":"Is `to_s.to_i` enough to mitigate injection attacks? I'm a a bit worried about this. Would be better if this didn't manually interpolate stuff into queries at all. The pg gem must have some kind of quote function, right?","created_at":"2014-12-09T09:16:52Z","updated_at":"2014-12-09T09:16:52Z","html_url":"https://github.com/elabs/refile/pull/23#discussion_r21514845","pull_request_url":"https://api.github.com/repos/elabs/refile/pulls/23","_links":{"self":{"href":"https://api.github.com/repos/elabs/refile/pulls/comments/21514845"},"html":{"href":"https://github.com/elabs/refile/pull/23#discussion_r21514845"},"pull_request":{"href":"https://api.github.com/repos/elabs/refile/pulls/23"}}},"pull_request":{"url":"https://api.github.com/repos/elabs/refile/pulls/23","id":25693722,"html_url":"https://github.com/elabs/refile/pull/23","diff_url":"https://github.com/elabs/refile/pull/23.diff","patch_url":"https://github.com/elabs/refile/pull/23.patch","issue_url":"https://api.github.com/repos/elabs/refile/issues/23","number":23,"state":"open","locked":false,"title":"Possibility to use Postgres as a backend.","user":{"login":"krists","id":197784,"avatar_url":"https://avatars.githubusercontent.com/u/197784?v=3","gravatar_id":"","url":"https://api.github.com/users/krists","html_url":"https://github.com/krists","followers_url":"https://api.github.com/users/krists/followers","following_url":"https://api.github.com/users/krists/following{/other_user}","gists_url":"https://api.github.com/users/krists/gists{/gist_id}","starred_url":"https://api.github.com/users/krists/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krists/subscriptions","organizations_url":"https://api.github.com/users/krists/orgs","repos_url":"https://api.github.com/users/krists/repos","events_url":"https://api.github.com/users/krists/events{/privacy}","received_events_url":"https://api.github.com/users/krists/received_events","type":"User","site_admin":false},"body":"It would be nice to support Postgres as one of the backends for attachments using \"large objects\".\r\nMore info about them can be found here: http://www.postgresql.org/docs/9.3/static/largeobjects.html\r\n\r\nNot sure if this should be included in this project or should go as a separate gem. \r\n\r\nPlease review this.","created_at":"2014-12-08T20:19:06Z","updated_at":"2014-12-09T09:16:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8ef2fda6fa45593a357fa2203097645b007d4c21","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elabs/refile/pulls/23/commits","review_comments_url":"https://api.github.com/repos/elabs/refile/pulls/23/comments","review_comment_url":"https://api.github.com/repos/elabs/refile/pulls/comments/{number}","comments_url":"https://api.github.com/repos/elabs/refile/issues/23/comments","statuses_url":"https://api.github.com/repos/elabs/refile/statuses/a0a6684f47a42e860ce913369ab199de1793a9ab","head":{"label":"krists:postgres-backend","ref":"postgres-backend","sha":"a0a6684f47a42e860ce913369ab199de1793a9ab","user":{"login":"krists","id":197784,"avatar_url":"https://avatars.githubusercontent.com/u/197784?v=3","gravatar_id":"","url":"https://api.github.com/users/krists","html_url":"https://github.com/krists","followers_url":"https://api.github.com/users/krists/followers","following_url":"https://api.github.com/users/krists/following{/other_user}","gists_url":"https://api.github.com/users/krists/gists{/gist_id}","starred_url":"https://api.github.com/users/krists/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krists/subscriptions","organizations_url":"https://api.github.com/users/krists/orgs","repos_url":"https://api.github.com/users/krists/repos","events_url":"https://api.github.com/users/krists/events{/privacy}","received_events_url":"https://api.github.com/users/krists/received_events","type":"User","site_admin":false},"repo":{"id":27582503,"name":"refile","full_name":"krists/refile","owner":{"login":"krists","id":197784,"avatar_url":"https://avatars.githubusercontent.com/u/197784?v=3","gravatar_id":"","url":"https://api.github.com/users/krists","html_url":"https://github.com/krists","followers_url":"https://api.github.com/users/krists/followers","following_url":"https://api.github.com/users/krists/following{/other_user}","gists_url":"https://api.github.com/users/krists/gists{/gist_id}","starred_url":"https://api.github.com/users/krists/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krists/subscriptions","organizations_url":"https://api.github.com/users/krists/orgs","repos_url":"https://api.github.com/users/krists/repos","events_url":"https://api.github.com/users/krists/events{/privacy}","received_events_url":"https://api.github.com/users/krists/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/krists/refile","description":"Ruby file uploads, take 3","fork":true,"url":"https://api.github.com/repos/krists/refile","forks_url":"https://api.github.com/repos/krists/refile/forks","keys_url":"https://api.github.com/repos/krists/refile/keys{/key_id}","collaborators_url":"https://api.github.com/repos/krists/refile/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/krists/refile/teams","hooks_url":"https://api.github.com/repos/krists/refile/hooks","issue_events_url":"https://api.github.com/repos/krists/refile/issues/events{/number}","events_url":"https://api.github.com/repos/krists/refile/events","assignees_url":"https://api.github.com/repos/krists/refile/assignees{/user}","branches_url":"https://api.github.com/repos/krists/refile/branches{/branch}","tags_url":"https://api.github.com/repos/krists/refile/tags","blobs_url":"https://api.github.com/repos/krists/refile/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/krists/refile/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/krists/refile/git/refs{/sha}","trees_url":"https://api.github.com/repos/krists/refile/git/trees{/sha}","statuses_url":"https://api.github.com/repos/krists/refile/statuses/{sha}","languages_url":"https://api.github.com/repos/krists/refile/languages","stargazers_url":"https://api.github.com/repos/krists/refile/stargazers","contributors_url":"https://api.github.com/repos/krists/refile/contributors","subscribers_url":"https://api.github.com/repos/krists/refile/subscribers","subscription_url":"https://api.github.com/repos/krists/refile/subscription","commits_url":"https://api.github.com/repos/krists/refile/commits{/sha}","git_commits_url":"https://api.github.com/repos/krists/refile/git/commits{/sha}","comments_url":"https://api.github.com/repos/krists/refile/comments{/number}","issue_comment_url":"https://api.github.com/repos/krists/refile/issues/comments/{number}","contents_url":"https://api.github.com/repos/krists/refile/contents/{+path}","compare_url":"https://api.github.com/repos/krists/refile/compare/{base}...{head}","merges_url":"https://api.github.com/repos/krists/refile/merges","archive_url":"https://api.github.com/repos/krists/refile/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/krists/refile/downloads","issues_url":"https://api.github.com/repos/krists/refile/issues{/number}","pulls_url":"https://api.github.com/repos/krists/refile/pulls{/number}","milestones_url":"https://api.github.com/repos/krists/refile/milestones{/number}","notifications_url":"https://api.github.com/repos/krists/refile/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/krists/refile/labels{/name}","releases_url":"https://api.github.com/repos/krists/refile/releases{/id}","created_at":"2014-12-05T08:43:23Z","updated_at":"2014-12-05T08:43:24Z","pushed_at":"2014-12-08T20:15:24Z","git_url":"git://github.com/krists/refile.git","ssh_url":"git@github.com:krists/refile.git","clone_url":"https://github.com/krists/refile.git","svn_url":"https://github.com/krists/refile","homepage":"","size":459,"stargazers_count":0,"watchers_count":0,"language":"Ruby","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":"elabs:master","ref":"master","sha":"1049ee1ff66b929d5259331acb0d207f1eaeb94e","user":{"login":"elabs","id":34438,"avatar_url":"https://avatars.githubusercontent.com/u/34438?v=3","gravatar_id":"","url":"https://api.github.com/users/elabs","html_url":"https://github.com/elabs","followers_url":"https://api.github.com/users/elabs/followers","following_url":"https://api.github.com/users/elabs/following{/other_user}","gists_url":"https://api.github.com/users/elabs/gists{/gist_id}","starred_url":"https://api.github.com/users/elabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elabs/subscriptions","organizations_url":"https://api.github.com/users/elabs/orgs","repos_url":"https://api.github.com/users/elabs/repos","events_url":"https://api.github.com/users/elabs/events{/privacy}","received_events_url":"https://api.github.com/users/elabs/received_events","type":"Organization","site_admin":false},"repo":{"id":26870928,"name":"refile","full_name":"elabs/refile","owner":{"login":"elabs","id":34438,"avatar_url":"https://avatars.githubusercontent.com/u/34438?v=3","gravatar_id":"","url":"https://api.github.com/users/elabs","html_url":"https://github.com/elabs","followers_url":"https://api.github.com/users/elabs/followers","following_url":"https://api.github.com/users/elabs/following{/other_user}","gists_url":"https://api.github.com/users/elabs/gists{/gist_id}","starred_url":"https://api.github.com/users/elabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elabs/subscriptions","organizations_url":"https://api.github.com/users/elabs/orgs","repos_url":"https://api.github.com/users/elabs/repos","events_url":"https://api.github.com/users/elabs/events{/privacy}","received_events_url":"https://api.github.com/users/elabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elabs/refile","description":"Ruby file uploads, take 3","fork":false,"url":"https://api.github.com/repos/elabs/refile","forks_url":"https://api.github.com/repos/elabs/refile/forks","keys_url":"https://api.github.com/repos/elabs/refile/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elabs/refile/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elabs/refile/teams","hooks_url":"https://api.github.com/repos/elabs/refile/hooks","issue_events_url":"https://api.github.com/repos/elabs/refile/issues/events{/number}","events_url":"https://api.github.com/repos/elabs/refile/events","assignees_url":"https://api.github.com/repos/elabs/refile/assignees{/user}","branches_url":"https://api.github.com/repos/elabs/refile/branches{/branch}","tags_url":"https://api.github.com/repos/elabs/refile/tags","blobs_url":"https://api.github.com/repos/elabs/refile/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elabs/refile/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elabs/refile/git/refs{/sha}","trees_url":"https://api.github.com/repos/elabs/refile/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elabs/refile/statuses/{sha}","languages_url":"https://api.github.com/repos/elabs/refile/languages","stargazers_url":"https://api.github.com/repos/elabs/refile/stargazers","contributors_url":"https://api.github.com/repos/elabs/refile/contributors","subscribers_url":"https://api.github.com/repos/elabs/refile/subscribers","subscription_url":"https://api.github.com/repos/elabs/refile/subscription","commits_url":"https://api.github.com/repos/elabs/refile/commits{/sha}","git_commits_url":"https://api.github.com/repos/elabs/refile/git/commits{/sha}","comments_url":"https://api.github.com/repos/elabs/refile/comments{/number}","issue_comment_url":"https://api.github.com/repos/elabs/refile/issues/comments/{number}","contents_url":"https://api.github.com/repos/elabs/refile/contents/{+path}","compare_url":"https://api.github.com/repos/elabs/refile/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elabs/refile/merges","archive_url":"https://api.github.com/repos/elabs/refile/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elabs/refile/downloads","issues_url":"https://api.github.com/repos/elabs/refile/issues{/number}","pulls_url":"https://api.github.com/repos/elabs/refile/pulls{/number}","milestones_url":"https://api.github.com/repos/elabs/refile/milestones{/number}","notifications_url":"https://api.github.com/repos/elabs/refile/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elabs/refile/labels{/name}","releases_url":"https://api.github.com/repos/elabs/refile/releases{/id}","created_at":"2014-11-19T16:41:22Z","updated_at":"2014-12-09T08:01:13Z","pushed_at":"2014-12-08T15:47:58Z","git_url":"git://github.com/elabs/refile.git","ssh_url":"git@github.com:elabs/refile.git","clone_url":"https://github.com/elabs/refile.git","svn_url":"https://github.com/elabs/refile","homepage":"","size":459,"stargazers_count":275,"watchers_count":275,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":15,"forks":12,"open_issues":15,"watchers":275,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elabs/refile/pulls/23"},"html":{"href":"https://github.com/elabs/refile/pull/23"},"issue":{"href":"https://api.github.com/repos/elabs/refile/issues/23"},"comments":{"href":"https://api.github.com/repos/elabs/refile/issues/23/comments"},"review_comments":{"href":"https://api.github.com/repos/elabs/refile/pulls/23/comments"},"review_comment":{"href":"https://api.github.com/repos/elabs/refile/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/elabs/refile/pulls/23/commits"},"statuses":{"href":"https://api.github.com/repos/elabs/refile/statuses/a0a6684f47a42e860ce913369ab199de1793a9ab"}}}}