{"action":"created","comment":{"url":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/comments/56192452","id":56192452,"diff_hunk":"@@ -445,36 +445,34 @@ public long getCurrentModelId() {\n      * @return the mid of the model in Anki\n      */\n     public Long findModelIdByName(String modelName, int numFields) {\n+        SharedPreferences modelsDb = mContext.getSharedPreferences(MODEL_REF_DB, Context.MODE_PRIVATE);\n+        long prefsModelId = modelsDb.getLong(modelName, -1L);\n         // Build list of all models with modelName and at least numFields\n         Map<Long, String> modelList = getModelList(numFields);\n-        ArrayList<Long> foundModels = new ArrayList<>();\n+        long bestModelIdSoFar = -1L;\n         for (Map.Entry<Long, String> entry : modelList.entrySet()) {\n             if (entry.getValue().equals(modelName)) {\n-                foundModels.add(entry.getKey());\n+                long id = entry.getKey();\n+                if (id == prefsModelId) {\n+                    return id; // there is a model with the right name and same id as in prefs","path":"api/src/main/java/com/ichi2/anki/api/AddContentApi.java","position":15,"original_position":15,"commit_id":"74c741aae6d8ddb177be32298d80ba12c74b9e0d","original_commit_id":"74c741aae6d8ddb177be32298d80ba12c74b9e0d","user":{"login":"marcardar","id":409640,"avatar_url":"https://avatars.githubusercontent.com/u/409640?v=3","gravatar_id":"","url":"https://api.github.com/users/marcardar","html_url":"https://github.com/marcardar","followers_url":"https://api.github.com/users/marcardar/followers","following_url":"https://api.github.com/users/marcardar/following{/other_user}","gists_url":"https://api.github.com/users/marcardar/gists{/gist_id}","starred_url":"https://api.github.com/users/marcardar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcardar/subscriptions","organizations_url":"https://api.github.com/users/marcardar/orgs","repos_url":"https://api.github.com/users/marcardar/repos","events_url":"https://api.github.com/users/marcardar/events{/privacy}","received_events_url":"https://api.github.com/users/marcardar/received_events","type":"User","site_admin":false},"body":"Yes, I know ;)","created_at":"2016-03-15T16:19:48Z","updated_at":"2016-03-15T16:19:48Z","html_url":"https://github.com/ankidroid/Anki-Android/pull/4138#discussion_r56192452","pull_request_url":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/4138","_links":{"self":{"href":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/comments/56192452"},"html":{"href":"https://github.com/ankidroid/Anki-Android/pull/4138#discussion_r56192452"},"pull_request":{"href":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/4138"}}},"pull_request":{"url":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/4138","id":62931416,"html_url":"https://github.com/ankidroid/Anki-Android/pull/4138","diff_url":"https://github.com/ankidroid/Anki-Android/pull/4138.diff","patch_url":"https://github.com/ankidroid/Anki-Android/pull/4138.patch","issue_url":"https://api.github.com/repos/ankidroid/Anki-Android/issues/4138","number":4138,"state":"open","locked":false,"title":"fixed findModelIdByName()","user":{"login":"marcardar","id":409640,"avatar_url":"https://avatars.githubusercontent.com/u/409640?v=3","gravatar_id":"","url":"https://api.github.com/users/marcardar","html_url":"https://github.com/marcardar","followers_url":"https://api.github.com/users/marcardar/followers","following_url":"https://api.github.com/users/marcardar/following{/other_user}","gists_url":"https://api.github.com/users/marcardar/gists{/gist_id}","starred_url":"https://api.github.com/users/marcardar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcardar/subscriptions","organizations_url":"https://api.github.com/users/marcardar/orgs","repos_url":"https://api.github.com/users/marcardar/repos","events_url":"https://api.github.com/users/marcardar/events{/privacy}","received_events_url":"https://api.github.com/users/marcardar/received_events","type":"User","site_admin":false},"body":"The existing method is broken in the situation where:\r\n\r\nThe modelName exists in the database AND in the shared preferences.\r\n\r\nThe spec says the modelId from the database should win, but in the current implementation the shared prefs id wins.","created_at":"2016-03-15T16:05:44Z","updated_at":"2016-03-15T16:19:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b753bbfad11deb9ff584334cbbbe1dc794428b8b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/4138/commits","review_comments_url":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/4138/comments","review_comment_url":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ankidroid/Anki-Android/issues/4138/comments","statuses_url":"https://api.github.com/repos/ankidroid/Anki-Android/statuses/74c741aae6d8ddb177be32298d80ba12c74b9e0d","head":{"label":"marcardar:fix-broken-find-model-id-by-name","ref":"fix-broken-find-model-id-by-name","sha":"74c741aae6d8ddb177be32298d80ba12c74b9e0d","user":{"login":"marcardar","id":409640,"avatar_url":"https://avatars.githubusercontent.com/u/409640?v=3","gravatar_id":"","url":"https://api.github.com/users/marcardar","html_url":"https://github.com/marcardar","followers_url":"https://api.github.com/users/marcardar/followers","following_url":"https://api.github.com/users/marcardar/following{/other_user}","gists_url":"https://api.github.com/users/marcardar/gists{/gist_id}","starred_url":"https://api.github.com/users/marcardar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcardar/subscriptions","organizations_url":"https://api.github.com/users/marcardar/orgs","repos_url":"https://api.github.com/users/marcardar/repos","events_url":"https://api.github.com/users/marcardar/events{/privacy}","received_events_url":"https://api.github.com/users/marcardar/received_events","type":"User","site_admin":false},"repo":{"id":52933751,"name":"Anki-Android","full_name":"marcardar/Anki-Android","owner":{"login":"marcardar","id":409640,"avatar_url":"https://avatars.githubusercontent.com/u/409640?v=3","gravatar_id":"","url":"https://api.github.com/users/marcardar","html_url":"https://github.com/marcardar","followers_url":"https://api.github.com/users/marcardar/followers","following_url":"https://api.github.com/users/marcardar/following{/other_user}","gists_url":"https://api.github.com/users/marcardar/gists{/gist_id}","starred_url":"https://api.github.com/users/marcardar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marcardar/subscriptions","organizations_url":"https://api.github.com/users/marcardar/orgs","repos_url":"https://api.github.com/users/marcardar/repos","events_url":"https://api.github.com/users/marcardar/events{/privacy}","received_events_url":"https://api.github.com/users/marcardar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/marcardar/Anki-Android","description":"AnkiDroid: Anki on Android","fork":true,"url":"https://api.github.com/repos/marcardar/Anki-Android","forks_url":"https://api.github.com/repos/marcardar/Anki-Android/forks","keys_url":"https://api.github.com/repos/marcardar/Anki-Android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/marcardar/Anki-Android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/marcardar/Anki-Android/teams","hooks_url":"https://api.github.com/repos/marcardar/Anki-Android/hooks","issue_events_url":"https://api.github.com/repos/marcardar/Anki-Android/issues/events{/number}","events_url":"https://api.github.com/repos/marcardar/Anki-Android/events","assignees_url":"https://api.github.com/repos/marcardar/Anki-Android/assignees{/user}","branches_url":"https://api.github.com/repos/marcardar/Anki-Android/branches{/branch}","tags_url":"https://api.github.com/repos/marcardar/Anki-Android/tags","blobs_url":"https://api.github.com/repos/marcardar/Anki-Android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/marcardar/Anki-Android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/marcardar/Anki-Android/git/refs{/sha}","trees_url":"https://api.github.com/repos/marcardar/Anki-Android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/marcardar/Anki-Android/statuses/{sha}","languages_url":"https://api.github.com/repos/marcardar/Anki-Android/languages","stargazers_url":"https://api.github.com/repos/marcardar/Anki-Android/stargazers","contributors_url":"https://api.github.com/repos/marcardar/Anki-Android/contributors","subscribers_url":"https://api.github.com/repos/marcardar/Anki-Android/subscribers","subscription_url":"https://api.github.com/repos/marcardar/Anki-Android/subscription","commits_url":"https://api.github.com/repos/marcardar/Anki-Android/commits{/sha}","git_commits_url":"https://api.github.com/repos/marcardar/Anki-Android/git/commits{/sha}","comments_url":"https://api.github.com/repos/marcardar/Anki-Android/comments{/number}","issue_comment_url":"https://api.github.com/repos/marcardar/Anki-Android/issues/comments{/number}","contents_url":"https://api.github.com/repos/marcardar/Anki-Android/contents/{+path}","compare_url":"https://api.github.com/repos/marcardar/Anki-Android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/marcardar/Anki-Android/merges","archive_url":"https://api.github.com/repos/marcardar/Anki-Android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/marcardar/Anki-Android/downloads","issues_url":"https://api.github.com/repos/marcardar/Anki-Android/issues{/number}","pulls_url":"https://api.github.com/repos/marcardar/Anki-Android/pulls{/number}","milestones_url":"https://api.github.com/repos/marcardar/Anki-Android/milestones{/number}","notifications_url":"https://api.github.com/repos/marcardar/Anki-Android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/marcardar/Anki-Android/labels{/name}","releases_url":"https://api.github.com/repos/marcardar/Anki-Android/releases{/id}","deployments_url":"https://api.github.com/repos/marcardar/Anki-Android/deployments","created_at":"2016-03-02T04:26:22Z","updated_at":"2016-03-02T04:26:27Z","pushed_at":"2016-03-15T16:10:33Z","git_url":"git://github.com/marcardar/Anki-Android.git","ssh_url":"git@github.com:marcardar/Anki-Android.git","clone_url":"https://github.com/marcardar/Anki-Android.git","svn_url":"https://github.com/marcardar/Anki-Android","homepage":"","size":102633,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":false,"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":"develop"}},"base":{"label":"ankidroid:develop","ref":"develop","sha":"2cfb5bdddd4865e22efe137502cae5f1304fac52","user":{"login":"ankidroid","id":3320903,"avatar_url":"https://avatars.githubusercontent.com/u/3320903?v=3","gravatar_id":"","url":"https://api.github.com/users/ankidroid","html_url":"https://github.com/ankidroid","followers_url":"https://api.github.com/users/ankidroid/followers","following_url":"https://api.github.com/users/ankidroid/following{/other_user}","gists_url":"https://api.github.com/users/ankidroid/gists{/gist_id}","starred_url":"https://api.github.com/users/ankidroid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ankidroid/subscriptions","organizations_url":"https://api.github.com/users/ankidroid/orgs","repos_url":"https://api.github.com/users/ankidroid/repos","events_url":"https://api.github.com/users/ankidroid/events{/privacy}","received_events_url":"https://api.github.com/users/ankidroid/received_events","type":"Organization","site_admin":false},"repo":{"id":7716883,"name":"Anki-Android","full_name":"ankidroid/Anki-Android","owner":{"login":"ankidroid","id":3320903,"avatar_url":"https://avatars.githubusercontent.com/u/3320903?v=3","gravatar_id":"","url":"https://api.github.com/users/ankidroid","html_url":"https://github.com/ankidroid","followers_url":"https://api.github.com/users/ankidroid/followers","following_url":"https://api.github.com/users/ankidroid/following{/other_user}","gists_url":"https://api.github.com/users/ankidroid/gists{/gist_id}","starred_url":"https://api.github.com/users/ankidroid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ankidroid/subscriptions","organizations_url":"https://api.github.com/users/ankidroid/orgs","repos_url":"https://api.github.com/users/ankidroid/repos","events_url":"https://api.github.com/users/ankidroid/events{/privacy}","received_events_url":"https://api.github.com/users/ankidroid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ankidroid/Anki-Android","description":"AnkiDroid: Anki on Android","fork":false,"url":"https://api.github.com/repos/ankidroid/Anki-Android","forks_url":"https://api.github.com/repos/ankidroid/Anki-Android/forks","keys_url":"https://api.github.com/repos/ankidroid/Anki-Android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ankidroid/Anki-Android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ankidroid/Anki-Android/teams","hooks_url":"https://api.github.com/repos/ankidroid/Anki-Android/hooks","issue_events_url":"https://api.github.com/repos/ankidroid/Anki-Android/issues/events{/number}","events_url":"https://api.github.com/repos/ankidroid/Anki-Android/events","assignees_url":"https://api.github.com/repos/ankidroid/Anki-Android/assignees{/user}","branches_url":"https://api.github.com/repos/ankidroid/Anki-Android/branches{/branch}","tags_url":"https://api.github.com/repos/ankidroid/Anki-Android/tags","blobs_url":"https://api.github.com/repos/ankidroid/Anki-Android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ankidroid/Anki-Android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ankidroid/Anki-Android/git/refs{/sha}","trees_url":"https://api.github.com/repos/ankidroid/Anki-Android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ankidroid/Anki-Android/statuses/{sha}","languages_url":"https://api.github.com/repos/ankidroid/Anki-Android/languages","stargazers_url":"https://api.github.com/repos/ankidroid/Anki-Android/stargazers","contributors_url":"https://api.github.com/repos/ankidroid/Anki-Android/contributors","subscribers_url":"https://api.github.com/repos/ankidroid/Anki-Android/subscribers","subscription_url":"https://api.github.com/repos/ankidroid/Anki-Android/subscription","commits_url":"https://api.github.com/repos/ankidroid/Anki-Android/commits{/sha}","git_commits_url":"https://api.github.com/repos/ankidroid/Anki-Android/git/commits{/sha}","comments_url":"https://api.github.com/repos/ankidroid/Anki-Android/comments{/number}","issue_comment_url":"https://api.github.com/repos/ankidroid/Anki-Android/issues/comments{/number}","contents_url":"https://api.github.com/repos/ankidroid/Anki-Android/contents/{+path}","compare_url":"https://api.github.com/repos/ankidroid/Anki-Android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ankidroid/Anki-Android/merges","archive_url":"https://api.github.com/repos/ankidroid/Anki-Android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ankidroid/Anki-Android/downloads","issues_url":"https://api.github.com/repos/ankidroid/Anki-Android/issues{/number}","pulls_url":"https://api.github.com/repos/ankidroid/Anki-Android/pulls{/number}","milestones_url":"https://api.github.com/repos/ankidroid/Anki-Android/milestones{/number}","notifications_url":"https://api.github.com/repos/ankidroid/Anki-Android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ankidroid/Anki-Android/labels{/name}","releases_url":"https://api.github.com/repos/ankidroid/Anki-Android/releases{/id}","deployments_url":"https://api.github.com/repos/ankidroid/Anki-Android/deployments","created_at":"2013-01-20T13:55:53Z","updated_at":"2016-03-14T15:27:41Z","pushed_at":"2016-03-15T16:10:34Z","git_url":"git://github.com/ankidroid/Anki-Android.git","ssh_url":"git@github.com:ankidroid/Anki-Android.git","clone_url":"https://github.com/ankidroid/Anki-Android.git","svn_url":"https://github.com/ankidroid/Anki-Android","homepage":"","size":124511,"stargazers_count":508,"watchers_count":508,"language":"Java","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":false,"forks_count":414,"mirror_url":null,"open_issues_count":280,"forks":414,"open_issues":280,"watchers":508,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/4138"},"html":{"href":"https://github.com/ankidroid/Anki-Android/pull/4138"},"issue":{"href":"https://api.github.com/repos/ankidroid/Anki-Android/issues/4138"},"comments":{"href":"https://api.github.com/repos/ankidroid/Anki-Android/issues/4138/comments"},"review_comments":{"href":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/4138/comments"},"review_comment":{"href":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ankidroid/Anki-Android/pulls/4138/commits"},"statuses":{"href":"https://api.github.com/repos/ankidroid/Anki-Android/statuses/74c741aae6d8ddb177be32298d80ba12c74b9e0d"}}}}