diff --git a/apps/social/models.py b/apps/social/models.py index 80b851263..e1cc925eb 100644 --- a/apps/social/models.py +++ b/apps/social/models.py @@ -1967,16 +1967,15 @@ class MInteraction(mongo.Document): @classmethod def new_comment_like(cls, liking_user_id, comment_user_id, social_feed_id, story_id, story_title, comments): - params = { - 'user_id': comment_user_id, - 'with_user_id': liking_user_id, - 'category': 'comment_like', - 'feed_id': social_feed_id, - 'content_id': story_id, - 'title': story_title, - 'content': comments, - } - cls.objects.create(**params) + cls.objects.get_or_create(user_id=comment_user_id, + with_user_id=liking_user_id, + category="comment_like", + feed_id=social_feed_id, + content_id=story_id, + defaults={ + "title": story_title, + "content": comments, + }) @classmethod def new_reply_reply(cls, user_id, reply_user_id, reply_content, social_feed_id, story_id, story_title=None, original_message=None): @@ -2146,16 +2145,15 @@ class MActivity(mongo.Document): @classmethod def new_comment_like(cls, liking_user_id, comment_user_id, social_feed_id, story_id, story_title, comments): - params = { - 'user_id': comment_user_id, - 'with_user_id': liking_user_id, - 'category': 'comment_like', - 'feed_id': social_feed_id, - 'content_id': story_id, - 'title': story_title, - 'content': comments, - } - cls.objects.create(**params) + cls.objects.get_or_create(user_id=comment_user_id, + with_user_id=liking_user_id, + category="comment_like", + feed_id=social_feed_id, + content_id=story_id, + defaults={ + "title": story_title, + "content": comments, + }) @classmethod def new_shared_story(cls, user_id, story_title, comments, story_feed_id, story_id, share_date=None): diff --git a/settings.py b/settings.py index 35e21525a..c6dddf0d1 100644 --- a/settings.py +++ b/settings.py @@ -436,4 +436,5 @@ JAMMIT = jammit.JammitAssets(NEWSBLUR_DIR) if DEBUG: MIDDLEWARE_CLASSES += ('utils.mongo_raw_log_middleware.SqldumpMiddleware',) MIDDLEWARE_CLASSES += ('utils.redis_raw_log_middleware.SqldumpMiddleware',) + MIDDLEWARE_CLASSES += ('utils.request_introspection_middleware.DumpRequestMiddleware',) diff --git a/utils/request_introspection_middleware.py b/utils/request_introspection_middleware.py new file mode 100644 index 000000000..e7364584d --- /dev/null +++ b/utils/request_introspection_middleware.py @@ -0,0 +1,9 @@ +from django.conf import settings +from utils import log as logging + +class DumpRequestMiddleware: + def process_request(self, request): + if settings.DEBUG: + request_items = request.REQUEST.items() + if request_items: + logging.debug("~BC~FK%s" % dict(request_items)) \ No newline at end of file