{"action":"created","comment":{"url":"https://api.github.com/repos/FarmLogs/python-utils/pulls/comments/41434195","id":41434195,"diff_hunk":"@@ -6,67 +6,79 @@\n from psycopg2.extras import RealDictCursor\n from contextlib import contextmanager\n \n+from flutil.memoize import memoize\n+\n MAX_CONNECTION_ATTEMPTS = 10\n \n \n class EnvironmentVariableNotFoundException(Exception):\n     pass\n \n-class PoolManager:\n-    connections = {}\n \n-    @staticmethod\n-    def get_url_from_environment(name=None):\n+class PoolManager:\n+    @classmethod\n+    @memoize\n+    def from_name(cls, name='DATABASE_URL', mincount=2, maxcount=40, cursor_factory=RealDictCursor):\n         \"\"\"\n-        Try name as upper-cased and with _DATABASE_URL appended,\n-        accepting the first name that exists.\n+        Return a pool instance by name (following our convention of NAME_DATABASE_URL)\n+        first checking to see if it's already been created and returning that instance.\n \n         \"\"\"\n-        attempts = (name.upper(), '%s_DATABASE_URL' % name.upper(), )\n-\n-        for env in attempts:\n-            if env in os.environ:\n-                return os.environ.get(env), env\n+        url, env = cls.__get_url_from_environment(name)\n+        return DatabasePool(url, name, mincount, maxcount, cursor_factory)\n \n-        raise EnvironmentVariableNotFoundException(\\\n-            \"The envrionment variables %s were not found.\" % ' or '.join(attempts) )\n+    @staticmethod","path":"flutil/db.py","position":38,"original_position":38,"commit_id":"e7695c43ac7f02cb135d91ab905beaeefaa46359","original_commit_id":"e7695c43ac7f02cb135d91ab905beaeefaa46359","user":{"login":"dbjohnson","id":2688028,"avatar_url":"https://avatars.githubusercontent.com/u/2688028?v=3","gravatar_id":"","url":"https://api.github.com/users/dbjohnson","html_url":"https://github.com/dbjohnson","followers_url":"https://api.github.com/users/dbjohnson/followers","following_url":"https://api.github.com/users/dbjohnson/following{/other_user}","gists_url":"https://api.github.com/users/dbjohnson/gists{/gist_id}","starred_url":"https://api.github.com/users/dbjohnson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbjohnson/subscriptions","organizations_url":"https://api.github.com/users/dbjohnson/orgs","repos_url":"https://api.github.com/users/dbjohnson/repos","events_url":"https://api.github.com/users/dbjohnson/events{/privacy}","received_events_url":"https://api.github.com/users/dbjohnson/received_events","type":"User","site_admin":false},"body":"only need the class handle in the from_name constructor so we can get a handle to the __get_url_from_env() method.","created_at":"2015-10-07T19:24:56Z","updated_at":"2015-10-07T19:24:56Z","html_url":"https://github.com/FarmLogs/python-utils/pull/6#discussion_r41434195","pull_request_url":"https://api.github.com/repos/FarmLogs/python-utils/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/FarmLogs/python-utils/pulls/comments/41434195"},"html":{"href":"https://github.com/FarmLogs/python-utils/pull/6#discussion_r41434195"},"pull_request":{"href":"https://api.github.com/repos/FarmLogs/python-utils/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/FarmLogs/python-utils/pulls/6","id":47036784,"html_url":"https://github.com/FarmLogs/python-utils/pull/6","diff_url":"https://github.com/FarmLogs/python-utils/pull/6.diff","patch_url":"https://github.com/FarmLogs/python-utils/pull/6.patch","issue_url":"https://api.github.com/repos/FarmLogs/python-utils/issues/6","number":6,"state":"open","locked":false,"title":"added memoize decorator, pushed cache management to PoolManager ctor","user":{"login":"dbjohnson","id":2688028,"avatar_url":"https://avatars.githubusercontent.com/u/2688028?v=3","gravatar_id":"","url":"https://api.github.com/users/dbjohnson","html_url":"https://github.com/dbjohnson","followers_url":"https://api.github.com/users/dbjohnson/followers","following_url":"https://api.github.com/users/dbjohnson/following{/other_user}","gists_url":"https://api.github.com/users/dbjohnson/gists{/gist_id}","starred_url":"https://api.github.com/users/dbjohnson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbjohnson/subscriptions","organizations_url":"https://api.github.com/users/dbjohnson/orgs","repos_url":"https://api.github.com/users/dbjohnson/repos","events_url":"https://api.github.com/users/dbjohnson/events{/privacy}","received_events_url":"https://api.github.com/users/dbjohnson/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-07T14:46:33Z","updated_at":"2015-10-07T19:24:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fe977ed4ffcaf4c9cd7496867fb2e90ce15e021f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/FarmLogs/python-utils/pulls/6/commits","review_comments_url":"https://api.github.com/repos/FarmLogs/python-utils/pulls/6/comments","review_comment_url":"https://api.github.com/repos/FarmLogs/python-utils/pulls/comments{/number}","comments_url":"https://api.github.com/repos/FarmLogs/python-utils/issues/6/comments","statuses_url":"https://api.github.com/repos/FarmLogs/python-utils/statuses/e7695c43ac7f02cb135d91ab905beaeefaa46359","head":{"label":"FarmLogs:memoize-for-db-caching","ref":"memoize-for-db-caching","sha":"e7695c43ac7f02cb135d91ab905beaeefaa46359","user":{"login":"FarmLogs","id":1245307,"avatar_url":"https://avatars.githubusercontent.com/u/1245307?v=3","gravatar_id":"","url":"https://api.github.com/users/FarmLogs","html_url":"https://github.com/FarmLogs","followers_url":"https://api.github.com/users/FarmLogs/followers","following_url":"https://api.github.com/users/FarmLogs/following{/other_user}","gists_url":"https://api.github.com/users/FarmLogs/gists{/gist_id}","starred_url":"https://api.github.com/users/FarmLogs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FarmLogs/subscriptions","organizations_url":"https://api.github.com/users/FarmLogs/orgs","repos_url":"https://api.github.com/users/FarmLogs/repos","events_url":"https://api.github.com/users/FarmLogs/events{/privacy}","received_events_url":"https://api.github.com/users/FarmLogs/received_events","type":"Organization","site_admin":false},"repo":{"id":42311099,"name":"python-utils","full_name":"FarmLogs/python-utils","owner":{"login":"FarmLogs","id":1245307,"avatar_url":"https://avatars.githubusercontent.com/u/1245307?v=3","gravatar_id":"","url":"https://api.github.com/users/FarmLogs","html_url":"https://github.com/FarmLogs","followers_url":"https://api.github.com/users/FarmLogs/followers","following_url":"https://api.github.com/users/FarmLogs/following{/other_user}","gists_url":"https://api.github.com/users/FarmLogs/gists{/gist_id}","starred_url":"https://api.github.com/users/FarmLogs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FarmLogs/subscriptions","organizations_url":"https://api.github.com/users/FarmLogs/orgs","repos_url":"https://api.github.com/users/FarmLogs/repos","events_url":"https://api.github.com/users/FarmLogs/events{/privacy}","received_events_url":"https://api.github.com/users/FarmLogs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/FarmLogs/python-utils","description":"Farmlogs Centric Python Utilities","fork":false,"url":"https://api.github.com/repos/FarmLogs/python-utils","forks_url":"https://api.github.com/repos/FarmLogs/python-utils/forks","keys_url":"https://api.github.com/repos/FarmLogs/python-utils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FarmLogs/python-utils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FarmLogs/python-utils/teams","hooks_url":"https://api.github.com/repos/FarmLogs/python-utils/hooks","issue_events_url":"https://api.github.com/repos/FarmLogs/python-utils/issues/events{/number}","events_url":"https://api.github.com/repos/FarmLogs/python-utils/events","assignees_url":"https://api.github.com/repos/FarmLogs/python-utils/assignees{/user}","branches_url":"https://api.github.com/repos/FarmLogs/python-utils/branches{/branch}","tags_url":"https://api.github.com/repos/FarmLogs/python-utils/tags","blobs_url":"https://api.github.com/repos/FarmLogs/python-utils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FarmLogs/python-utils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FarmLogs/python-utils/git/refs{/sha}","trees_url":"https://api.github.com/repos/FarmLogs/python-utils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FarmLogs/python-utils/statuses/{sha}","languages_url":"https://api.github.com/repos/FarmLogs/python-utils/languages","stargazers_url":"https://api.github.com/repos/FarmLogs/python-utils/stargazers","contributors_url":"https://api.github.com/repos/FarmLogs/python-utils/contributors","subscribers_url":"https://api.github.com/repos/FarmLogs/python-utils/subscribers","subscription_url":"https://api.github.com/repos/FarmLogs/python-utils/subscription","commits_url":"https://api.github.com/repos/FarmLogs/python-utils/commits{/sha}","git_commits_url":"https://api.github.com/repos/FarmLogs/python-utils/git/commits{/sha}","comments_url":"https://api.github.com/repos/FarmLogs/python-utils/comments{/number}","issue_comment_url":"https://api.github.com/repos/FarmLogs/python-utils/issues/comments{/number}","contents_url":"https://api.github.com/repos/FarmLogs/python-utils/contents/{+path}","compare_url":"https://api.github.com/repos/FarmLogs/python-utils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FarmLogs/python-utils/merges","archive_url":"https://api.github.com/repos/FarmLogs/python-utils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FarmLogs/python-utils/downloads","issues_url":"https://api.github.com/repos/FarmLogs/python-utils/issues{/number}","pulls_url":"https://api.github.com/repos/FarmLogs/python-utils/pulls{/number}","milestones_url":"https://api.github.com/repos/FarmLogs/python-utils/milestones{/number}","notifications_url":"https://api.github.com/repos/FarmLogs/python-utils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FarmLogs/python-utils/labels{/name}","releases_url":"https://api.github.com/repos/FarmLogs/python-utils/releases{/id}","created_at":"2015-09-11T13:48:01Z","updated_at":"2015-10-06T21:33:59Z","pushed_at":"2015-10-07T19:10:02Z","git_url":"git://github.com/FarmLogs/python-utils.git","ssh_url":"git@github.com:FarmLogs/python-utils.git","clone_url":"https://github.com/FarmLogs/python-utils.git","svn_url":"https://github.com/FarmLogs/python-utils","homepage":"","size":208,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"FarmLogs:master","ref":"master","sha":"81d05d8d2a24fa22e9d66ca8b090992f4c5df07f","user":{"login":"FarmLogs","id":1245307,"avatar_url":"https://avatars.githubusercontent.com/u/1245307?v=3","gravatar_id":"","url":"https://api.github.com/users/FarmLogs","html_url":"https://github.com/FarmLogs","followers_url":"https://api.github.com/users/FarmLogs/followers","following_url":"https://api.github.com/users/FarmLogs/following{/other_user}","gists_url":"https://api.github.com/users/FarmLogs/gists{/gist_id}","starred_url":"https://api.github.com/users/FarmLogs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FarmLogs/subscriptions","organizations_url":"https://api.github.com/users/FarmLogs/orgs","repos_url":"https://api.github.com/users/FarmLogs/repos","events_url":"https://api.github.com/users/FarmLogs/events{/privacy}","received_events_url":"https://api.github.com/users/FarmLogs/received_events","type":"Organization","site_admin":false},"repo":{"id":42311099,"name":"python-utils","full_name":"FarmLogs/python-utils","owner":{"login":"FarmLogs","id":1245307,"avatar_url":"https://avatars.githubusercontent.com/u/1245307?v=3","gravatar_id":"","url":"https://api.github.com/users/FarmLogs","html_url":"https://github.com/FarmLogs","followers_url":"https://api.github.com/users/FarmLogs/followers","following_url":"https://api.github.com/users/FarmLogs/following{/other_user}","gists_url":"https://api.github.com/users/FarmLogs/gists{/gist_id}","starred_url":"https://api.github.com/users/FarmLogs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FarmLogs/subscriptions","organizations_url":"https://api.github.com/users/FarmLogs/orgs","repos_url":"https://api.github.com/users/FarmLogs/repos","events_url":"https://api.github.com/users/FarmLogs/events{/privacy}","received_events_url":"https://api.github.com/users/FarmLogs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/FarmLogs/python-utils","description":"Farmlogs Centric Python Utilities","fork":false,"url":"https://api.github.com/repos/FarmLogs/python-utils","forks_url":"https://api.github.com/repos/FarmLogs/python-utils/forks","keys_url":"https://api.github.com/repos/FarmLogs/python-utils/keys{/key_id}","collaborators_url":"https://api.github.com/repos/FarmLogs/python-utils/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/FarmLogs/python-utils/teams","hooks_url":"https://api.github.com/repos/FarmLogs/python-utils/hooks","issue_events_url":"https://api.github.com/repos/FarmLogs/python-utils/issues/events{/number}","events_url":"https://api.github.com/repos/FarmLogs/python-utils/events","assignees_url":"https://api.github.com/repos/FarmLogs/python-utils/assignees{/user}","branches_url":"https://api.github.com/repos/FarmLogs/python-utils/branches{/branch}","tags_url":"https://api.github.com/repos/FarmLogs/python-utils/tags","blobs_url":"https://api.github.com/repos/FarmLogs/python-utils/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/FarmLogs/python-utils/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/FarmLogs/python-utils/git/refs{/sha}","trees_url":"https://api.github.com/repos/FarmLogs/python-utils/git/trees{/sha}","statuses_url":"https://api.github.com/repos/FarmLogs/python-utils/statuses/{sha}","languages_url":"https://api.github.com/repos/FarmLogs/python-utils/languages","stargazers_url":"https://api.github.com/repos/FarmLogs/python-utils/stargazers","contributors_url":"https://api.github.com/repos/FarmLogs/python-utils/contributors","subscribers_url":"https://api.github.com/repos/FarmLogs/python-utils/subscribers","subscription_url":"https://api.github.com/repos/FarmLogs/python-utils/subscription","commits_url":"https://api.github.com/repos/FarmLogs/python-utils/commits{/sha}","git_commits_url":"https://api.github.com/repos/FarmLogs/python-utils/git/commits{/sha}","comments_url":"https://api.github.com/repos/FarmLogs/python-utils/comments{/number}","issue_comment_url":"https://api.github.com/repos/FarmLogs/python-utils/issues/comments{/number}","contents_url":"https://api.github.com/repos/FarmLogs/python-utils/contents/{+path}","compare_url":"https://api.github.com/repos/FarmLogs/python-utils/compare/{base}...{head}","merges_url":"https://api.github.com/repos/FarmLogs/python-utils/merges","archive_url":"https://api.github.com/repos/FarmLogs/python-utils/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/FarmLogs/python-utils/downloads","issues_url":"https://api.github.com/repos/FarmLogs/python-utils/issues{/number}","pulls_url":"https://api.github.com/repos/FarmLogs/python-utils/pulls{/number}","milestones_url":"https://api.github.com/repos/FarmLogs/python-utils/milestones{/number}","notifications_url":"https://api.github.com/repos/FarmLogs/python-utils/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/FarmLogs/python-utils/labels{/name}","releases_url":"https://api.github.com/repos/FarmLogs/python-utils/releases{/id}","created_at":"2015-09-11T13:48:01Z","updated_at":"2015-10-06T21:33:59Z","pushed_at":"2015-10-07T19:10:02Z","git_url":"git://github.com/FarmLogs/python-utils.git","ssh_url":"git@github.com:FarmLogs/python-utils.git","clone_url":"https://github.com/FarmLogs/python-utils.git","svn_url":"https://github.com/FarmLogs/python-utils","homepage":"","size":208,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/FarmLogs/python-utils/pulls/6"},"html":{"href":"https://github.com/FarmLogs/python-utils/pull/6"},"issue":{"href":"https://api.github.com/repos/FarmLogs/python-utils/issues/6"},"comments":{"href":"https://api.github.com/repos/FarmLogs/python-utils/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/FarmLogs/python-utils/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/FarmLogs/python-utils/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/FarmLogs/python-utils/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/FarmLogs/python-utils/statuses/e7695c43ac7f02cb135d91ab905beaeefaa46359"}}}}