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.

refactor: debug new schema#429

Merged
mydearxym merged 25 commits intodevfromdebug-new-schema
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
25 commits
Select commitHold shift + click to select a range
e8e50b7
chore(community): missing field
mydearxymAug 24, 2021
901ed9a
refactor: add some seed
mydearxymAug 25, 2021
b34b5ec
refactor: fmt
mydearxymAug 25, 2021
4766d38
refactor: seeds script for debug
mydearxymAug 25, 2021
c9dee45
chore: wip
mydearxymAug 25, 2021
9c15667
fix: modeule naming
mydearxymAug 25, 2021
078cd34
fix: digest length test case
mydearxymAug 25, 2021
0acdff5
chore: wip
mydearxymAug 26, 2021
0125a61
chore: seed fix
mydearxymAug 27, 2021
1f8a3d9
chore: debug
mydearxymAug 28, 2021
a737dc1
chore: radar & article tags enhance
mydearxymAug 29, 2021
5dc8446
refactor(article-meta): add latest_upvoted_users
mydearxymAug 31, 2021
ebfb88c
refactor(test): imporve exsit_in / exist_user_in
mydearxymAug 31, 2021
b06f3cc
fix(article): digest length test case
mydearxymAug 31, 2021
9b0d398
fix(article): tag tests
mydearxymAug 31, 2021
e1cf65a
fix(article): tag tests
mydearxymAug 31, 2021
581c0bd
fix(article): tag tests
mydearxymAug 31, 2021
69f0b92
fix: article gq workflow args
mydearxymAug 31, 2021
47783e4
fix: article tag tests
mydearxymSep 1, 2021
ee922ac
fix: article tag tests
mydearxymSep 1, 2021
d749056
fix: article tag tests
mydearxymSep 1, 2021
295d0fa
chore: wip
mydearxymSep 1, 2021
e60108c
fix(article): wip
mydearxymSep 3, 2021
8dd0274
fix(article): enhance seed
mydearxymSep 4, 2021
96095c1
chore: add link to repo & clean up
mydearxymSep 7, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletionconfig/config.exs
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -78,6 +78,9 @@ config :groupher_server, :article,
# job: 10,
# ...
},
# record count in article meta
# works use 8
max_upvoted_users_count: 8,

