Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commita424b36

Browse files
committed
refactor: improve extract article method
1 parent290ee65 commita424b36

File tree

7 files changed

+30
-18
lines changed

7 files changed

+30
-18
lines changed

‎lib/groupher_server/accounts/delegates/collect_folder.ex‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ defmodule GroupherServer.Accounts.Delegate.CollectFolder do
99
aliasHelper.QueryBuilder
1010

1111
importHelper.ErrorCode
12-
importHelper.Utils,only:[done:1]
12+
importHelper.Utils,only:[done:1,get_config:2]
1313

1414
importShortMaps
1515

@@ -24,7 +24,7 @@ defmodule GroupherServer.Accounts.Delegate.CollectFolder do
2424
# @max_article_count_per_collect_folder 300
2525

2626
@default_metaEmbeds.CollectFolderMeta.default_meta()
27-
@supported_collect_threads[:post,:job]
27+
@article_threadsget_config(:article,:article_threads)
2828

2929
@doc"""
3030
list a user's not-private collect folders
@@ -75,9 +75,15 @@ defmodule GroupherServer.Accounts.Delegate.CollectFolder do
7575
end
7676

7777
defpdo_paged_collect_folder_articles(folder,filter)do
78-
Repo.preload(folder.collects,@supported_collect_threads)
78+
article_preload=
79+
@article_threads
80+
|>Enum.reduce([],fnthread,acc->
81+
acc++Keyword.new([{thread,[author::user]}])
82+
end)
83+
84+
Repo.preload(folder.collects,article_preload)
7985
|>ORM.embeds_paginater(filter)
80-
|>ORM.extract_articles(@supported_collect_threads)
86+
|>ORM.extract_articles()
8187
|>done()
8288
end
8389

‎lib/groupher_server/accounts/delegates/upvoted_articles.ex‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ defmodule GroupherServer.Accounts.Delegate.UpvotedArticles do
33
get contents(posts, jobs ...) that user upvotes
44
"""
55
importEcto.Query,warn:false
6-
importHelper.Utils,only:[done:1]
6+
importHelper.Utils,only:[done:1,get_config:2]
77
importShortMaps
88

99
aliasHelper.{ORM,QueryBuilder}
1010

1111
aliasGroupherServer.CMS
1212
aliasCMS.{ArticleUpvote}
1313

14-
# TODO: move to Model
15-
@supported_uovoted_threads[:post,:job]
14+
@article_threadsget_config(:article,:article_threads)
1615

1716
@doc"""
1817
get paged upvoted articles
@@ -31,13 +30,19 @@ defmodule GroupherServer.Accounts.Delegate.UpvotedArticles do
3130
end
3231

3332
defpload_upvoted_articles(where_query,%{page:page,size:size}=filter)do
34-
query=from(ainArticleUpvote,preload:^@supported_uovoted_threads)
33+
article_preload=
34+
@article_threads
35+
|>Enum.reduce([],fnthread,acc->
36+
acc++Keyword.new([{thread,[author::user]}])
37+
end)
38+
39+
query=from(ainArticleUpvote,preload:^article_preload)
3540

3641
query
3742
|>where(^where_query)
3843
|>QueryBuilder.filter_pack(filter)
3944
|>ORM.paginater(~m(page size)a)
40-
|>ORM.extract_articles(@supported_uovoted_threads)
45+
|>ORM.extract_articles()
4146
|>done()
4247
end
4348
end

‎lib/helper/orm.ex‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,13 @@ defmodule Helper.ORM do
310310

311311
@doc"extract common articles info"
312312
@specextract_articles(T.paged_data(),[Atom.t()])::T.paged_article_common()
313-
defextract_articles(%{entries:entries}=paged_articles,supported_threads)do
313+
defextract_articles(%{entries:entries}=paged_articles,threads\\@article_threads)do
314314
paged_articles
315-
|>Map.put(:entries,Enum.map(entries,&extract_article_info(&1,supported_threads)))
315+
|>Map.put(:entries,Enum.map(entries,&extract_article_info(&1,threads)))
316316
end
317317

318-
defpextract_article_info(reaction,supported_threads)do
319-
thread=Enum.find(supported_threads,&(notis_nil(Map.get(reaction,&1))))
318+
defpextract_article_info(reaction,threads)do
319+
thread=Enum.find(threads,&(notis_nil(Map.get(reaction,&1))))
320320
article=Map.get(reaction,thread)
321321

322322
export_article_info(thread,article)

‎test/groupher_server/accounts/reacted_articles_test.exs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ defmodule GroupherServer.Test.Accounts.ReactedContents do
1414
end
1515

1616
describe"[user upvoted articles]"do
17+
@tag:wip2
1718
test"user can get paged upvoted common articles",~m(user post job)ado
1819
{:ok,_}=CMS.upvote_article(:post,post.id,user)
1920
{:ok,_}=CMS.upvote_article(:job,job.id,user)
@@ -28,8 +29,8 @@ defmodule GroupherServer.Test.Accounts.ReactedContents do
2829
assertjob.id==article_job|>Map.get(:id)
2930
assertpost.id==article_post|>Map.get(:id)
3031

31-
assert[:id,:thread,:title,:upvotes_count]==article_post|>Map.keys()
32-
assert[:id,:thread,:title,:upvotes_count]==article_job|>Map.keys()
32+
assert[:author,:id,:thread,:title,:upvotes_count]==article_post|>Map.keys()
33+
assert[:author,:id,:thread,:title,:upvotes_count]==article_job|>Map.keys()
3334
end
3435

3536
test"user can get paged upvoted posts by thread filter",~m(user post job)ado

‎test/groupher_server_web/query/accounts/published/published_jobs_test.exs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ defmodule GroupherServer.Test.Query.Accounts.Published.Jobs do
7575
}
7676
}
7777
"""
78-
@tag:wip2
78+
7979
test"user can get paged published comments on job",~m(guest_conn user job)ado
8080
pub_comments=
8181
Enum.reduce(1..@publish_count,[],fn_,acc->

‎test/groupher_server_web/query/accounts/published/published_posts_test.exs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ defmodule GroupherServer.Test.Query.Accounts.Published.Posts do
7575
}
7676
}
7777
"""
78-
@tag:wip2
78+
7979
test"user can get paged published comments on post",~m(guest_conn user post)ado
8080
pub_comments=
8181
Enum.reduce(1..@publish_count,[],fn_,acc->

‎test/groupher_server_web/query/accounts/published/published_repos_test.exs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ defmodule GroupherServer.Test.Query.Accounts.Published.Repos do
7575
}
7676
}
7777
"""
78-
@tag:wip2
78+
7979
test"user can get paged published comments on repo",~m(guest_conn user repo)ado
8080
pub_comments=
8181
Enum.reduce(1..@publish_count,[],fn_,acc->

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp