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

Commit 79dcb42

Browse files
committed
refactor(wip): wip
1 parent df9aa68 commit 79dcb42

File tree

23 files changed

+103
-90
lines changed

23 files changed

+103
-90
lines changed

config/config.exs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ config :logger, :console,
2020
format: "$time $metadata[$level] $message\n",
2121
metadata: [:request_id]
2222

23-
config :phoenix, :format_encoders, json: Jason
24-
config :ecto, json_library: Jason
23+
config :phoenix, :json_library, Jason
2524

2625
# TODO move this config to secret later
2726
config :mastani_server, Helper.Guardian,

lib/mastani_server/cms/delegates/seeds.ex

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
4747
{:ok, bot} <- seed_bot(),
4848
{:ok, categories} <- seed_categories(bot, :default),
4949
{:ok, communities} <- seed_for_communities(bot, :pl) do
50-
threadify_communities(communities, threads)
51-
tagfy_threads(communities, threads, bot)
50+
threadify_communities(communities, threads.entries)
51+
tagfy_threads(communities, threads.entries, bot)
5252
categorify_communities(communities, categories, :pl)
5353
end
5454
end
@@ -59,10 +59,10 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
5959
def seed_communities(:framework) do
6060
with {:ok, threads} <- seed_threads(:default),
6161
{:ok, bot} <- seed_bot(),
62-
{:ok, categories} <- seed_categories(bot, :default),
62+
{:ok, _categories} <- seed_categories(bot, :default),
6363
{:ok, communities} <- seed_for_communities(bot, :framework) do
64-
threadify_communities(communities, threads)
65-
tagfy_threads(communities, threads, bot)
64+
threadify_communities(communities, threads.entries)
65+
tagfy_threads(communities, threads.entries, bot)
6666

6767
# categorify_communities(communities, categories, :other)
6868
end
@@ -76,8 +76,8 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
7676
{:ok, bot} <- seed_bot(),
7777
{:ok, categories} <- seed_categories(bot, :default),
7878
{:ok, communities} <- seed_for_communities(bot, :editor) do
79-
threadify_communities(communities, threads)
80-
tagfy_threads(communities, threads, bot)
79+
threadify_communities(communities, threads.entries)
80+
tagfy_threads(communities, threads.entries, bot)
8181

8282
categorify_communities(communities, categories, :other)
8383
end
@@ -89,10 +89,10 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
8989
def seed_communities(:database) do
9090
with {:ok, threads} <- seed_threads(:default),
9191
{:ok, bot} <- seed_bot(),
92-
{:ok, categories} <- seed_categories(bot, :default),
92+
{:ok, _categories} <- seed_categories(bot, :default),
9393
{:ok, communities} <- seed_for_communities(bot, :database) do
94-
threadify_communities(communities, threads)
95-
tagfy_threads(communities, threads, bot)
94+
threadify_communities(communities, threads.entries)
95+
tagfy_threads(communities, threads.entries, bot)
9696

9797
# categorify_communities(communities, categories, :other)
9898
end
@@ -106,8 +106,8 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
106106
{:ok, bot} <- seed_bot(),
107107
{:ok, categories} <- seed_categories(bot, :default),
108108
{:ok, communities} <- seed_for_communities(bot, :devops) do
109-
threadify_communities(communities, threads)
110-
tagfy_threads(communities, threads, bot)
109+
threadify_communities(communities, threads.entries)
110+
tagfy_threads(communities, threads.entries, bot)
111111

112112
categorify_communities(communities, categories, :other)
113113
end
@@ -119,10 +119,10 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
119119
def seed_communities(:blockchain) do
120120
with {:ok, threads} <- seed_threads(:default),
121121
{:ok, bot} <- seed_bot(),
122-
{:ok, categories} <- seed_categories(bot, :default),
122+
{:ok, _categories} <- seed_categories(bot, :default),
123123
{:ok, communities} <- seed_for_communities(bot, :blockchain) do
124-
threadify_communities(communities, threads)
125-
tagfy_threads(communities, threads, bot)
124+
threadify_communities(communities, threads.entries)
125+
tagfy_threads(communities, threads.entries, bot)
126126

127127
# categorify_communities(communities, categories, :other)
128128
end
@@ -134,10 +134,10 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
134134
def seed_communities(:design) do
135135
with {:ok, threads} <- seed_threads(:default),
136136
{:ok, bot} <- seed_bot(),
137-
{:ok, categories} <- seed_categories(bot, :default),
137+
{:ok, _categories} <- seed_categories(bot, :default),
138138
{:ok, communities} <- seed_for_communities(bot, :design) do
139-
threadify_communities(communities, threads)
140-
tagfy_threads(communities, threads, bot)
139+
threadify_communities(communities, threads.entries)
140+
tagfy_threads(communities, threads.entries, bot)
141141