# NOTE: if you want to add/remove emotion, just edit the list below
# and migrate the field to table "articles_users_emotions"
Expand All@@ -104,7 +107,7 @@ config :groupher_server, :article,
:pill,
:popcorn
],
digest_length:120,
digest_length:150,
archive_threshold: %{
# for post, blog, job, works, radar, job
default: [weeks: -1],
Expand Down
7 changes: 6 additions & 1 deletionlib/groupher_server/cms/cms.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -199,6 +199,11 @@ defmodule GroupherServer.CMS do
defdelegate seed_community(raw, type), to: Seeds
defdelegate seed_community(raw), to: Seeds
defdelegate seed_set_category(communities, category), to: Seeds
defdelegate seed_articles(community, type), to: Seeds
defdelegate seed_articles(community, type, count), to: Seeds

defdelegate seed_bot, to: Seeds
defdelegate clean_up_community(raw), to: Seeds
defdelegate clean_up_articles(community, type), to: Seeds

# defdelegate seed_bot, to: Seeds
end
5 changes: 2 additions & 3 deletionslib/groupher_server/cms/delegates/Seeds/domain.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,10 +29,9 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Domain do
def seed_community(:home) do
with {:error, _} <- ORM.find_by(Community, %{raw: "home"}),
{:ok, bot} <- seed_bot(),
{:ok, threads} <- seed_threads(:home),
{:ok, categories} <- seed_categories_ifneed(bot) do
{:ok, threads} <- seed_threads(:home) do
args = %{
title: "coderplanets",
title: "CoderPlanets",
desc: "the most sexy community for developers, ever.",
logo: "#{@oss_endpoint}/icons/cmd/keyboard_logo.png",
raw: "home",
Expand Down
9 changes: 6 additions & 3 deletionslib/groupher_server/cms/delegates/Seeds/helper.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,9 +65,12 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Helper do
threads = Seeds.Threads.get(type)
threads_list = threads |> Enum.map(& &1.raw)

with {:error, _} <- ORM.find_by(Thread, %{raw: "post"}) do
threads |> Enum.each(&CMS.create_thread(&1))
end
threads
|> Enum.each(fn thread ->
with {:error, _} <- ORM.find_by(Thread, %{raw: thread.raw}) do
CMS.create_thread(thread)
end
end)

Thread
|> where([t], t.raw in ^threads_list)
Expand Down
76 changes: 69 additions & 7 deletionslib/groupher_server/cms/delegates/Seeds/seeds.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,7 +3,8 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
seeds data for init, should be called ONLY in new database, like migration
"""

import Helper.Utils, only: [done: 1]
import GroupherServer.Support.Factory
import Helper.Utils, only: [done: 1, get_config: 2]
import Ecto.Query, warn: false

import GroupherServer.CMS.Delegate.Seeds.Helper,
Expand All@@ -17,18 +18,14 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
insert_community: 3
]

@oss_endpoint "https://cps-oss.oss-cn-shanghai.aliyuncs.com"
# import Helper.Utils, only: [done: 1, map_atom_value: 2]
# import GroupherServer.CMS.Delegate.ArticleCURD, only: [ensure_author_exists: 1]
# import ShortMaps

alias Helper.ORM
alias GroupherServer.CMS

alias CMS.Model.{Community, Category}
alias CMS.Model.{Community, Category, Post}
alias CMS.Delegate.Seeds
alias Seeds.Domain

@article_threads get_config(:article, :threads)
# categories
@community_types [:pl, :framework, :editor, :database, :devops, :city]

Expand DownExpand Up@@ -76,4 +73,69 @@ defmodule GroupherServer.CMS.Delegate.Seeds do
{:ok, _} = CMS.set_category(%Community{id: community.id}, %Category{id: category.id})
end)
end

def seed_articles(%Community{} = community, thread, count \\ 3)
when thread in @article_threads do
#
thread_upcase = thread |> to_string |> String.upcase()
tags_filter = %{community_id: community.id, thread: thread_upcase}

with {:ok, community} <- ORM.find(Community, community.id),
{:ok, tags} <- CMS.paged_article_tags(tags_filter),
{:ok, user} <- db_insert(:user) do
1..count
|> Enum.each(fn _ ->
attrs = mock_attrs(thread, %{community_id: community.id})
{:ok, article} = CMS.create_article(community, thread, attrs, user)
seed_tags(tags, thread, article.id)
seed_upvotes(thread, article.id)
end)
end
end

defp seed_upvotes(thread, article_id) do
with {:ok, users} <- db_insert_multi(:user, Enum.random(1..10)) do
users
|> Enum.each(fn user ->
{:ok, _article} = CMS.upvote_article(thread, article_id, user)
end)
end
end

defp seed_tags(tags, thread, article_id) do
get_tag_ids(tags, thread)
|> Enum.each(fn tag_id ->
{:ok, _} = CMS.set_article_tag(thread, article_id, tag_id)
end)
end

defp get_tag_ids(tags, :job) do
tags.entries |> Enum.map(& &1.id) |> Enum.shuffle() |> Enum.take(3)
end

defp get_tag_ids(tags, _) do
tags.entries |> Enum.map(& &1.id) |> Enum.shuffle() |> Enum.take(1)
end

# clean up

def clean_up(:all) do
#
end

def clean_up_community(raw) do
with {:ok, community} <- ORM.findby_delete(Community, %{raw: to_string(raw)}) do
clean_up_articles(community, :post)
end
end

def clean_up_articles(%Community{} = community, :post) do
Post
|> join(:inner, [p], c in assoc(p, :original_community))
|> where([p, c], c.id == ^community.id)
|> ORM.delete_all(:if_exist)
|> done
end

def clean_up_articles(_, _), do: {:ok, :pass}
end
45 changes: 33 additions & 12 deletionslib/groupher_server/cms/delegates/Seeds/tags.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,6 +11,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
def random_color(), do: @tag_colors |> Enum.random() |> String.to_atom()

def get(_, :users, _), do: []
def get(_, :cper, _), do: []
def get(_, :setting, _), do: []
def get(_, :team, _), do: []

Expand DownExpand Up@@ -150,7 +151,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
raw: "backend"
},
%{
title: "iOS/Mac",
title: "apple",
raw: "apple"
},
%{
Expand All@@ -170,8 +171,12 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
raw: "ai"
},
%{
title: "运营 & 增长",
raw: "marketing"
title: "运营",
raw: "growth"
},
%{
title: "生活",
raw: "life"
},
%{
title: "其他",
Expand All@@ -189,13 +194,23 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
group: "城市"
},
%{
raw: "yrd",
title: "长三角",
raw: "shanghai",
title: "上海",
group: "城市"
},
%{
raw: "hangzhou",
title: "杭州",
group: "城市"
},
%{
raw: "prd",
title: "珠三角",
raw: "shenzhen",
title: "深圳",
group: "城市"
},
%{
raw: "guangzhou",
title: "广州",
group: "城市"
},
%{
Expand All@@ -208,6 +223,11 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
title: "成都",
group: "城市"
},
%{
raw: "xian",
title: "西安",
group: "城市"
},
%{
raw: "xiamen",
title: "厦门",
Expand All@@ -229,8 +249,8 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
group: "城市"
},
%{
raw: "web",
title: "web前端",
raw: "frontend",
title: "前端",
group: "职位"
},
%{
Expand All@@ -250,7 +270,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
},
%{
raw: "devops",
title: "运维",
title: "DevOps",
group: "职位"
},
%{
Expand All@@ -259,8 +279,8 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
group: "职位"
},
%{
raw: "DBA",
title: "DBA",
raw: "others",
title: "其他",
group: "职位"
},
%{
Expand DownExpand Up@@ -289,6 +309,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Tags do
group: "薪资范围"
}
]
|> Enum.map(fn attr -> Map.merge(%{thread: :job, color: random_color()}, attr) end)
end

## 首页 end
Expand Down
2 changes: 1 addition & 1 deletionlib/groupher_server/cms/delegates/Seeds/threads.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -23,7 +23,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Threads do
},
%{
title: "CPer",
raw: "users",
raw: "cper",
index: 5
},
%{
Expand Down
4 changes: 2 additions & 2 deletionslib/groupher_server/cms/delegates/article_collect.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -44,7 +44,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCollect do
update_article_reactions_count(info, article, :collects_count, :inc)
end)
|> Multi.run(:update_article_reaction_user_list, fn _, _ ->
update_article_reaction_user_list(:collect, article,user_id, :add)
update_article_reaction_user_list(:collect, article,from_user, :add)
end)
|> Multi.run(:create_collect, fn _, _ ->
thread = thread |> to_string |> String.upcase()
Expand DownExpand Up@@ -86,7 +86,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCollect do
update_article_reactions_count(info, article, :collects_count, :dec)
end)
|> Multi.run(:update_article_reaction_user_list, fn _, _ ->
update_article_reaction_user_list(:collect, article,user_id, :remove)
update_article_reaction_user_list(:collect, article,from_user, :remove)
end)
|> Multi.run(:undo_collect, fn _, _ ->
args = Map.put(%{user_id: user_id}, info.foreign_key, article.id)
Expand Down
2 changes: 1 addition & 1 deletionlib/groupher_server/cms/delegates/article_curd.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -550,7 +550,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCURD do
defp result({:ok, %{set_viewer_has_states: result}}), do: result |> done()
defp result({:ok, %{update_article_meta: result}}), do: {:ok, result}

defp result({:error, :create_article,result, _steps}) do
defp result({:error, :create_article,_result, _steps}) do
{:error, [message: "create article", code: ecode(:create_fails)]}
end

Expand Down
2 changes: 1 addition & 1 deletionlib/groupher_server/cms/delegates/article_tag.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -131,7 +131,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleTag do
defp do_update_article_tags_assoc(article, %ArticleTag{} = tag, opt) do
article_tags =
case opt do
:add -> article.article_tags ++ [tag]
:add ->(article.article_tags ++ [tag]) |> Enum.uniq_by(& &1.id)
:remove -> article.article_tags -- [tag]
end

Expand Down
4 changes: 2 additions & 2 deletionslib/groupher_server/cms/delegates/article_upvote.ex
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,7 +37,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleUpvote do
update_article_reactions_count(info, article, :upvotes_count, :inc)
end)
|> Multi.run(:update_article_reaction_user_list, fn _, _ ->
update_article_reaction_user_list(:upvot, article,user_id, :add)
update_article_reaction_user_list(:upvot, article,from_user, :add)
end)
|> Multi.run(:add_achievement, fn _, _ ->
achiever_id = article.author.user_id
Expand DownExpand Up@@ -68,7 +68,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleUpvote do
update_article_reactions_count(info, article, :upvotes_count, :dec)
end)
|> Multi.run(:update_article_reaction_user_list, fn _, _ ->
update_article_reaction_user_list(:upvot, article,user_id, :remove)
update_article_reaction_user_list(:upvot, article,from_user, :remove)
end)
|> Multi.run(:undo_upvote, fn _, _ ->
args = Map.put(%{user_id: user_id}, info.foreign_key, article.id)
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp