Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 5893df6

Browse files
committed
feat(blog-thread): remove old post_comment && re-org PassportLoader
1 parent 91b1495 commit 5893df6

File tree

17 files changed

+28
-1243
lines changed

17 files changed

+28
-1243
lines changed

lib/groupher_server/cms/cms.ex

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ defmodule GroupherServer.CMS do
1818
ArticleCommentAction,
1919
ArticleCommentEmotion,
2020
ArticleTag,
21-
CommentCURD,
2221
CommunitySync,
2322
CommunityCURD,
2423
CommunityOperation,
@@ -162,14 +161,6 @@ defmodule GroupherServer.CMS do
162161
###################
163162
###################
164163
###################
165-
defdelegate create_comment(thread, content_id, args, user), to: CommentCURD
166-
defdelegate update_comment(thread, id, args, user), to: CommentCURD
167-
defdelegate delete_comment(thread, content_id), to: CommentCURD
168-
defdelegate paged_replies(thread, comment, user), to: CommentCURD
169-
defdelegate reply_comment(thread, comment, args, user), to: CommentCURD
170-
171-
defdelegate paged_comments(thread, content_id, filters), to: CommentCURD
172-
defdelegate paged_comments_participators(thread, content_id, filters), to: CommentCURD
173164

174165
# TODO: move report to abuse report module
175166
defdelegate report_article(thread, article_id, reason, attr, user), to: AbuseReport

lib/groupher_server/cms/delegates/comment_curd.ex

Lines changed: 0 additions & 242 deletions
This file was deleted.

lib/groupher_server/cms/helper/loader.ex

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ defmodule GroupherServer.CMS.Helper.Loader do
66

77
alias GroupherServer.{CMS, Repo}
88

9-
alias CMS.Model.{
10-
Author,
11-
CommunityThread,
12-
PostComment,
13-
PostCommentLike,
14-
PostCommentReply
15-
}
16-
9+
alias CMS.Model.{Author, CommunityThread}
1710
alias Helper.QueryBuilder
1811

1912
def data, do: Dataloader.Ecto.new(Repo, query: &query/2)
@@ -31,96 +24,6 @@ defmodule GroupherServer.CMS.Helper.Loader do
3124
)
3225
end
3326

34-
# ------- post comments ------
35-
@doc """
36-
get unique participators join in comments
37-
"""
38-
# NOTE: this is NOT the right solution
39-
# should use WINDOW function
40-
# see https://github.com/coderplanets/coderplanets_server/issues/16
41-
def query({"posts_comments", PostComment}, %{filter: _filter, unique: true}) do
42-
PostComment
43-
|> join(:inner, [c], a in assoc(c, :author))
44-
# NOTE: this distinct not working in production env, so the uniq logic is move to
45-
# cut_participators.ex middleware, when the data is large, will cause performace issue
46-
# |> distinct([c, a], a.id)
47-
|> select([c, a], a)
48-
end
49-
50-
def query({"posts_comments", PostComment}, %{count: _, unique: true}) do
51-
PostComment
52-
|> join(:inner, [c], a in assoc(c, :author))
53-
|> distinct([c, a], a.id)
54-
|> group_by([c, a], a.id)
55-
|> group_by([c, a], c.post_id)
56-
|> select([c, a], count(c.id))
57-
end
58-
59-
def query({"posts_comments", PostComment}, %{count: _}) do
60-
PostComment
61-
|> group_by([c], c.post_id)
62-
|> select([c], count(c.id))
63-
end
64-
65-
def query({"posts_comments", PostComment}, %{filter: filter}) do
66-
PostComment
67-
|> QueryBuilder.filter_pack(filter)
68-
end
69-
70-
def query({"posts_comments_replies", PostCommentReply}, %{count: _}) do
71-
PostCommentReply
72-
|> group_by([c], c.post_comment_id)
73-
|> select([c], count(c.id))
74-
end
75-
76-
def query({"posts_comments_replies", PostCommentReply}, %{filter: filter}) do
77-
PostCommentReply
78-
|> load_inner_replies(filter)
79-
end
80-
81-
@doc """
82-
load replies of the given comment
83-
TODO: remove
84-
"""
85-
defp load_inner_replies(queryable, filter) do
86-
queryable
87-
|> QueryBuilder.filter_pack(filter)
88-
|> join(:inner, [c], r in assoc(c, :reply))
89-
|> select([c, r], r)
90-
end
91-
92-
def query({"posts_comments_replies", PostCommentReply}, %{reply_to: _}) do
93-
PostCommentReply
94-
|> join(:inner, [c], r in assoc(c, :post_comment))
95-
|> select([c, r], r)
96-
end
97-
98-
def query({"posts_comments_likes", PostCommentLike}, %{count: _}) do
99-
PostCommentLike
100-
|> group_by([f], f.post_comment_id)
101-
|> select([f], count(f.id))
102-
end
103-
104-
def query({"posts_comments_likes", PostCommentLike}, %{viewer_did: _, cur_user: cur_user}) do
105-
PostCommentLike |> where([f], f.user_id == ^cur_user.id)
106-
end
107-
108-
def query({"posts_comments_likes", PostCommentLike}, %{filter: _filter} = args) do
109-
PostCommentLike |> members_pack(args)
110-
end
111-
112-
# TODO: remove it
113-
def members_pack(queryable, %{filter: filter}) do
114-
queryable |> QueryBuilder.load_inner_users(filter)
115-
end
116-
117-
# def query({"articles_comments_upvotes", ArticleCommentUpvote}, %{
118-
# viewer_did: _,
119-
# cur_user: cur_user
120-
# }) do
121-
# ArticleCommentUpvote |> where([f], f.user_id == ^cur_user.id)
122-
# end
123-
12427
# default loader
12528
def query(queryable, _args) do
12629
queryable

lib/groupher_server/cms/models/post.ex

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule GroupherServer.CMS.Model.Post do
99
import GroupherServer.CMS.Helper.Macros
1010

1111
alias GroupherServer.CMS
12-
alias CMS.Model.{Embeds, PostComment}
12+
alias CMS.Model.Embeds
1313

1414
alias Helper.HTML
1515

@@ -30,9 +30,6 @@ defmodule GroupherServer.CMS.Model.Post do
3030
field(:is_solved, :boolean, default: false)
3131
field(:solution_digest, :string)
3232

33-
# TODO: remove after legacy data migrated
34-
has_many(:comments, {"posts_comments", PostComment})
35-
3633
article_tags_field(:post)
3734
article_communities_field(:post)
3835
general_article_fields()

0 commit comments

Comments
 (0)