142142
# categorify_communities(communities, categories, :other)
143143
end
@@ -151,8 +151,8 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
151151
{:ok, bot} <- seed_bot(),
152152
{:ok, categories} <- seed_categories(bot, :default),
153153
{:ok, communities} <- seed_for_communities(bot, :city) do
154-
threadify_communities(communities, threads)
155-
tagfy_threads(communities, threads, bot, :city)
154+
threadify_communities(communities, threads.entries)
155+
tagfy_threads(communities, threads.entries, bot, :city)
156156
categorify_communities(communities, categories, :city)
157157
end
158158
end
@@ -174,9 +174,9 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
174174
}
175175

176176
{:ok, community} = Community |> ORM.create(args)
177-
threadify_communities(community, threads)
178177

179-
tagfy_threads(community, threads, bot, :home)
178+
threadify_communities(community, threads.entries)
179+
tagfy_threads(community, threads.entries, bot, :home)
180180
categorify_communities(community, categories, :other)
181181
end
182182
end
@@ -283,49 +283,49 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
283283
# seed raw communities, without thread or categories staff
284284
defp seed_for_communities(bot, :pl) do
285285
with {:error, _} <- ORM.find_by(Community, %{raw: "javascript"}) do
286-
{:ok, communities} = insert_multi_communities(bot, @pl_communities, :pl)
286+
{:ok, _communities} = insert_multi_communities(bot, @pl_communities, :pl)
287287
end
288288
end
289289

290290
defp seed_for_communities(bot, :framework) do
291291
with {:error, _} <- ORM.find_by(Community, %{raw: "react"}) do
292-
{:ok, communities} = insert_multi_communities(bot, @framework_communities, :framework)
292+
{:ok, _communities} = insert_multi_communities(bot, @framework_communities, :framework)
293293
end
294294
end
295295

296296
defp seed_for_communities(bot, :editor) do
297297
with {:error, _} <- ORM.find_by(Community, %{raw: "emacs"}) do
298-
{:ok, communities} = insert_multi_communities(bot, @editor_communities, :editor)
298+
{:ok, _communities} = insert_multi_communities(bot, @editor_communities, :editor)
299299
end
300300
end
301301

302302
defp seed_for_communities(bot, :database) do
303303
with {:error, _} <- ORM.find_by(Community, %{raw: "mysql"}) do
304-
{:ok, communities} = insert_multi_communities(bot, @database_communities, :database)
304+
{:ok, _communities} = insert_multi_communities(bot, @database_communities, :database)
305305
end
306306
end
307307

308308
defp seed_for_communities(bot, :devops) do
309309
with {:error, _} <- ORM.find_by(Community, %{raw: "cps-support"}) do
310-
{:ok, communities} = insert_multi_communities(bot, @devops_communities, :devops)
310+
{:ok, _communities} = insert_multi_communities(bot, @devops_communities, :devops)
311311
end
312312
end
313313

314314
defp seed_for_communities(bot, :blockchain) do
315315
with {:error, _} <- ORM.find_by(Community, %{raw: "bitcoin"}) do
316-
{:ok, communities} = insert_multi_communities(bot, @dblockchain_communities, :blockchain)
316+
{:ok, _communities} = insert_multi_communities(bot, @dblockchain_communities, :blockchain)
317317
end
318318
end
319319

320320
defp seed_for_communities(bot, :design) do
321321
with {:error, _} <- ORM.find_by(Community, %{raw: "css"}) do
322-
{:ok, communities} = insert_multi_communities(bot, @design_communities, :design)
322+
{:ok, _communities} = insert_multi_communities(bot, @design_communities, :design)
323323
end
324324
end
325325

326326
defp seed_for_communities(bot, :city) do
327327
with {:error, _} <- ORM.find_by(Community, %{raw: "chengdu"}) do
328-
{:ok, communities} = insert_multi_communities(bot, @city_communities, :city)
328+
{:ok, _communities} = insert_multi_communities(bot, @city_communities, :city)
329329
end
330330
end
331331

@@ -399,7 +399,7 @@ defmodule MastaniServer.CMS.Delegate.Seeds do
399399

400400
# tagfy only post job repo and video
401401

