{"action":"created","comment":{"url":"https://api.github.com/repos/washingtontrails/vms/pulls/comments/31344085","id":31344085,"diff_hunk":"@@ -111,6 +118,67 @@ def get_volunteer_hours(self, wp_id):\n     def describe_table(self, table):\n         return getattr(self, table).describe()\n \n+    @lru_cache(25, cache=DOCUMENTS_CACHE)\n+    def get_crew_documents(self, folder_id):\n+        \"\"\"Get metadata about all documents in 'folder_id'\"\"\"\n+        res = self.query_all(\n+            \"SELECT Id, Name, Description, ContentType, Type \"\n+            \"FROM Document \"\n+            \"WHERE FolderId='{}' AND IsDeleted=false\",\n+            folder_id\n+        )\n+        return [convert_sf_record(r) for r in res['records']]\n+\n+    @lru_cache(100, cache=DOCS_DOWNLOAD_CACHE)\n+    def get_crew_document_metadata(self, document_id):\n+        \"\"\"retrieve metadata of a crew document\n+\n+        Does not check any permissions, but returns data that can be used to do\n+        so.\n+        \"\"\"\n+        # allow errors from this to bubble up, handle them in the calling\n+        # context\n+        res = self.Document.get(document_id)\n+        metadata = convert_sf_record(res)\n+\n+        # build a cache_key that will be used for the file download itself\n+        key_fields = ['systemmodstamp', 'contenttype', 'bodylength',\n+                      'developername']","path":"src/vms/salesforce_client.py","position":47,"original_position":47,"commit_id":"4c64eabcfdfa7a40b0c4b0bbae1cf896a5d37b33","original_commit_id":"4c64eabcfdfa7a40b0c4b0bbae1cf896a5d37b33","user":{"login":"davisagli","id":49014,"avatar_url":"https://avatars.githubusercontent.com/u/49014?v=3","gravatar_id":"","url":"https://api.github.com/users/davisagli","html_url":"https://github.com/davisagli","followers_url":"https://api.github.com/users/davisagli/followers","following_url":"https://api.github.com/users/davisagli/following{/other_user}","gists_url":"https://api.github.com/users/davisagli/gists{/gist_id}","starred_url":"https://api.github.com/users/davisagli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davisagli/subscriptions","organizations_url":"https://api.github.com/users/davisagli/orgs","repos_url":"https://api.github.com/users/davisagli/repos","events_url":"https://api.github.com/users/davisagli/events{/privacy}","received_events_url":"https://api.github.com/users/davisagli/received_events","type":"User","site_admin":false},"body":"Can't we obtain all these fields in get_crew_documents? And then when it's time to build the key use those cached results rather than needing a separate SF call to get the document metadata?","created_at":"2015-05-29T17:10:35Z","updated_at":"2015-05-29T17:10:35Z","html_url":"https://github.com/washingtontrails/vms/pull/115#discussion_r31344085","pull_request_url":"https://api.github.com/repos/washingtontrails/vms/pulls/115","_links":{"self":{"href":"https://api.github.com/repos/washingtontrails/vms/pulls/comments/31344085"},"html":{"href":"https://github.com/washingtontrails/vms/pull/115#discussion_r31344085"},"pull_request":{"href":"https://api.github.com/repos/washingtontrails/vms/pulls/115"}}},"pull_request":{"url":"https://api.github.com/repos/washingtontrails/vms/pulls/115","id":36468695,"html_url":"https://github.com/washingtontrails/vms/pull/115","diff_url":"https://github.com/washingtontrails/vms/pull/115.diff","patch_url":"https://github.com/washingtontrails/vms/pull/115.patch","issue_url":"https://api.github.com/repos/washingtontrails/vms/issues/115","number":115,"state":"open","locked":false,"title":"WIP: Features/crew documents","user":{"login":"cewing","id":417109,"avatar_url":"https://avatars.githubusercontent.com/u/417109?v=3","gravatar_id":"","url":"https://api.github.com/users/cewing","html_url":"https://github.com/cewing","followers_url":"https://api.github.com/users/cewing/followers","following_url":"https://api.github.com/users/cewing/following{/other_user}","gists_url":"https://api.github.com/users/cewing/gists{/gist_id}","starred_url":"https://api.github.com/users/cewing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cewing/subscriptions","organizations_url":"https://api.github.com/users/cewing/orgs","repos_url":"https://api.github.com/users/cewing/repos","events_url":"https://api.github.com/users/cewing/events{/privacy}","received_events_url":"https://api.github.com/users/cewing/received_events","type":"User","site_admin":false},"body":"@davisagli, please review this approach.  I have not yet fixed the problems with test failures that arise from the SF work here, but will do so before this PR is complete.  \r\n\r\nIn particular I'd appreciate attention to the caching that happens, and for how long various parts of the process are cached:\r\n\r\n1.  Metadata for displaying available file downloads is cached in LRU by sf folder id for two hours \r\n2.  Metadata used to calculate file downloads is cached in LRU by sf document id for two hours\r\n3.  the filepath from which to serve a given downloadable file is cached in LRU by document id and \"key\" for 1 year (the key is a hash of the file's name, last modified date, byte size and content type)\r\n4.  the download response has cache control headers allowing for a file to be cached for 30 in HTTP cache.","created_at":"2015-05-29T02:18:05Z","updated_at":"2015-05-29T17:10:36Z","closed_at":null,"merged_at":null,"merge_commit_sha":"da22b7f3a90f373b0a8ffe5a06d7342ecf76f6a7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/washingtontrails/vms/pulls/115/commits","review_comments_url":"https://api.github.com/repos/washingtontrails/vms/pulls/115/comments","review_comment_url":"https://api.github.com/repos/washingtontrails/vms/pulls/comments{/number}","comments_url":"https://api.github.com/repos/washingtontrails/vms/issues/115/comments","statuses_url":"https://api.github.com/repos/washingtontrails/vms/statuses/4c64eabcfdfa7a40b0c4b0bbae1cf896a5d37b33","head":{"label":"washingtontrails:features/crew_documents","ref":"features/crew_documents","sha":"4c64eabcfdfa7a40b0c4b0bbae1cf896a5d37b33","user":{"login":"washingtontrails","id":955676,"avatar_url":"https://avatars.githubusercontent.com/u/955676?v=3","gravatar_id":"","url":"https://api.github.com/users/washingtontrails","html_url":"https://github.com/washingtontrails","followers_url":"https://api.github.com/users/washingtontrails/followers","following_url":"https://api.github.com/users/washingtontrails/following{/other_user}","gists_url":"https://api.github.com/users/washingtontrails/gists{/gist_id}","starred_url":"https://api.github.com/users/washingtontrails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/washingtontrails/subscriptions","organizations_url":"https://api.github.com/users/washingtontrails/orgs","repos_url":"https://api.github.com/users/washingtontrails/repos","events_url":"https://api.github.com/users/washingtontrails/events{/privacy}","received_events_url":"https://api.github.com/users/washingtontrails/received_events","type":"Organization","site_admin":false},"repo":{"id":29159012,"name":"vms","full_name":"washingtontrails/vms","owner":{"login":"washingtontrails","id":955676,"avatar_url":"https://avatars.githubusercontent.com/u/955676?v=3","gravatar_id":"","url":"https://api.github.com/users/washingtontrails","html_url":"https://github.com/washingtontrails","followers_url":"https://api.github.com/users/washingtontrails/followers","following_url":"https://api.github.com/users/washingtontrails/following{/other_user}","gists_url":"https://api.github.com/users/washingtontrails/gists{/gist_id}","starred_url":"https://api.github.com/users/washingtontrails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/washingtontrails/subscriptions","organizations_url":"https://api.github.com/users/washingtontrails/orgs","repos_url":"https://api.github.com/users/washingtontrails/repos","events_url":"https://api.github.com/users/washingtontrails/events{/privacy}","received_events_url":"https://api.github.com/users/washingtontrails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/washingtontrails/vms","description":"Volunteer Management System","fork":false,"url":"https://api.github.com/repos/washingtontrails/vms","forks_url":"https://api.github.com/repos/washingtontrails/vms/forks","keys_url":"https://api.github.com/repos/washingtontrails/vms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/washingtontrails/vms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/washingtontrails/vms/teams","hooks_url":"https://api.github.com/repos/washingtontrails/vms/hooks","issue_events_url":"https://api.github.com/repos/washingtontrails/vms/issues/events{/number}","events_url":"https://api.github.com/repos/washingtontrails/vms/events","assignees_url":"https://api.github.com/repos/washingtontrails/vms/assignees{/user}","branches_url":"https://api.github.com/repos/washingtontrails/vms/branches{/branch}","tags_url":"https://api.github.com/repos/washingtontrails/vms/tags","blobs_url":"https://api.github.com/repos/washingtontrails/vms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/washingtontrails/vms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/washingtontrails/vms/git/refs{/sha}","trees_url":"https://api.github.com/repos/washingtontrails/vms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/washingtontrails/vms/statuses/{sha}","languages_url":"https://api.github.com/repos/washingtontrails/vms/languages","stargazers_url":"https://api.github.com/repos/washingtontrails/vms/stargazers","contributors_url":"https://api.github.com/repos/washingtontrails/vms/contributors","subscribers_url":"https://api.github.com/repos/washingtontrails/vms/subscribers","subscription_url":"https://api.github.com/repos/washingtontrails/vms/subscription","commits_url":"https://api.github.com/repos/washingtontrails/vms/commits{/sha}","git_commits_url":"https://api.github.com/repos/washingtontrails/vms/git/commits{/sha}","comments_url":"https://api.github.com/repos/washingtontrails/vms/comments{/number}","issue_comment_url":"https://api.github.com/repos/washingtontrails/vms/issues/comments{/number}","contents_url":"https://api.github.com/repos/washingtontrails/vms/contents/{+path}","compare_url":"https://api.github.com/repos/washingtontrails/vms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/washingtontrails/vms/merges","archive_url":"https://api.github.com/repos/washingtontrails/vms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/washingtontrails/vms/downloads","issues_url":"https://api.github.com/repos/washingtontrails/vms/issues{/number}","pulls_url":"https://api.github.com/repos/washingtontrails/vms/pulls{/number}","milestones_url":"https://api.github.com/repos/washingtontrails/vms/milestones{/number}","notifications_url":"https://api.github.com/repos/washingtontrails/vms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/washingtontrails/vms/labels{/name}","releases_url":"https://api.github.com/repos/washingtontrails/vms/releases{/id}","created_at":"2015-01-12T21:55:40Z","updated_at":"2015-05-07T02:03:05Z","pushed_at":"2015-05-29T03:16:11Z","git_url":"git://github.com/washingtontrails/vms.git","ssh_url":"git@github.com:washingtontrails/vms.git","clone_url":"https://github.com/washingtontrails/vms.git","svn_url":"https://github.com/washingtontrails/vms","homepage":null,"size":5872,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":33,"forks":0,"open_issues":33,"watchers":2,"default_branch":"master"}},"base":{"label":"washingtontrails:master","ref":"master","sha":"796ee22617bbedae164a940c6dc3b8b369b257ad","user":{"login":"washingtontrails","id":955676,"avatar_url":"https://avatars.githubusercontent.com/u/955676?v=3","gravatar_id":"","url":"https://api.github.com/users/washingtontrails","html_url":"https://github.com/washingtontrails","followers_url":"https://api.github.com/users/washingtontrails/followers","following_url":"https://api.github.com/users/washingtontrails/following{/other_user}","gists_url":"https://api.github.com/users/washingtontrails/gists{/gist_id}","starred_url":"https://api.github.com/users/washingtontrails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/washingtontrails/subscriptions","organizations_url":"https://api.github.com/users/washingtontrails/orgs","repos_url":"https://api.github.com/users/washingtontrails/repos","events_url":"https://api.github.com/users/washingtontrails/events{/privacy}","received_events_url":"https://api.github.com/users/washingtontrails/received_events","type":"Organization","site_admin":false},"repo":{"id":29159012,"name":"vms","full_name":"washingtontrails/vms","owner":{"login":"washingtontrails","id":955676,"avatar_url":"https://avatars.githubusercontent.com/u/955676?v=3","gravatar_id":"","url":"https://api.github.com/users/washingtontrails","html_url":"https://github.com/washingtontrails","followers_url":"https://api.github.com/users/washingtontrails/followers","following_url":"https://api.github.com/users/washingtontrails/following{/other_user}","gists_url":"https://api.github.com/users/washingtontrails/gists{/gist_id}","starred_url":"https://api.github.com/users/washingtontrails/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/washingtontrails/subscriptions","organizations_url":"https://api.github.com/users/washingtontrails/orgs","repos_url":"https://api.github.com/users/washingtontrails/repos","events_url":"https://api.github.com/users/washingtontrails/events{/privacy}","received_events_url":"https://api.github.com/users/washingtontrails/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/washingtontrails/vms","description":"Volunteer Management System","fork":false,"url":"https://api.github.com/repos/washingtontrails/vms","forks_url":"https://api.github.com/repos/washingtontrails/vms/forks","keys_url":"https://api.github.com/repos/washingtontrails/vms/keys{/key_id}","collaborators_url":"https://api.github.com/repos/washingtontrails/vms/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/washingtontrails/vms/teams","hooks_url":"https://api.github.com/repos/washingtontrails/vms/hooks","issue_events_url":"https://api.github.com/repos/washingtontrails/vms/issues/events{/number}","events_url":"https://api.github.com/repos/washingtontrails/vms/events","assignees_url":"https://api.github.com/repos/washingtontrails/vms/assignees{/user}","branches_url":"https://api.github.com/repos/washingtontrails/vms/branches{/branch}","tags_url":"https://api.github.com/repos/washingtontrails/vms/tags","blobs_url":"https://api.github.com/repos/washingtontrails/vms/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/washingtontrails/vms/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/washingtontrails/vms/git/refs{/sha}","trees_url":"https://api.github.com/repos/washingtontrails/vms/git/trees{/sha}","statuses_url":"https://api.github.com/repos/washingtontrails/vms/statuses/{sha}","languages_url":"https://api.github.com/repos/washingtontrails/vms/languages","stargazers_url":"https://api.github.com/repos/washingtontrails/vms/stargazers","contributors_url":"https://api.github.com/repos/washingtontrails/vms/contributors","subscribers_url":"https://api.github.com/repos/washingtontrails/vms/subscribers","subscription_url":"https://api.github.com/repos/washingtontrails/vms/subscription","commits_url":"https://api.github.com/repos/washingtontrails/vms/commits{/sha}","git_commits_url":"https://api.github.com/repos/washingtontrails/vms/git/commits{/sha}","comments_url":"https://api.github.com/repos/washingtontrails/vms/comments{/number}","issue_comment_url":"https://api.github.com/repos/washingtontrails/vms/issues/comments{/number}","contents_url":"https://api.github.com/repos/washingtontrails/vms/contents/{+path}","compare_url":"https://api.github.com/repos/washingtontrails/vms/compare/{base}...{head}","merges_url":"https://api.github.com/repos/washingtontrails/vms/merges","archive_url":"https://api.github.com/repos/washingtontrails/vms/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/washingtontrails/vms/downloads","issues_url":"https://api.github.com/repos/washingtontrails/vms/issues{/number}","pulls_url":"https://api.github.com/repos/washingtontrails/vms/pulls{/number}","milestones_url":"https://api.github.com/repos/washingtontrails/vms/milestones{/number}","notifications_url":"https://api.github.com/repos/washingtontrails/vms/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/washingtontrails/vms/labels{/name}","releases_url":"https://api.github.com/repos/washingtontrails/vms/releases{/id}","created_at":"2015-01-12T21:55:40Z","updated_at":"2015-05-07T02:03:05Z","pushed_at":"2015-05-29T03:16:11Z","git_url":"git://github.com/washingtontrails/vms.git","ssh_url":"git@github.com:washingtontrails/vms.git","clone_url":"https://github.com/washingtontrails/vms.git","svn_url":"https://github.com/washingtontrails/vms","homepage":null,"size":5872,"stargazers_count":2,"watchers_count":2,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":33,"forks":0,"open_issues":33,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/washingtontrails/vms/pulls/115"},"html":{"href":"https://github.com/washingtontrails/vms/pull/115"},"issue":{"href":"https://api.github.com/repos/washingtontrails/vms/issues/115"},"comments":{"href":"https://api.github.com/repos/washingtontrails/vms/issues/115/comments"},"review_comments":{"href":"https://api.github.com/repos/washingtontrails/vms/pulls/115/comments"},"review_comment":{"href":"https://api.github.com/repos/washingtontrails/vms/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/washingtontrails/vms/pulls/115/commits"},"statuses":{"href":"https://api.github.com/repos/washingtontrails/vms/statuses/4c64eabcfdfa7a40b0c4b0bbae1cf896a5d37b33"}}}}