Skip to content

Commit

Permalink
优化了查询
Browse files Browse the repository at this point in the history
  • Loading branch information
xishandong committed Jul 17, 2023
1 parent 66d5446 commit 000e4cc
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Server01/views/__pycache__/comment.cpython-39.pyc
Binary file not shown.
Binary file modified Server01/views/__pycache__/post.cpython-39.pyc
Binary file not shown.
Binary file modified Server01/views/__pycache__/user.cpython-39.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Server01/views/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def load_reply(request):
offset = data['offset']
comment = Comment.objects.filter(id=id).first()
if comment:
replies = comment.replies.all()
replies = comment.replies
filter_replies = filter_querySet(replies, offset, limit=5)
data = [
{
Expand Down
8 changes: 4 additions & 4 deletions Server01/views/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def get_post_detail(request):
'avatar': post.user.avatar
},
'createTime': convert_to_timezone(post.created_at, TIME_ZONE),
'likeCount': post.favoritePosts.all().count(),
'collectCount': post.collectedPosts.all().count(),
'commentCount': post.comments.all().count(),
'likeCount': post.favoritePosts.count(),
'collectCount': post.collectedPosts.count(),
'commentCount': post.comments.count(),
'content': post.content
}
return JsonResponse({'info': info}, status=200)
Expand All @@ -78,7 +78,7 @@ def query_post_index(request):
Q(content__icontains=query)
)
else:
posts = models.Post.objects.all()
posts = models.Post.objects
posts = filter_querySet(posts, offset, limit=10)
if posts:
return JsonResponse({'info': list(combine_index_post(posts))}, status=200)
Expand Down
12 changes: 6 additions & 6 deletions Server01/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def query_user_index_post(request):
user = models.User.objects.filter(id=user_id).first()
if user and types in type_mapping:
field_name = type_mapping[types]
postObj = getattr(user, field_name).all()
postObj = getattr(user, field_name)
posts = filter_querySet(postObj, offset, limit=10)
if posts:
return JsonResponse({'info': list(combine_index_post(posts))}, status=200)
Expand Down Expand Up @@ -183,19 +183,19 @@ def user_control_index(request, payload):
user = models.User.objects.filter(id=user_id).first()
if user:
if types == 'posts':
user_data = user.posts.all()
user_data = user.posts
info = get_user_post_info(user_data, offset)
elif types == 'collected':
user_data = user.collected.all()
user_data = user.collected
info = get_user_post_info(user_data, offset)
elif types == 'favorites':
user_data = user.favorites.all()
user_data = user.favorites
info = get_user_post_info(user_data, offset)
elif types == 'fans':
user_data = user.beFocusOn.all()
user_data = user.beFocusOn
info = get_user_info(user_data, offset)
elif types == 'follow':
user_data = user.following.all()
user_data = user.following
info = get_user_info(user_data, offset)
else:
return JsonResponse({'error': '错误的操作'}, status=404)
Expand Down
Binary file modified webServer/__pycache__/settings.cpython-39.pyc
Binary file not shown.

0 comments on commit 000e4cc

Please sign in to comment.