402-
defp tagfy_threads(communities, threads, bot, :city) when is_list(communities) do
402+
defp tagfy_threads(communities, _threads, bot, :city) when is_list(communities) do
403403
Enum.each(communities, fn community ->
404404
set_tags(community, :post, bot, :city)
405405
end)

lib/mastani_server/cms/job.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ defmodule MastaniServer.CMS.Job do
7070
on_replace: :delete
7171
)
7272

73-
timestamps(type: :utc_datetime)
73+
# timestamps(type: :utc_datetime)
74+
timestamps(type: :utc_datetime_usec)
7475
end
7576

7677
@doc false

lib/mastani_server/cms/post.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ defmodule MastaniServer.CMS.Post do
7474
on_replace: :delete
7575
)
7676

77-
timestamps(type: :utc_datetime)
77+
# timestamps(type: :utc_datetime)
78+
# for paged test to diff
79+
timestamps(type: :utc_datetime_usec)
7880
end
7981

8082
@doc false

lib/mastani_server/cms/repo.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ defmodule MastaniServer.CMS.Repo do
7373
on_replace: :delete
7474
)
7575

76-
timestamps(type: :utc_datetime)
76+
# timestamps(type: :utc_datetime)
77+
timestamps(type: :utc_datetime_usec)
7778
end
7879

7980
@doc false

lib/mastani_server/cms/video.ex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ defmodule MastaniServer.CMS.Video do
6464
on_replace: :delete
6565
)
6666

67-
timestamps(type: :utc_datetime)
67+
# timestamps(type: :utc_datetime)
68+
timestamps(type: :utc_datetime_usec)
6869
end
6970

7071
@doc false

lib/mastani_server/delivery/delegates/mentions.ex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ defmodule MastaniServer.Delivery.Delegate.Mentions do
3131
source_preview: info.source_preview,
3232
# timestamp are not auto-gen, see:
3333
# https://stackoverflow.com/questions/37537094/insert-all-does-not-create-auto-generated-inserted-at-with-ecto-2-0/46844417
34-
inserted_at: Ecto.DateTime.utc(),
35-
updated_at: Ecto.DateTime.utc()
34+
# Ecto.DateTime.utc(),
35+
inserted_at: DateTime.truncate(Timex.now(), :second),
36+
# Ecto.DateTime.utc()
37+
updated_at: DateTime.truncate(Timex.now(), :second)
3638
}
3739

3840
acc ++ [attrs]

lib/mastani_server/statistics/community_contribute.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ defmodule MastaniServer.Statistics.CommunityContribute do
1313
# field(:community_id, :id)
1414
belongs_to(:community, CMS.Community)
1515

16-
timestamps()
16+
timestamps(type: :utc_datetime)
1717
end
1818

1919
@doc false

lib/mastani_server/statistics/delegates/contribute.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ defmodule MastaniServer.Statistics.Delegate.Contribute do
4545
|> QueryBuilder.recent_inserted(months: @user_contribute_months)
4646
|> select([c], %{date: c.date, count: c.count})
4747
|> Repo.all()
48-
|> to_contrubutes_map()
48+
|> to_contributes_map()
4949
|> done
5050
end
5151

@@ -73,13 +73,12 @@ defmodule MastaniServer.Statistics.Delegate.Contribute do
7373
|> to_contribute_records()
7474
end
7575

76-
defp to_contrubutes_map(data) do
76+
defp to_contributes_map(data) do
7777
end_date = Timex.today()
7878
start_date = Timex.shift(Timex.today(), months: -6)
7979
total_count = Enum.reduce(data, 0, &(&1.count + &2))
8080

81-
records = to_contribute_records(data)
82-
81+
records = data
8382
~m(start_date end_date total_count records)a
8483
end
8584

@@ -121,8 +120,10 @@ defmodule MastaniServer.Statistics.Delegate.Contribute do
121120
end
122121

123122
defp convert_date(date) do
124-
{:ok, edate} = Date.from_erl(date)
125-
edate
123+
date
124+
# IO.inspect date, label: "convert_date"
125+
# {:ok, edate} = Date.to_string(date) #Date.from_erl(date)
126+
# edate
126127
end
127128

128129
defp inc_contribute_count(contribute, :community) do

lib/mastani_server/statistics/user_contribute.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ defmodule MastaniServer.Statistics.UserContribute do
1212
field(:date, :date)
1313
belongs_to(:user, Accounts.User)
1414

15-
timestamps()
15+
timestamps(type: :utc_datetime)
1616
end
1717

1818
@doc false

0 commit comments

Comments
 (0)