Пример #1
0
    def handle(self, *args, **options):
        SearchIndex.objects.all().delete()
        indexed_comment_count = 0
        indexed_post_count = 0
        indexed_user_count = 0

        for chunk in chunked_queryset(
            Comment.visible_objects().filter(is_deleted=False, post__is_visible=True)
        ):
            for comment in chunk:
                self.stdout.write(f"Indexing comment: {comment.id}")
                SearchIndex.update_comment_index(comment)
                indexed_comment_count += 1

        for chunk in chunked_queryset(
            Post.visible_objects().filter(is_shadow_banned=False)
        ):
            for post in chunk:
                self.stdout.write(f"Indexing post: {post.slug}")
                SearchIndex.update_post_index(post)
                indexed_post_count += 1

        for chunk in chunked_queryset(
            User.objects.filter(moderation_status=User.MODERATION_STATUS_APPROVED)
        ):
            for user in chunk:
                self.stdout.write(f"Indexing user: {user.slug}")
                SearchIndex.update_user_index(user)
                SearchIndex.update_user_tags(user)
                indexed_user_count += 1

        self.stdout.write(
            f"Done 🥙 "
            f"Comments: {indexed_comment_count} Posts: {indexed_post_count} Users: {indexed_user_count}"
        )
Пример #2
0
def toggle_tag(request, tag_code):
    if request.method != "POST":
        raise Http404()

    tag = get_object_or_404(Tag, code=tag_code)

    user_tag, is_created = UserTag.objects.get_or_create(
        user=request.me, tag=tag, defaults=dict(name=tag.name)
    )

    if not is_created:
        user_tag.delete()

    SearchIndex.update_user_tags(request.me)

    return {
        "status": "created" if is_created else "deleted",
        "tag": {"code": tag.code, "name": tag.name, "color": tag.color},
    }
Пример #3
0
    def handle(self, *args, **options):
        SearchIndex.objects.all().delete()

        for comment in Comment.visible_objects().filter(is_deleted=False,
                                                        post__is_visible=True):
            self.stdout.write(f"Indexing comment: {comment.id}")
            SearchIndex.update_comment_index(comment)

        for post in Post.visible_objects().filter(is_shadow_banned=False):
            self.stdout.write(f"Indexing post: {post.slug}")
            SearchIndex.update_post_index(post)

        for user in User.objects.filter(
                moderation_status=User.MODERATION_STATUS_APPROVED):
            self.stdout.write(f"Indexing user: {user.slug}")
            SearchIndex.update_user_index(user)
            SearchIndex.update_user_tags(user)

        self.stdout.write("Done 🥙")
    def handle(self, *args, **options):
        SearchIndex.objects.all().delete()

        for comment in Comment.visible_objects().filter(is_deleted=False,
                                                        post__is_visible=True):
            self.stdout.write(f"Indexing comment: {comment.id}")
            SearchIndex.update_comment_index(comment)

        for post in Post.visible_objects().filter(is_shadow_banned=False):
            self.stdout.write(f"Indexing post: {post.slug}")
            SearchIndex.update_post_index(post)

        for user in User.objects.filter(is_profile_complete=True,
                                        is_profile_reviewed=True,
                                        is_profile_rejected=False):
            self.stdout.write(f"Indexing user: {user.slug}")
            SearchIndex.update_user_index(user)
            SearchIndex.update_user_tags(user)

        self.stdout.write("Done 🥙")