{"action":"created","comment":{"url":"https://api.github.com/repos/learningequality/ka-lite/pulls/comments/35056371","id":35056371,"diff_hunk":"@@ -67,6 +78,20 @@ def get_topic_tree(force=False, annotate=False, channel=None, language=None, par\n         TOPICS = {}\n     if TOPICS.get(channel) is None:\n         TOPICS[channel] = {}\n+\n+    if settings.DO_NOT_RELOAD_CONTENT_CACHE_AT_STARTUP and not force:","path":"kalite/topic_tools/__init__.py","position":29,"original_position":29,"commit_id":"10fe718da75188d253ac9d43fb5a523e85278824","original_commit_id":"10fe718da75188d253ac9d43fb5a523e85278824","user":{"login":"MCGallaspy","id":8888020,"avatar_url":"https://avatars.githubusercontent.com/u/8888020?v=3","gravatar_id":"","url":"https://api.github.com/users/MCGallaspy","html_url":"https://github.com/MCGallaspy","followers_url":"https://api.github.com/users/MCGallaspy/followers","following_url":"https://api.github.com/users/MCGallaspy/following{/other_user}","gists_url":"https://api.github.com/users/MCGallaspy/gists{/gist_id}","starred_url":"https://api.github.com/users/MCGallaspy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MCGallaspy/subscriptions","organizations_url":"https://api.github.com/users/MCGallaspy/orgs","repos_url":"https://api.github.com/users/MCGallaspy/repos","events_url":"https://api.github.com/users/MCGallaspy/events{/privacy}","received_events_url":"https://api.github.com/users/MCGallaspy/received_events","type":"User","site_admin":false},"body":"Yeah, I see what you mean. But now you will call `softload_json` every time `force` is `False` (if this setting is enabled). Seems like the intended behavior of the original version is something like this:\r\n\r\n1. If `TOPICS[channel][language]` doesn't exist, then load the _un_-annotated version from disk, then annotate it.\r\n2. If you must annotate the `TOPICS[channel][language]`, under certain conditions (`settings.DO_NOT_RELOAD_CONTENT_CACHE_AT_STARTUP and not force`) first check if the annotated version is cached, and load the cache if it is.\r\n3. In all other cases, do something else.\r\n\r\nIn order to preserve this behavior but cut out the unnecessary `softload_json` that you identified, I think it should be like this:\r\n\r\n```python\r\ndef get_topic_tree(force=False, annotate=False, channel=None, language=None, parent=None):\r\n    \r\n    # Hardcode the Brazilian Portuguese mapping that only the central server knows about\r\n    # TODO(jamalex): BURN IT ALL DOWN!\r\n    if language == \"pt-BR\":\r\n        language = \"pt\"\r\n\r\n    if not channel:\r\n        channel = django_settings.CHANNEL\r\n\r\n    if not language:\r\n        language = django_settings.LANGUAGE_CODE\r\n\r\n    global TOPICS\r\n    if not TOPICS:\r\n        TOPICS = {}\r\n    if TOPICS.get(channel) is None:\r\n        TOPICS[channel] = {}\r\n    \r\n    if annotate or TOPICS.get(channel, {}).get(language) is None:\r\n        if settings.DO_NOT_RELOAD_CONTENT_CACHE_AT_STARTUP and not force:\r\n            cached_topics = softload_json(\r\n                cache_file_path(\"topic_{0}_{1}.json\".format(channel, language)),\r\n                logger=logging.debug,\r\n                raises=False\r\n            )\r\n        if cached_topics:\r\n            TOPICS[channel][language] = cached_topics\r\n            annotate = False\r\n            # Get rid of this and let it drop down to similar statement below\r\n            #if parent:\r\n            #    return filter(lambda x: x.get(\"parent\") == parent, cached_topics)\r\n            #else:\r\n            #    return cached_topics\r\n        else:\r\n            topics = softload_json(settings.TOPICS_FILEPATHS.get(channel), logger=logging.debug, raises=False)\r\n            # Just loaded from disk, so have to restamp.\r\n            annotate = True\r\n\r\n    if annotate:\r\n        flat_topic_tree = []\r\n\r\n        # Loop through all the nodes in the topic tree\r\n        # and cross reference with the content_cache to check availability.\r\n        content_cache = get_content_cache(language=language)\r\n        exercise_cache = get_exercise_cache(language=language)\r\n```","created_at":"2015-07-20T23:32:11Z","updated_at":"2015-07-20T23:32:11Z","html_url":"https://github.com/learningequality/ka-lite/pull/4122#discussion_r35056371","pull_request_url":"https://api.github.com/repos/learningequality/ka-lite/pulls/4122","_links":{"self":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/comments/35056371"},"html":{"href":"https://github.com/learningequality/ka-lite/pull/4122#discussion_r35056371"},"pull_request":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/4122"}}},"pull_request":{"url":"https://api.github.com/repos/learningequality/ka-lite/pulls/4122","id":40348357,"html_url":"https://github.com/learningequality/ka-lite/pull/4122","diff_url":"https://github.com/learningequality/ka-lite/pull/4122.diff","patch_url":"https://github.com/learningequality/ka-lite/pull/4122.patch","issue_url":"https://api.github.com/repos/learningequality/ka-lite/issues/4122","number":4122,"state":"open","locked":false,"title":"Write cache data in user space #4109","user":{"login":"benjaoming","id":374612,"avatar_url":"https://avatars.githubusercontent.com/u/374612?v=3","gravatar_id":"","url":"https://api.github.com/users/benjaoming","html_url":"https://github.com/benjaoming","followers_url":"https://api.github.com/users/benjaoming/followers","following_url":"https://api.github.com/users/benjaoming/following{/other_user}","gists_url":"https://api.github.com/users/benjaoming/gists{/gist_id}","starred_url":"https://api.github.com/users/benjaoming/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjaoming/subscriptions","organizations_url":"https://api.github.com/users/benjaoming/orgs","repos_url":"https://api.github.com/users/benjaoming/repos","events_url":"https://api.github.com/users/benjaoming/events{/privacy}","received_events_url":"https://api.github.com/users/benjaoming/received_events","type":"User","site_admin":false},"body":"Resolves #4109.","created_at":"2015-07-20T12:51:51Z","updated_at":"2015-07-20T23:32:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7a19c36a66efff120f5d65e56b785531c5dced66","assignee":{"login":"rtibbles","id":1680573,"avatar_url":"https://avatars.githubusercontent.com/u/1680573?v=3","gravatar_id":"","url":"https://api.github.com/users/rtibbles","html_url":"https://github.com/rtibbles","followers_url":"https://api.github.com/users/rtibbles/followers","following_url":"https://api.github.com/users/rtibbles/following{/other_user}","gists_url":"https://api.github.com/users/rtibbles/gists{/gist_id}","starred_url":"https://api.github.com/users/rtibbles/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtibbles/subscriptions","organizations_url":"https://api.github.com/users/rtibbles/orgs","repos_url":"https://api.github.com/users/rtibbles/repos","events_url":"https://api.github.com/users/rtibbles/events{/privacy}","received_events_url":"https://api.github.com/users/rtibbles/received_events","type":"User","site_admin":false},"milestone":{"url":"https://api.github.com/repos/learningequality/ka-lite/milestones/41","html_url":"https://github.com/learningequality/ka-lite/milestones/0.14.0","labels_url":"https://api.github.com/repos/learningequality/ka-lite/milestones/41/labels","id":795036,"number":41,"title":"0.14.0","description":"","creator":{"login":"aronasorman","id":191955,"avatar_url":"https://avatars.githubusercontent.com/u/191955?v=3","gravatar_id":"","url":"https://api.github.com/users/aronasorman","html_url":"https://github.com/aronasorman","followers_url":"https://api.github.com/users/aronasorman/followers","following_url":"https://api.github.com/users/aronasorman/following{/other_user}","gists_url":"https://api.github.com/users/aronasorman/gists{/gist_id}","starred_url":"https://api.github.com/users/aronasorman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aronasorman/subscriptions","organizations_url":"https://api.github.com/users/aronasorman/orgs","repos_url":"https://api.github.com/users/aronasorman/repos","events_url":"https://api.github.com/users/aronasorman/events{/privacy}","received_events_url":"https://api.github.com/users/aronasorman/received_events","type":"User","site_admin":false},"open_issues":31,"closed_issues":434,"state":"open","created_at":"2014-09-18T21:53:07Z","updated_at":"2015-07-20T22:43:11Z","due_on":"2015-07-01T07:00:00Z","closed_at":null},"commits_url":"https://api.github.com/repos/learningequality/ka-lite/pulls/4122/commits","review_comments_url":"https://api.github.com/repos/learningequality/ka-lite/pulls/4122/comments","review_comment_url":"https://api.github.com/repos/learningequality/ka-lite/pulls/comments{/number}","comments_url":"https://api.github.com/repos/learningequality/ka-lite/issues/4122/comments","statuses_url":"https://api.github.com/repos/learningequality/ka-lite/statuses/10fe718da75188d253ac9d43fb5a523e85278824","head":{"label":"benjaoming:user-data-cache-files","ref":"user-data-cache-files","sha":"10fe718da75188d253ac9d43fb5a523e85278824","user":{"login":"benjaoming","id":374612,"avatar_url":"https://avatars.githubusercontent.com/u/374612?v=3","gravatar_id":"","url":"https://api.github.com/users/benjaoming","html_url":"https://github.com/benjaoming","followers_url":"https://api.github.com/users/benjaoming/followers","following_url":"https://api.github.com/users/benjaoming/following{/other_user}","gists_url":"https://api.github.com/users/benjaoming/gists{/gist_id}","starred_url":"https://api.github.com/users/benjaoming/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjaoming/subscriptions","organizations_url":"https://api.github.com/users/benjaoming/orgs","repos_url":"https://api.github.com/users/benjaoming/repos","events_url":"https://api.github.com/users/benjaoming/events{/privacy}","received_events_url":"https://api.github.com/users/benjaoming/received_events","type":"User","site_admin":false},"repo":{"id":29163611,"name":"ka-lite","full_name":"benjaoming/ka-lite","owner":{"login":"benjaoming","id":374612,"avatar_url":"https://avatars.githubusercontent.com/u/374612?v=3","gravatar_id":"","url":"https://api.github.com/users/benjaoming","html_url":"https://github.com/benjaoming","followers_url":"https://api.github.com/users/benjaoming/followers","following_url":"https://api.github.com/users/benjaoming/following{/other_user}","gists_url":"https://api.github.com/users/benjaoming/gists{/gist_id}","starred_url":"https://api.github.com/users/benjaoming/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjaoming/subscriptions","organizations_url":"https://api.github.com/users/benjaoming/orgs","repos_url":"https://api.github.com/users/benjaoming/repos","events_url":"https://api.github.com/users/benjaoming/events{/privacy}","received_events_url":"https://api.github.com/users/benjaoming/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/benjaoming/ka-lite","description":"KA Lite: lightweight web server for serving core Khan Academy content (videos and exercises) without needing internet connectivity","fork":true,"url":"https://api.github.com/repos/benjaoming/ka-lite","forks_url":"https://api.github.com/repos/benjaoming/ka-lite/forks","keys_url":"https://api.github.com/repos/benjaoming/ka-lite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/benjaoming/ka-lite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/benjaoming/ka-lite/teams","hooks_url":"https://api.github.com/repos/benjaoming/ka-lite/hooks","issue_events_url":"https://api.github.com/repos/benjaoming/ka-lite/issues/events{/number}","events_url":"https://api.github.com/repos/benjaoming/ka-lite/events","assignees_url":"https://api.github.com/repos/benjaoming/ka-lite/assignees{/user}","branches_url":"https://api.github.com/repos/benjaoming/ka-lite/branches{/branch}","tags_url":"https://api.github.com/repos/benjaoming/ka-lite/tags","blobs_url":"https://api.github.com/repos/benjaoming/ka-lite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/benjaoming/ka-lite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/benjaoming/ka-lite/git/refs{/sha}","trees_url":"https://api.github.com/repos/benjaoming/ka-lite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/benjaoming/ka-lite/statuses/{sha}","languages_url":"https://api.github.com/repos/benjaoming/ka-lite/languages","stargazers_url":"https://api.github.com/repos/benjaoming/ka-lite/stargazers","contributors_url":"https://api.github.com/repos/benjaoming/ka-lite/contributors","subscribers_url":"https://api.github.com/repos/benjaoming/ka-lite/subscribers","subscription_url":"https://api.github.com/repos/benjaoming/ka-lite/subscription","commits_url":"https://api.github.com/repos/benjaoming/ka-lite/commits{/sha}","git_commits_url":"https://api.github.com/repos/benjaoming/ka-lite/git/commits{/sha}","comments_url":"https://api.github.com/repos/benjaoming/ka-lite/comments{/number}","issue_comment_url":"https://api.github.com/repos/benjaoming/ka-lite/issues/comments{/number}","contents_url":"https://api.github.com/repos/benjaoming/ka-lite/contents/{+path}","compare_url":"https://api.github.com/repos/benjaoming/ka-lite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/benjaoming/ka-lite/merges","archive_url":"https://api.github.com/repos/benjaoming/ka-lite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/benjaoming/ka-lite/downloads","issues_url":"https://api.github.com/repos/benjaoming/ka-lite/issues{/number}","pulls_url":"https://api.github.com/repos/benjaoming/ka-lite/pulls{/number}","milestones_url":"https://api.github.com/repos/benjaoming/ka-lite/milestones{/number}","notifications_url":"https://api.github.com/repos/benjaoming/ka-lite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/benjaoming/ka-lite/labels{/name}","releases_url":"https://api.github.com/repos/benjaoming/ka-lite/releases{/id}","created_at":"2015-01-13T00:04:53Z","updated_at":"2015-04-05T18:11:24Z","pushed_at":"2015-07-20T22:52:15Z","git_url":"git://github.com/benjaoming/ka-lite.git","ssh_url":"git@github.com:benjaoming/ka-lite.git","clone_url":"https://github.com/benjaoming/ka-lite.git","svn_url":"https://github.com/benjaoming/ka-lite","homepage":"https://learningequality.org/ka-lite/","size":157603,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"learningequality:0.14.x","ref":"0.14.x","sha":"8abd359c62a2b7112e52f8f5ef71a341f6f5c17b","user":{"login":"learningequality","id":3926525,"avatar_url":"https://avatars.githubusercontent.com/u/3926525?v=3","gravatar_id":"","url":"https://api.github.com/users/learningequality","html_url":"https://github.com/learningequality","followers_url":"https://api.github.com/users/learningequality/followers","following_url":"https://api.github.com/users/learningequality/following{/other_user}","gists_url":"https://api.github.com/users/learningequality/gists{/gist_id}","starred_url":"https://api.github.com/users/learningequality/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/learningequality/subscriptions","organizations_url":"https://api.github.com/users/learningequality/orgs","repos_url":"https://api.github.com/users/learningequality/repos","events_url":"https://api.github.com/users/learningequality/events{/privacy}","received_events_url":"https://api.github.com/users/learningequality/received_events","type":"Organization","site_admin":false},"repo":{"id":5741125,"name":"ka-lite","full_name":"learningequality/ka-lite","owner":{"login":"learningequality","id":3926525,"avatar_url":"https://avatars.githubusercontent.com/u/3926525?v=3","gravatar_id":"","url":"https://api.github.com/users/learningequality","html_url":"https://github.com/learningequality","followers_url":"https://api.github.com/users/learningequality/followers","following_url":"https://api.github.com/users/learningequality/following{/other_user}","gists_url":"https://api.github.com/users/learningequality/gists{/gist_id}","starred_url":"https://api.github.com/users/learningequality/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/learningequality/subscriptions","organizations_url":"https://api.github.com/users/learningequality/orgs","repos_url":"https://api.github.com/users/learningequality/repos","events_url":"https://api.github.com/users/learningequality/events{/privacy}","received_events_url":"https://api.github.com/users/learningequality/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/learningequality/ka-lite","description":"KA Lite: lightweight web server for serving core Khan Academy content (videos and exercises) without needing internet connectivity","fork":false,"url":"https://api.github.com/repos/learningequality/ka-lite","forks_url":"https://api.github.com/repos/learningequality/ka-lite/forks","keys_url":"https://api.github.com/repos/learningequality/ka-lite/keys{/key_id}","collaborators_url":"https://api.github.com/repos/learningequality/ka-lite/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/learningequality/ka-lite/teams","hooks_url":"https://api.github.com/repos/learningequality/ka-lite/hooks","issue_events_url":"https://api.github.com/repos/learningequality/ka-lite/issues/events{/number}","events_url":"https://api.github.com/repos/learningequality/ka-lite/events","assignees_url":"https://api.github.com/repos/learningequality/ka-lite/assignees{/user}","branches_url":"https://api.github.com/repos/learningequality/ka-lite/branches{/branch}","tags_url":"https://api.github.com/repos/learningequality/ka-lite/tags","blobs_url":"https://api.github.com/repos/learningequality/ka-lite/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/learningequality/ka-lite/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/learningequality/ka-lite/git/refs{/sha}","trees_url":"https://api.github.com/repos/learningequality/ka-lite/git/trees{/sha}","statuses_url":"https://api.github.com/repos/learningequality/ka-lite/statuses/{sha}","languages_url":"https://api.github.com/repos/learningequality/ka-lite/languages","stargazers_url":"https://api.github.com/repos/learningequality/ka-lite/stargazers","contributors_url":"https://api.github.com/repos/learningequality/ka-lite/contributors","subscribers_url":"https://api.github.com/repos/learningequality/ka-lite/subscribers","subscription_url":"https://api.github.com/repos/learningequality/ka-lite/subscription","commits_url":"https://api.github.com/repos/learningequality/ka-lite/commits{/sha}","git_commits_url":"https://api.github.com/repos/learningequality/ka-lite/git/commits{/sha}","comments_url":"https://api.github.com/repos/learningequality/ka-lite/comments{/number}","issue_comment_url":"https://api.github.com/repos/learningequality/ka-lite/issues/comments{/number}","contents_url":"https://api.github.com/repos/learningequality/ka-lite/contents/{+path}","compare_url":"https://api.github.com/repos/learningequality/ka-lite/compare/{base}...{head}","merges_url":"https://api.github.com/repos/learningequality/ka-lite/merges","archive_url":"https://api.github.com/repos/learningequality/ka-lite/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/learningequality/ka-lite/downloads","issues_url":"https://api.github.com/repos/learningequality/ka-lite/issues{/number}","pulls_url":"https://api.github.com/repos/learningequality/ka-lite/pulls{/number}","milestones_url":"https://api.github.com/repos/learningequality/ka-lite/milestones{/number}","notifications_url":"https://api.github.com/repos/learningequality/ka-lite/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/learningequality/ka-lite/labels{/name}","releases_url":"https://api.github.com/repos/learningequality/ka-lite/releases{/id}","created_at":"2012-09-09T20:01:40Z","updated_at":"2015-07-20T20:51:23Z","pushed_at":"2015-07-20T23:11:17Z","git_url":"git://github.com/learningequality/ka-lite.git","ssh_url":"git@github.com:learningequality/ka-lite.git","clone_url":"https://github.com/learningequality/ka-lite.git","svn_url":"https://github.com/learningequality/ka-lite","homepage":"https://learningequality.org/ka-lite/","size":234445,"stargazers_count":221,"watchers_count":221,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":254,"mirror_url":null,"open_issues_count":262,"forks":254,"open_issues":262,"watchers":221,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/4122"},"html":{"href":"https://github.com/learningequality/ka-lite/pull/4122"},"issue":{"href":"https://api.github.com/repos/learningequality/ka-lite/issues/4122"},"comments":{"href":"https://api.github.com/repos/learningequality/ka-lite/issues/4122/comments"},"review_comments":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/4122/comments"},"review_comment":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/learningequality/ka-lite/pulls/4122/commits"},"statuses":{"href":"https://api.github.com/repos/learningequality/ka-lite/statuses/10fe718da75188d253ac9d43fb5a523e85278824"}}}}