Thanks to visit codestin.com
Credit goes to github.com

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

Commit 47ec512

Browse files
authored
chore(prod): debug with prod data (#443)
1 parent f45e944 commit 47ec512

File tree

23 files changed

+824
-174
lines changed

23 files changed

+824
-174
lines changed

config/mock.exs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ config :phoenix, :stacktrace_depth, 20
1818
# Configure your database
1919
config :groupher_server, GroupherServer.Repo,
2020
adapter: Ecto.Adapters.Postgres,
21-
username: "postgres",
22-
password: "postgres",
23-
database: "groupher_server_mock",
24-
hostname: "localhost",
25-
pool_size: 10
21+
22+
# username: "postgres",
23+
# password: "postgres",
24+
# database: "groupher_server_mock",
25+
# hostname: "localhost",
26+
pool_size: 90
2627

2728
# config email services
2829
config :groupher_server, GroupherServer.Mailer, adapter: Bamboo.LocalAdapter

lib/groupher_server/cms/cms.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ defmodule GroupherServer.CMS do
4343
defdelegate is_community_exist?(raw), to: CommunityCURD
4444
defdelegate has_pending_community_apply?(user), to: CommunityCURD
4545

46+
# TODO: delete after prod seed
47+
defdelegate update_community_count_field(community, user_id, type, opt), to: CommunityCURD
48+
defdelegate update_community_count_field(community, thread), to: CommunityCURD
4649
# >> editor ..
4750
defdelegate update_editor(user, community, title), to: CommunityCURD
4851
# >> geo info ..
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
defmodule GroupherServer.CMS.Delegate.Seeds.Prod.Turning do
2+
@moduledoc """
3+
seeds data for init, should be called ONLY in new database, like migration
4+
"""
5+
6+
import GroupherServer.Support.Factory
7+
import Helper.Utils, only: [done: 1, get_config: 2]
8+
import Ecto.Query, warn: false
9+
10+
import GroupherServer.CMS.Delegate.Seeds.Helper,
11+
only: [
12+
threadify_communities: 2,
13+
tagfy_threads: 4,
14+
categorify_communities: 3,
15+
seed_bot: 0,
16+
seed_threads: 1,
17+
seed_categories_ifneed: 1,
18+
insert_community: 3
19+
]
20+
21+
alias Helper.ORM
22+
alias GroupherServer.CMS
23+
24+
alias CMS.Model.{Community, Thread, Category, Post, Comment}
25+
26+
@article_threads get_config(:article, :threads)
27+
# categories
28+
@community_types [:pl, :framework, :editor, :database, :devops, :city]
29+
30+
@comment_emotions get_config(:article, :comment_emotions)
31+
# seed community
32+
33+
def seed_home() do
34+
with {:ok, home_community} <- ORM.find_by(Community, %{raw: "home"}),
35+
{:ok, bot} <- seed_bot(),
36+
{:ok, threads} <- seed_threads(:home) do
37+
# IO.inspect(home_community, label: "seed_home_tags home_community")
38+
threadify_communities([home_community], threads.entries)
39+
tagfy_threads([home_community], threads.entries, bot, :home)
40+
end
41+
end
42+
43+
def seed_one_community(raw, category) do
44+
with {:ok, threads} <- seed_threads(category),
45+
{:ok, bot} <- seed_bot(),
46+
{:ok, community} <- ORM.find_by(Community, %{raw: to_string(raw)}) do
47+
threadify_communities([community], threads.entries)
48+
tagfy_threads([community], threads.entries, bot, category)
49+
end
50+
end
51+
52+
def seed_categories() do
53+
init_cats = [
54+
%{title: "编程语言", raw: "pl"},
55+
%{title: "框架/库", raw: "framework"},
56+
%{title: "开发平台", raw: "platform"},
57+
%{title: "设计交互", raw: "design"},
58+
%{title: "数据库", raw: "db"},
59+
%{title: "人工智能", raw: "ai"},
60+
%{title: "区块链", raw: "blockchain"},
61+
%{title: "作品 & 团队", raw: "works"},
62+
%{title: "城市", raw: "city"},
63+
%{title: "DevOps", raw: "devops"},
64+
%{title: "工具箱", raw: "toolbox"},
65+
%{title: "站务", raw: "community"},
66+
%{title: "其他", raw: "others"}
67+
]
68+
69+
with {:ok, bot} <- seed_bot() do
70+
init_cats
71+
|> Enum.reverse()
72+
|> Enum.each(fn cat ->
73+
{:ok, category} = CMS.create_category(cat, bot)
74+
Process.sleep(500)
75+
end)
76+
end
77+
end
78+
end

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

Lines changed: 81 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
1010

1111
def random_color(), do: @tag_colors |> Enum.random() |> String.to_atom()
1212

13-
def get(_, :users, _), do: []
13+
def get(_, :map, _), do: []
1414
def get(_, :cper, _), do: []
1515
def get(_, :setting, _), do: []
1616
def get(_, :team, _), do: []
17+
def get(_, :kanban, _), do: []
18+
def get(_, :works, _), do: []
19+
def get(_, :interview, _), do: []
1720

1821
## 首页 start
1922

@@ -378,43 +381,48 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
378381
[
379382
%{
380383
title: "Bug",
381-
raw: "bug"
384+
raw: "bug",
385+
group: "产品"
382386
},
383387
%{
384-
title: "官方公告",
385-
raw: "offical"
386-
},
387-
%{
388-
title: "产品建议",
389-
raw: "suggest"
388+
title: "功能建议",
389+
raw: "demand",
390+
group: "产品"
390391
},
391392
%{
392393
title: "内容审核",
393-
raw: "audit"
394+
raw: "audit",
395+
group: "产品"
394396
},
395397
%{
396398
title: "编辑器",
397-
raw: "editor"
399+
raw: "editor",
400+
group: "产品"
398401
},
399402
%{
400-
title: "UI/UX",
401-
raw: "UI"
403+
title: "界面交互",
404+
raw: "UI/UX",
405+
group: "产品"
402406
},
403407
%{
404-
title: "使用疑问",
405-
raw: "manual"
408+
title: "社区治理",
409+
raw: "manage",
410+
group: "产品"
406411
},
407412
%{
408-
title: "更新日志",
409-
raw: "log"
413+
title: "规章指南",
414+
raw: "intro",
415+
group: "其他"
410416
},
411417
%{
412-
title: "社区治理",
413-
raw: "management"
418+
title: "周报",
419+
raw: "devlog",
420+
group: "其他"
414421
},
415422
%{
416423
title: "其他",
417-
raw: "others"
424+
raw: "others",
425+
group: "其他"
418426
}
419427
]
420428
|> Enum.map(fn attr -> Map.merge(%{thread: :post, color: random_color()}, attr) end)
@@ -502,23 +510,38 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
502510
[
503511
%{
504512
title: "求助",
505-
raw: "help"
513+
raw: "help",
514+
group: "技术与工程"
515+
},
516+
%{
517+
title: "分享推荐",
518+
raw: "REC",
519+
group: "技术与工程"
506520
},
507521
%{
508522
title: "讨论",
509-
raw: "hangout"
523+
raw: "discuss",
524+
group: "技术与工程"
510525
},
511526
%{
512-
title: "推荐",
513-
raw: "REC"
527+
title: "学习资源",
528+
raw: "tuts",
529+
group: "技术与工程"
514530
},
515531
%{
516532
title: "小聚",
517-
raw: "meetup"
533+
raw: "meetup",
534+
group: "其他"
518535
},
519536
%{
520-
title: "其他",
521-
raw: "others"
537+
title: "杂谈",
538+
raw: "others",
539+
group: "其他"
540+
},
541+
%{
542+
title: "社区事务",
543+
raw: "routine",
544+
group: "其他"
522545
}
523546
]
524547
|> Enum.map(fn attr -> Map.merge(%{thread: :post, color: random_color()}, attr) end)
@@ -531,61 +554,69 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
531554
[
532555
%{
533556
title: "官方",
534-
raw: "offical"
557+
raw: "offical",
558+
group: "资讯"
535559
},
536560
%{
537-
title: "技术领袖",
538-
raw: "techlead"
561+
title: "业界新闻",
562+
raw: "news",
563+
group: "资讯"
539564
},
540565
%{
541-
title: "大V",
542-
raw: "influencer"
566+
title: "言论",
567+
raw: "views",
568+
group: "资讯"
569+
},
570+
%{
571+
title: "框架 / 库",
572+
raw: "release",
573+
group: "其他"
543574
},
544575
%{
545576
title: "有意思",
546-
raw: "intersting"
577+
raw: "others",
578+
group: "其他"
547579
}
548580
]
549581
|> Enum.map(fn attr -> Map.merge(%{thread: :radar, color: random_color()}, attr) end)
550582
end
551583

552584
def get(_, :blog, :pl) do
553-
get(:ignore, :blog, :framework) |> Enum.reject(&(&1.raw in ["arch", "eco"]))
585+
get(:ignore, :blog, :framework)
586+
# get(:ignore, :blog, :framework) |> Enum.reject(&(&1.raw in ["arch", "eco"]))
554587
end
555588

556589
def get(_, :blog, :framework) do
557590
[
558-
%{
559-
title: "教程",
560-
raw: "tuts"
561-
},
562591
%{
563592
title: "踩坑",
564-
raw: "trap"
565-
},
566-
%{
567-
title: "硬核",
568-
raw: "hardcore"
593+
raw: "trap",
594+
group: "工程"
569595
},
570596
%{
571597
title: "技巧",
572-
raw: "tips"
598+
raw: "tips",
599+
group: "工程"
573600
},
574601
%{
575-
title: "组织 & 架构",
576-
raw: "arch"
602+
title: "重构",
603+
raw: "clean-code",
604+
group: "工程"
577605
},
578606
%{
579-
title: "重构",
580-
raw: "clean-code"
607+
title: "教程",
608+
raw: "tuts",
609+
group: "其他"
581610
},
582611
%{
583612
title: "生态链",
584-
raw: "eco"
613+
raw: "eco",
614+
group: "其他"
585615
},
586616
%{
587-
title: "其他",
588-
raw: "others"
617+
title: "杂谈",
618+
raw: "others",
619+
group: "其他"
589620
}
590621
]
591622
|> Enum.map(fn attr -> Map.merge(%{thread: :blog, color: random_color()}, attr) end)
@@ -633,53 +664,6 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
633664

634665
## 语言与框架 end
635666

636-
@doc "post thread of FEEDBACK community"
637-
def get(%Community{raw: "feedback"}, :post) do
638-
[
639-
%{
640-
title: "Bug",
641-
raw: "bug"
642-
},
643-
%{
644-
title: "官方公告",
645-
raw: "official"
646-
},
647-
%{
648-
title: "需求池",
649-
raw: "demand"
650-
},
651-
%{
652-
title: "内容审核",
653-
raw: "audit"
654-
},
655-
%{
656-
title: "编辑器",
657-
raw: "editor"
658-
},
659-
%{
660-
title: "界面交互",
661-
raw: "UI/UX"
662-
},
663-
%{
664-
title: "使用疑问",
665-
raw: "ask"
666-
},
667-
%{
668-
title: "周报",
669-
raw: "changelog"
670-
},
671-
%{
672-
title: "社区治理",
673-
raw: "manage"
674-
},
675-
%{
676-
title: "其他",
677-
raw: "others"
678-
}
679-
]
680-
|> Enum.map(fn attr -> Map.merge(%{thread: :post, color: random_color()}, attr) end)
681-
end
682-
683667
@doc "post thread of BLACK community"
684668
def get(%Community{raw: "blackhole"}, :post) do
685669
[

0 commit comments

Comments
 (0)