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.

Commit157ac79

Browse files
authored
fix(user): improve common article extract (#375)
* fix(user): add common user to common article* refactor: improve extract article method* refactor(article-reaction): remove support_thread concept* refactor(article-reaction): remove support_thread concept
1 parent205f66d commit157ac79

File tree

15 files changed

+86
-54
lines changed

15 files changed

+86
-54
lines changed

‎lib/groupher_server/accounts/collect_folder.ex‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ defmodule GroupherServer.Accounts.CollectFolder do
1212
@required_fields~w(user_id title)a
1313
@optional_fields~w(index total_count private desc last_updated)a
1414

15-
@supported_threads[:post,:job,:repo]
16-
17-
defsupported_threads,do:@supported_threads
18-
1915
@typet::%CollectFolder{}
2016
schema"collect_folders"do
2117
belongs_to(:user,User,foreign_key::user_id)

‎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/publish.ex‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ defmodule GroupherServer.Accounts.Delegate.Publish do
7575
thread=thread|>to_string|>String.upcase()
7676
thread_atom=thread|>String.downcase()|>String.to_atom()
7777

78-
# article_preload = Keyword.new([{thread_atom, :author}])
79-
# query = from(comment in ArticleComment, preload: ^article_preload)
80-
query=from(commentinArticleComment,preload:^thread_atom)
78+
article_preload=Keyword.new([{thread_atom,[author::user]}])
79+
query=from(commentinArticleComment,preload:^article_preload)
8180

8281
query
8382
|>join(:inner,[comment],authorinassoc(comment,:author))

‎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/groupher_server/accounts/embeds/collect_folder_meta.ex‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ defmodule GroupherServer.Accounts.Embeds.CollectFolderMeta.Macros do
1010
field(:has_repo, :boolean, default: false)
1111
field(:repo_count, :integer, default: 0)
1212
"""
13-
aliasGroupherServer.Accounts.CollectFolder
13+
importHelper.Utils,only:[get_config:2]
1414

15-
@supported_threadsCollectFolder.supported_threads()
15+
@article_threadsget_config(:article,:article_threads)
1616

1717
defmacrothreads_fields()do
18-
@supported_threads
18+
@article_threads
1919
|>Enum.map(fnthread->
2020
quotedo
2121
field(unquote(:"has_#{thread}"),:boolean,default:false)
@@ -27,21 +27,20 @@ end
2727

2828
defmoduleGroupherServer.Accounts.Embeds.CollectFolderMetado
2929
@moduledoc"""
30-
general article meta info forarticle-like content, like @supported_threads
30+
general article meta info forarticles
3131
"""
3232
useEcto.Schema
3333
importEcto.Changeset
3434
importGroupherServer.Accounts.Embeds.CollectFolderMeta.Macros
35+
importHelper.Utils,only:[get_config:2]
3536

36-
aliasGroupherServer.Accounts.CollectFolder
37+
@article_threadsget_config(:article,:article_threads)
3738

38-
@supported_threadsCollectFolder.supported_threads()
39-
40-
@optional_fieldsEnum.map(@supported_threads,&:"#{&1}_count")++
41-
Enum.map(@supported_threads,&:"has_#{&1}")
39+
@optional_fieldsEnum.map(@article_threads,&:"#{&1}_count")++
40+
Enum.map(@article_threads,&:"has_#{&1}")
4241

4342
defdefault_meta()do
44-
@supported_threads
43+
@article_threads
4544
|>Enum.reduce([],fnthread,acc->acc++["#{thread}_count":0,"has_#{thread}":false]end)
4645
|>Enum.into(%{})
4746
end

‎lib/groupher_server_web/schema/Helper/fields.ex‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do
99
@page_sizeget_config(:general,:page_size)
1010
@supported_emotionsget_config(:article,:supported_emotions)
1111
@supported_comment_emotionsget_config(:article,:comment_supported_emotions)
12-
@supported_collect_folder_threadsAccounts.CollectFolder.supported_threads()
1312

1413
@article_threadsget_config(:article,:article_threads)
1514

@@ -242,7 +241,7 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do
242241
general collect folder meta info
243242
"""
244243
defmacrocollect_folder_meta_fields()do
245-
@supported_collect_folder_threads
244+
@article_threads
246245
|>Enum.map(fnthread->
247246
quotedo
248247
field(unquote(:"has_#{thread}"),:boolean)

‎lib/groupher_server_web/schema/cms/cms_types.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
2727
field(:id,:id)
2828
# field(:body_html, :string)
2929
field(:title,:string)
30-
field(:author,:user,resolve:dataloader(CMS,:author))
30+
field(:author,:common_user)
3131
end
3232

3333
object:common_article_commentdo

‎lib/helper/orm.ex‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ defmodule Helper.ORM do
295295
|>Repo.update()
296296
end
297297

298+
@doc"""
299+
extract common article info and assign it to 'article' field
300+
"""
298301
defextract_and_assign_article(%{entries:entries}=paged_articles)do
299302
entries=
300303
Enum.map(entries,fnitem->
@@ -307,24 +310,27 @@ defmodule Helper.ORM do
307310

308311
@doc"extract common articles info"
309312
@specextract_articles(T.paged_data(),[Atom.t()])::T.paged_article_common()
310-
defextract_articles(%{entries:entries}=paged_articles,supported_threads)do
313+
defextract_articles(%{entries:entries}=paged_articles,threads\\@article_threads)do
311314
paged_articles
312-
|>Map.put(:entries,Enum.map(entries,&extract_article_info(&1,supported_threads)))
315+
|>Map.put(:entries,Enum.map(entries,&extract_article_info(&1,threads)))
313316
end
314317

315-
defpextract_article_info(reaction,supported_threads)do
316-
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))))
317320
article=Map.get(reaction,thread)
318321

319322
export_article_info(thread,article)
320323
end
321324

322325
defpexport_article_info(thread,article)do
326+
author=article.author.user
327+
323328
%{
324329
thread:thread,
325330
id:article.id,
326331
title:article.title,
327-
upvotes_count:Map.get(article,:upvotes_count)
332+
upvotes_count:Map.get(article,:upvotes_count),
333+
author:author
328334
}
329335
end
330336
end

‎test/groupher_server/accounts/published/published_jobs_test.exs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ defmodule GroupherServer.Test.Accounts.Published.Job do
7272
end
7373

7474
describe"[publised job comments]"do
75-
@tag:wip2
7675
test"can get published article comments",~m(job user)ado
7776
total_count=10
7877

‎test/groupher_server/accounts/published/published_posts_test.exs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ defmodule GroupherServer.Test.Accounts.Published.Post do
7272
end
7373

7474
describe"[publised post comments]"do
75-
@tag:wip2
7675
test"can get published article comments",~m(post user)ado
7776
total_count=10
7877

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp