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.

Commitb07f1f9

Browse files
authored
refactor: debug new schema (#429)
* chore(community): missing field* refactor: add some seed* refactor: fmt* refactor: seeds script for debug* chore: wip* fix: modeule naming* fix: digest length test case* chore: wip* chore: seed fix* chore: debug* chore: radar & article tags enhance* refactor(article-meta): add latest_upvoted_users* refactor(test): imporve exsit_in / exist_user_in* fix(article): digest length test case* fix(article): tag tests* fix(article): tag tests* fix(article): tag tests* fix: article gq workflow args* fix: article tag tests* fix: article tag tests* fix: article tag tests* chore: wip* fix(article): wip* fix(article): enhance seed* chore: add link to repo & clean up
1 parent55c2a5f commitb07f1f9

File tree

79 files changed

+757
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+757
-296
lines changed

‎config/config.exs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ config :groupher_server, :article,
7878
# job: 10,
7979
# ...
8080
},
81+
# record count in article meta
82+
# works use 8
83+
max_upvoted_users_count:8,
8184

8285
# NOTE: if you want to add/remove emotion, just edit the list below
8386
# and migrate the field to table "articles_users_emotions"
@@ -104,7 +107,7 @@ config :groupher_server, :article,
104107
:pill,
105108
:popcorn
106109
],
107-
digest_length:120,
110+
digest_length:150,
108111
archive_threshold:%{
109112
# for post, blog, job, works, radar, job
110113
default:[weeks:-1],

‎lib/groupher_server/cms/cms.ex‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ defmodule GroupherServer.CMS do
199199
defdelegateseed_community(raw,type),to:Seeds
200200
defdelegateseed_community(raw),to:Seeds
201201
defdelegateseed_set_category(communities,category),to:Seeds
202+
defdelegateseed_articles(community,type),to:Seeds
203+
defdelegateseed_articles(community,type,count),to:Seeds
202204

203-
defdelegateseed_bot,to:Seeds
205+
defdelegateclean_up_community(raw),to:Seeds
206+
defdelegateclean_up_articles(community,type),to:Seeds
207+
208+
# defdelegate seed_bot, to: Seeds
204209
end

‎lib/groupher_server/cms/delegates/Seeds/domain.ex‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Domain do
2929
defseed_community(:home)do
3030
with{:error,_}<-ORM.find_by(Community,%{raw:"home"}),
3131
{:ok,bot}<-seed_bot(),
32-
{:ok,threads}<-seed_threads(:home),
33-
{:ok,categories}<-seed_categories_ifneed(bot)do
32+
{:ok,threads}<-seed_threads(:home)do
3433
args=%{
35-
title:"coderplanets",
34+
title:"CoderPlanets",
3635
desc:"the most sexy community for developers, ever.",
3736
logo:"#{@oss_endpoint}/icons/cmd/keyboard_logo.png",
3837
raw:"home",

‎lib/groupher_server/cms/delegates/Seeds/helper.ex‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,12 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Helper do
6565
threads=Seeds.Threads.get(type)
6666
threads_list=threads|>Enum.map(&&1.raw)
6767

68-
with{:error,_}<-ORM.find_by(Thread,%{raw:"post"})do
69-
threads|>Enum.each(&CMS.create_thread(&1))
70-
end
68+
threads
69+
|>Enum.each(fnthread->
70+
with{:error,_}<-ORM.find_by(Thread,%{raw:thread.raw})do
71+
CMS.create_thread(thread)
72+
end
73+
end)
7174

7275
Thread
7376
|>where([t],t.rawin^threads_list)

‎lib/groupher_server/cms/delegates/Seeds/seeds.ex‎

Lines changed: 69 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
33
seeds data for init, should be called ONLY in new database, like migration
44
"""
55

6-
importHelper.Utils,only:[done:1]
6+
importGroupherServer.Support.Factory
7+
importHelper.Utils,only:[done:1,get_config:2]
78
importEcto.Query,warn:false
89

910
importGroupherServer.CMS.Delegate.Seeds.Helper,
@@ -17,18 +18,14 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
1718
insert_community:3
1819
]
1920

20-
@oss_endpoint"https://cps-oss.oss-cn-shanghai.aliyuncs.com"
21-
# import Helper.Utils, only: [done: 1, map_atom_value: 2]
22-
# import GroupherServer.CMS.Delegate.ArticleCURD, only: [ensure_author_exists: 1]
23-
# import ShortMaps
24-
2521
aliasHelper.ORM
2622
aliasGroupherServer.CMS
2723

28-
aliasCMS.Model.{Community,Category}
24+
aliasCMS.Model.{Community,Category,Post}
2925
aliasCMS.Delegate.Seeds
3026
aliasSeeds.Domain
3127

28+
@article_threadsget_config(:article,:threads)
3229
# categories
3330
@community_types[:pl,:framework,:editor,:database,:devops,:city]
3431

@@ -76,4 +73,69 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
7673
{:ok,_}=CMS.set_category(%Community{id:community.id},%Category{id:category.id})
7774
end)
7875
end
76+
77+
defseed_articles(%Community{}=community,thread,count\\3)
78+
whenthreadin@article_threadsdo
79+
#
80+
thread_upcase=thread|>to_string|>String.upcase()
81+
tags_filter=%{community_id:community.id,thread:thread_upcase}
82+
83+
with{:ok,community}<-ORM.find(Community,community.id),
84+
{:ok,tags}<-CMS.paged_article_tags(tags_filter),
85+
{:ok,user}<-db_insert(:user)do
86+
1..count
87+
|>Enum.each(fn_->
88+
attrs=mock_attrs(thread,%{community_id:community.id})
89+
{:ok,article}=CMS.create_article(community,thread,attrs,user)
90+
seed_tags(tags,thread,article.id)
91+
seed_upvotes(thread,article.id)
92+
end)
93+
end
94+
end
95+
96+
defpseed_upvotes(thread,article_id)do
97+
with{:ok,users}<-db_insert_multi(:user,Enum.random(1..10))do
98+
users
99+
|>Enum.each(fnuser->
100+
{:ok,_article}=CMS.upvote_article(thread,article_id,user)
101+
end)
102+
end
103+
end
104+
105+
defpseed_tags(tags,thread,article_id)do
106+
get_tag_ids(tags,thread)
107+
|>Enum.each(fntag_id->
108+
{:ok,_}=CMS.set_article_tag(thread,article_id,tag_id)
109+
end)
110+
end
111+
112+
defpget_tag_ids(tags,:job)do
113+
tags.entries|>Enum.map(&&1.id)|>Enum.shuffle()|>Enum.take(3)
114+
end
115+
116+
defpget_tag_ids(tags,_)do
117+
tags.entries|>Enum.map(&&1.id)|>Enum.shuffle()|>Enum.take(1)
118+
end
119+
120+
# clean up
121+
122+
defclean_up(:all)do
123+
#
124+
end
125+
126+
defclean_up_community(raw)do
127+
with{:ok,community}<-ORM.findby_delete(Community,%{raw:to_string(raw)})do
128+
clean_up_articles(community,:post)
129+
end
130+
end
131+
132+
defclean_up_articles(%Community{}=community,:post)do
133+
Post
134+
|>join(:inner,[p],cinassoc(p,:original_community))
135+
|>where([p,c],c.id==^community.id)
136+
|>ORM.delete_all(:if_exist)
137+
|>done
138+
end
139+
140+
defclean_up_articles(_,_),do:{:ok,:pass}
79141
end

‎lib/groupher_server/cms/delegates/Seeds/tags.ex‎

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
1111
defrandom_color(),do:@tag_colors|>Enum.random()|>String.to_atom()
1212

1313
defget(_,:users,_),do:[]
14+
defget(_,:cper,_),do:[]
1415
defget(_,:setting,_),do:[]
1516
defget(_,:team,_),do:[]
1617

@@ -150,7 +151,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
150151
raw:"backend"
151152
},
152153
%{
153-
title:"iOS/Mac",
154+
title:"apple",
154155
raw:"apple"
155156
},
156157
%{
@@ -170,8 +171,12 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
170171
raw:"ai"
171172
},
172173
%{
173-
title:"运营 & 增长",
174-
raw:"marketing"
174+
title:"运营",
175+
raw:"growth"
176+
},
177+
%{
178+
title:"生活",
179+
raw:"life"
175180
},
176181
%{
177182
title:"其他",
@@ -189,13 +194,23 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
189194
group:"城市"
190195
},
191196
%{
192-
raw:"yrd",
193-
title:"长三角",
197+
raw:"shanghai",
198+
title:"上海",
199+
group:"城市"
200+
},
201+
%{
202+
raw:"hangzhou",
203+
title:"杭州",
194204
group:"城市"
195205
},
196206
%{
197-
raw:"prd",
198-
title:"珠三角",
207+
raw:"shenzhen",
208+
title:"深圳",
209+
group:"城市"
210+
},
211+
%{
212+
raw:"guangzhou",
213+
title:"广州",
199214
group:"城市"
200215
},
201216
%{
@@ -208,6 +223,11 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
208223
title:"成都",
209224
group:"城市"
210225
},
226+
%{
227+
raw:"xian",
228+
title:"西安",
229+
group:"城市"
230+
},
211231
%{
212232
raw:"xiamen",
213233
title:"厦门",
@@ -229,8 +249,8 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
229249
group:"城市"
230250
},
231251
%{
232-
raw:"web",
233-
title:"web前端",
252+
raw:"frontend",
253+
title:"前端",
234254
group:"职位"
235255
},
236256
%{
@@ -250,7 +270,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
250270
},
251271
%{
252272
raw:"devops",
253-
title:"运维",
273+
title:"DevOps",
254274
group:"职位"
255275
},
256276
%{
@@ -259,8 +279,8 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
259279
group:"职位"
260280
},
261281
%{
262-
raw:"DBA",
263-
title:"DBA",
282+
raw:"others",
283+
title:"其他",
264284
group:"职位"
265285
},
266286
%{
@@ -289,6 +309,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
289309
group:"薪资范围"
290310
}
291311
]
312+
|>Enum.map(fnattr->Map.merge(%{thread::job,color:random_color()},attr)end)
292313
end
293314

294315
## 首页 end

‎lib/groupher_server/cms/delegates/Seeds/threads.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Threads do
2323
},
2424
%{
2525
title:"CPer",
26-
raw:"users",
26+
raw:"cper",
2727
index:5
2828
},
2929
%{

‎lib/groupher_server/cms/delegates/article_collect.ex‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCollect do
4444
update_article_reactions_count(info,article,:collects_count,:inc)
4545
end)
4646
|>Multi.run(:update_article_reaction_user_list,fn_,_->
47-
update_article_reaction_user_list(:collect,article,user_id,:add)
47+
update_article_reaction_user_list(:collect,article,from_user,:add)
4848
end)
4949
|>Multi.run(:create_collect,fn_,_->
5050
thread=thread|>to_string|>String.upcase()
@@ -86,7 +86,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCollect do
8686
update_article_reactions_count(info,article,:collects_count,:dec)
8787
end)
8888
|>Multi.run(:update_article_reaction_user_list,fn_,_->
89-
update_article_reaction_user_list(:collect,article,user_id,:remove)
89+
update_article_reaction_user_list(:collect,article,from_user,:remove)
9090
end)
9191
|>Multi.run(:undo_collect,fn_,_->
9292
args=Map.put(%{user_id:user_id},info.foreign_key,article.id)

‎lib/groupher_server/cms/delegates/article_curd.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
550550
defpresult({:ok,%{set_viewer_has_states:result}}),do:result|>done()
551551
defpresult({:ok,%{update_article_meta:result}}),do:{:ok,result}
552552

553-
defpresult({:error,:create_article,result,_steps})do
553+
defpresult({:error,:create_article,_result,_steps})do
554554
{:error,[message:"create article",code:ecode(:create_fails)]}
555555
end
556556

‎lib/groupher_server/cms/delegates/article_tag.ex‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleTag do
131131
defpdo_update_article_tags_assoc(article,%ArticleTag{}=tag,opt)do
132132
article_tags=
133133
caseoptdo
134-
:add->article.article_tags++[tag]
134+
:add->(article.article_tags++[tag])|>Enum.uniq_by(&&1.id)
135135
:remove->article.article_tags--[tag]
136136
end
137137

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp