{"action":"created","comment":{"url":"https://api.github.com/repos/inspirehep/inspire-next/pulls/comments/49432255","id":49432255,"diff_hunk":"@@ -0,0 +1,74 @@\n+# -*- coding: utf-8 -*-\n+#\n+# This file is part of INSPIRE.\n+# Copyright (C) 2015, 2016 CERN.\n+#\n+# INSPIRE is free software; you can redistribute it and/or\n+# modify it under the terms of the GNU General Public License as\n+# published by the Free Software Foundation; either version 2 of the\n+# License, or (at your option) any later version.\n+#\n+# INSPIRE is distributed in the hope that it will be useful, but\n+# WITHOUT ANY WARRANTY; without even the implied warranty of\n+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n+# General Public License for more details.\n+#\n+# You should have received a copy of the GNU General Public License\n+# along with INSPIRE; if not, write to the Free Software Foundation, Inc.,\n+# 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.\n+\n+\n+from invenio_records.signals import after_record_insert, after_record_update, before_record_index\n+\n+from .tasks import update_citation_count_for_records\n+from .utils import calculate_citation_count\n+\n+\n+@after_record_insert.connect\n+def catch_citations_insert(sender, *args, **kwargs):\n+    \"\"\"Triggers update of citation count for all the records\n+    which are affected by insertion of the sender\n+\n+    :param sender: The json representation of the record that is going to be inserted\n+    \"\"\"\n+    records_to_notify = []\n+    if 'references' in sender:\n+            records_to_notify = [ref['recid'] for ref in sender['references'] if ref.get('recid')]\n+\n+    if records_to_notify:\n+        # countdown added as it takes a while before an indexed record can be accessed from es\n+        update_citation_count_for_records.apply_async(args=[records_to_notify], countdown=3)\n+\n+\n+@before_record_index.connect\n+def add_citation_count_on_insert_or_update(sender, *args, **kwargs):\n+\n+    if kwargs is not None:\n+        json = kwargs.get('json')\n+        index = kwargs.get('index')\n+        if json and index == 'hep':\n+            calculate_citation_count(sender, json)\n+\n+\n+@after_record_update.connect\n+def catch_citations_update(sender, *args, **kwargs):\n+    \"\"\"Triggers update of citation count for all the records\n+    which are affected by update of the sender\n+\n+    :param sender: The json representation of the record that is going to be updated\n+    \"\"\"\n+    refs_before_update = []\n+    if sender.init_json:","path":"inspirehep/modules/citations/receivers.py","position":61,"original_position":61,"commit_id":"41706e01627f29326613aa1ece71ee18cb3f9322","original_commit_id":"41706e01627f29326613aa1ece71ee18cb3f9322","user":{"login":"tomaszgy","id":10139760,"avatar_url":"https://avatars.githubusercontent.com/u/10139760?v=3","gravatar_id":"","url":"https://api.github.com/users/tomaszgy","html_url":"https://github.com/tomaszgy","followers_url":"https://api.github.com/users/tomaszgy/followers","following_url":"https://api.github.com/users/tomaszgy/following{/other_user}","gists_url":"https://api.github.com/users/tomaszgy/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaszgy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaszgy/subscriptions","organizations_url":"https://api.github.com/users/tomaszgy/orgs","repos_url":"https://api.github.com/users/tomaszgy/repos","events_url":"https://api.github.com/users/tomaszgy/events{/privacy}","received_events_url":"https://api.github.com/users/tomaszgy/received_events","type":"User","site_admin":false},"body":"Sure. Then I need to create a PR also in invenio_records.","created_at":"2016-01-12T09:43:25Z","updated_at":"2016-01-12T09:43:25Z","html_url":"https://github.com/inspirehep/inspire-next/pull/621#discussion_r49432255","pull_request_url":"https://api.github.com/repos/inspirehep/inspire-next/pulls/621","_links":{"self":{"href":"https://api.github.com/repos/inspirehep/inspire-next/pulls/comments/49432255"},"html":{"href":"https://github.com/inspirehep/inspire-next/pull/621#discussion_r49432255"},"pull_request":{"href":"https://api.github.com/repos/inspirehep/inspire-next/pulls/621"}}},"pull_request":{"url":"https://api.github.com/repos/inspirehep/inspire-next/pulls/621","id":52865830,"html_url":"https://github.com/inspirehep/inspire-next/pull/621","diff_url":"https://github.com/inspirehep/inspire-next/pull/621.diff","patch_url":"https://github.com/inspirehep/inspire-next/pull/621.patch","issue_url":"https://api.github.com/repos/inspirehep/inspire-next/issues/621","number":621,"state":"open","locked":false,"title":"citations: update citation_count for record insert or update","user":{"login":"tomaszgy","id":10139760,"avatar_url":"https://avatars.githubusercontent.com/u/10139760?v=3","gravatar_id":"","url":"https://api.github.com/users/tomaszgy","html_url":"https://github.com/tomaszgy","followers_url":"https://api.github.com/users/tomaszgy/followers","following_url":"https://api.github.com/users/tomaszgy/following{/other_user}","gists_url":"https://api.github.com/users/tomaszgy/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaszgy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaszgy/subscriptions","organizations_url":"https://api.github.com/users/tomaszgy/orgs","repos_url":"https://api.github.com/users/tomaszgy/repos","events_url":"https://api.github.com/users/tomaszgy/events{/privacy}","received_events_url":"https://api.github.com/users/tomaszgy/received_events","type":"User","site_admin":false},"body":"implemented using https://github.com/inspirehep/inspire-next/pull/492","created_at":"2015-12-07T16:22:34Z","updated_at":"2016-01-12T09:43:25Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0ae4d91787ce0a19deb09c35b5b0eaf29b87575b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/inspirehep/inspire-next/pulls/621/commits","review_comments_url":"https://api.github.com/repos/inspirehep/inspire-next/pulls/621/comments","review_comment_url":"https://api.github.com/repos/inspirehep/inspire-next/pulls/comments{/number}","comments_url":"https://api.github.com/repos/inspirehep/inspire-next/issues/621/comments","statuses_url":"https://api.github.com/repos/inspirehep/inspire-next/statuses/41706e01627f29326613aa1ece71ee18cb3f9322","head":{"label":"tomaszgy:cit_with_signals","ref":"cit_with_signals","sha":"41706e01627f29326613aa1ece71ee18cb3f9322","user":{"login":"tomaszgy","id":10139760,"avatar_url":"https://avatars.githubusercontent.com/u/10139760?v=3","gravatar_id":"","url":"https://api.github.com/users/tomaszgy","html_url":"https://github.com/tomaszgy","followers_url":"https://api.github.com/users/tomaszgy/followers","following_url":"https://api.github.com/users/tomaszgy/following{/other_user}","gists_url":"https://api.github.com/users/tomaszgy/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaszgy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaszgy/subscriptions","organizations_url":"https://api.github.com/users/tomaszgy/orgs","repos_url":"https://api.github.com/users/tomaszgy/repos","events_url":"https://api.github.com/users/tomaszgy/events{/privacy}","received_events_url":"https://api.github.com/users/tomaszgy/received_events","type":"User","site_admin":false},"repo":{"id":45853625,"name":"inspire-next","full_name":"tomaszgy/inspire-next","owner":{"login":"tomaszgy","id":10139760,"avatar_url":"https://avatars.githubusercontent.com/u/10139760?v=3","gravatar_id":"","url":"https://api.github.com/users/tomaszgy","html_url":"https://github.com/tomaszgy","followers_url":"https://api.github.com/users/tomaszgy/followers","following_url":"https://api.github.com/users/tomaszgy/following{/other_user}","gists_url":"https://api.github.com/users/tomaszgy/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaszgy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaszgy/subscriptions","organizations_url":"https://api.github.com/users/tomaszgy/orgs","repos_url":"https://api.github.com/users/tomaszgy/repos","events_url":"https://api.github.com/users/tomaszgy/events{/privacy}","received_events_url":"https://api.github.com/users/tomaszgy/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/tomaszgy/inspire-next","description":"INSPIRE overlay repository to be used with https://github.com/inspirehep/invenio@labs branch","fork":true,"url":"https://api.github.com/repos/tomaszgy/inspire-next","forks_url":"https://api.github.com/repos/tomaszgy/inspire-next/forks","keys_url":"https://api.github.com/repos/tomaszgy/inspire-next/keys{/key_id}","collaborators_url":"https://api.github.com/repos/tomaszgy/inspire-next/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/tomaszgy/inspire-next/teams","hooks_url":"https://api.github.com/repos/tomaszgy/inspire-next/hooks","issue_events_url":"https://api.github.com/repos/tomaszgy/inspire-next/issues/events{/number}","events_url":"https://api.github.com/repos/tomaszgy/inspire-next/events","assignees_url":"https://api.github.com/repos/tomaszgy/inspire-next/assignees{/user}","branches_url":"https://api.github.com/repos/tomaszgy/inspire-next/branches{/branch}","tags_url":"https://api.github.com/repos/tomaszgy/inspire-next/tags","blobs_url":"https://api.github.com/repos/tomaszgy/inspire-next/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/tomaszgy/inspire-next/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/tomaszgy/inspire-next/git/refs{/sha}","trees_url":"https://api.github.com/repos/tomaszgy/inspire-next/git/trees{/sha}","statuses_url":"https://api.github.com/repos/tomaszgy/inspire-next/statuses/{sha}","languages_url":"https://api.github.com/repos/tomaszgy/inspire-next/languages","stargazers_url":"https://api.github.com/repos/tomaszgy/inspire-next/stargazers","contributors_url":"https://api.github.com/repos/tomaszgy/inspire-next/contributors","subscribers_url":"https://api.github.com/repos/tomaszgy/inspire-next/subscribers","subscription_url":"https://api.github.com/repos/tomaszgy/inspire-next/subscription","commits_url":"https://api.github.com/repos/tomaszgy/inspire-next/commits{/sha}","git_commits_url":"https://api.github.com/repos/tomaszgy/inspire-next/git/commits{/sha}","comments_url":"https://api.github.com/repos/tomaszgy/inspire-next/comments{/number}","issue_comment_url":"https://api.github.com/repos/tomaszgy/inspire-next/issues/comments{/number}","contents_url":"https://api.github.com/repos/tomaszgy/inspire-next/contents/{+path}","compare_url":"https://api.github.com/repos/tomaszgy/inspire-next/compare/{base}...{head}","merges_url":"https://api.github.com/repos/tomaszgy/inspire-next/merges","archive_url":"https://api.github.com/repos/tomaszgy/inspire-next/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/tomaszgy/inspire-next/downloads","issues_url":"https://api.github.com/repos/tomaszgy/inspire-next/issues{/number}","pulls_url":"https://api.github.com/repos/tomaszgy/inspire-next/pulls{/number}","milestones_url":"https://api.github.com/repos/tomaszgy/inspire-next/milestones{/number}","notifications_url":"https://api.github.com/repos/tomaszgy/inspire-next/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/tomaszgy/inspire-next/labels{/name}","releases_url":"https://api.github.com/repos/tomaszgy/inspire-next/releases{/id}","created_at":"2015-11-09T17:13:36Z","updated_at":"2015-11-09T17:13:43Z","pushed_at":"2016-01-11T10:16:39Z","git_url":"git://github.com/tomaszgy/inspire-next.git","ssh_url":"git@github.com:tomaszgy/inspire-next.git","clone_url":"https://github.com/tomaszgy/inspire-next.git","svn_url":"https://github.com/tomaszgy/inspire-next","homepage":"https://labs.inspirehep.net","size":39959,"stargazers_count":0,"watchers_count":0,"language":"Python","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":"inspirehep:master","ref":"master","sha":"37f87632f2c2a54449f68deb78f40432474dbfde","user":{"login":"inspirehep","id":356664,"avatar_url":"https://avatars.githubusercontent.com/u/356664?v=3","gravatar_id":"","url":"https://api.github.com/users/inspirehep","html_url":"https://github.com/inspirehep","followers_url":"https://api.github.com/users/inspirehep/followers","following_url":"https://api.github.com/users/inspirehep/following{/other_user}","gists_url":"https://api.github.com/users/inspirehep/gists{/gist_id}","starred_url":"https://api.github.com/users/inspirehep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inspirehep/subscriptions","organizations_url":"https://api.github.com/users/inspirehep/orgs","repos_url":"https://api.github.com/users/inspirehep/repos","events_url":"https://api.github.com/users/inspirehep/events{/privacy}","received_events_url":"https://api.github.com/users/inspirehep/received_events","type":"Organization","site_admin":false},"repo":{"id":15221515,"name":"inspire-next","full_name":"inspirehep/inspire-next","owner":{"login":"inspirehep","id":356664,"avatar_url":"https://avatars.githubusercontent.com/u/356664?v=3","gravatar_id":"","url":"https://api.github.com/users/inspirehep","html_url":"https://github.com/inspirehep","followers_url":"https://api.github.com/users/inspirehep/followers","following_url":"https://api.github.com/users/inspirehep/following{/other_user}","gists_url":"https://api.github.com/users/inspirehep/gists{/gist_id}","starred_url":"https://api.github.com/users/inspirehep/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/inspirehep/subscriptions","organizations_url":"https://api.github.com/users/inspirehep/orgs","repos_url":"https://api.github.com/users/inspirehep/repos","events_url":"https://api.github.com/users/inspirehep/events{/privacy}","received_events_url":"https://api.github.com/users/inspirehep/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/inspirehep/inspire-next","description":"INSPIRE overlay repository to be used with https://github.com/inspirehep/invenio@labs branch","fork":false,"url":"https://api.github.com/repos/inspirehep/inspire-next","forks_url":"https://api.github.com/repos/inspirehep/inspire-next/forks","keys_url":"https://api.github.com/repos/inspirehep/inspire-next/keys{/key_id}","collaborators_url":"https://api.github.com/repos/inspirehep/inspire-next/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/inspirehep/inspire-next/teams","hooks_url":"https://api.github.com/repos/inspirehep/inspire-next/hooks","issue_events_url":"https://api.github.com/repos/inspirehep/inspire-next/issues/events{/number}","events_url":"https://api.github.com/repos/inspirehep/inspire-next/events","assignees_url":"https://api.github.com/repos/inspirehep/inspire-next/assignees{/user}","branches_url":"https://api.github.com/repos/inspirehep/inspire-next/branches{/branch}","tags_url":"https://api.github.com/repos/inspirehep/inspire-next/tags","blobs_url":"https://api.github.com/repos/inspirehep/inspire-next/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/inspirehep/inspire-next/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/inspirehep/inspire-next/git/refs{/sha}","trees_url":"https://api.github.com/repos/inspirehep/inspire-next/git/trees{/sha}","statuses_url":"https://api.github.com/repos/inspirehep/inspire-next/statuses/{sha}","languages_url":"https://api.github.com/repos/inspirehep/inspire-next/languages","stargazers_url":"https://api.github.com/repos/inspirehep/inspire-next/stargazers","contributors_url":"https://api.github.com/repos/inspirehep/inspire-next/contributors","subscribers_url":"https://api.github.com/repos/inspirehep/inspire-next/subscribers","subscription_url":"https://api.github.com/repos/inspirehep/inspire-next/subscription","commits_url":"https://api.github.com/repos/inspirehep/inspire-next/commits{/sha}","git_commits_url":"https://api.github.com/repos/inspirehep/inspire-next/git/commits{/sha}","comments_url":"https://api.github.com/repos/inspirehep/inspire-next/comments{/number}","issue_comment_url":"https://api.github.com/repos/inspirehep/inspire-next/issues/comments{/number}","contents_url":"https://api.github.com/repos/inspirehep/inspire-next/contents/{+path}","compare_url":"https://api.github.com/repos/inspirehep/inspire-next/compare/{base}...{head}","merges_url":"https://api.github.com/repos/inspirehep/inspire-next/merges","archive_url":"https://api.github.com/repos/inspirehep/inspire-next/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/inspirehep/inspire-next/downloads","issues_url":"https://api.github.com/repos/inspirehep/inspire-next/issues{/number}","pulls_url":"https://api.github.com/repos/inspirehep/inspire-next/pulls{/number}","milestones_url":"https://api.github.com/repos/inspirehep/inspire-next/milestones{/number}","notifications_url":"https://api.github.com/repos/inspirehep/inspire-next/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/inspirehep/inspire-next/labels{/name}","releases_url":"https://api.github.com/repos/inspirehep/inspire-next/releases{/id}","created_at":"2013-12-16T09:11:58Z","updated_at":"2016-01-11T10:45:15Z","pushed_at":"2016-01-12T09:34:38Z","git_url":"git://github.com/inspirehep/inspire-next.git","ssh_url":"git@github.com:inspirehep/inspire-next.git","clone_url":"https://github.com/inspirehep/inspire-next.git","svn_url":"https://github.com/inspirehep/inspire-next","homepage":"https://labs.inspirehep.net","size":44299,"stargazers_count":9,"watchers_count":9,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":23,"mirror_url":null,"open_issues_count":98,"forks":23,"open_issues":98,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/inspirehep/inspire-next/pulls/621"},"html":{"href":"https://github.com/inspirehep/inspire-next/pull/621"},"issue":{"href":"https://api.github.com/repos/inspirehep/inspire-next/issues/621"},"comments":{"href":"https://api.github.com/repos/inspirehep/inspire-next/issues/621/comments"},"review_comments":{"href":"https://api.github.com/repos/inspirehep/inspire-next/pulls/621/comments"},"review_comment":{"href":"https://api.github.com/repos/inspirehep/inspire-next/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/inspirehep/inspire-next/pulls/621/commits"},"statuses":{"href":"https://api.github.com/repos/inspirehep/inspire-next/statuses/41706e01627f29326613aa1ece71ee18cb3f9322"}}}}