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

Commit 0f758aa

Browse files
committed
chore: Merge branch 'dev'
2 parents 62a57d3 + b4a3abf commit 0f758aa

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed
228 Bytes
Binary file not shown.

lib/groupher_server/cms/utils/loader.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,9 @@ defmodule GroupherServer.CMS.Utils.Loader do
181181
def query({"posts_comments", PostComment}, %{filter: filter, unique: true}) do
182182
PostComment
183183
|> join(:inner, [c], a in assoc(c, :author))
184-
|> distinct([c, a], a.id)
184+
# NOTE: this distinct not working in production env, so the uniq logic is move to
185+
# cut_participators.ex middleware, when the data is large, will cause performace issue
186+
# |> distinct([c, a], a.id)
185187
|> select([c, a], a)
186188

187189
# |> select([c, a], %{

lib/groupher_server_web/middleware/cut_participators.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ defmodule GroupherServerWeb.Middleware.CutParticipators do
88
# should use WINDOW function
99
# see https://github.com/coderplanets/coderplanets_server/issues/16
1010
#
11+
# the Enum.uniq logic is a tmp sulution for distinct comments users, this should be
12+
# in dataloader logic, but the distinct is not working in production env
1113
"""
1214

1315
@behaviour Absinthe.Middleware
@@ -16,11 +18,14 @@ defmodule GroupherServerWeb.Middleware.CutParticipators do
1618
def call(%{errors: errors} = resolution, _) when length(errors) > 0, do: resolution
1719

1820
def call(%{value: value, arguments: %{filter: %{first: first}} = args} = resolution, _) do
19-
%{resolution | value: value |> Enum.reverse() |> Enum.slice(0, first)}
21+
%{resolution | value: value |> Enum.uniq() |> Enum.reverse() |> Enum.slice(0, first)}
2022
end
2123

2224
def call(%{value: value} = resolution, _) do
23-
%{resolution | value: value |> Enum.reverse() |> Enum.slice(0, @default_length)}
25+
%{
26+
resolution
27+
| value: value |> Enum.uniq() |> Enum.reverse() |> Enum.slice(0, @default_length)
28+
}
2429
end
2530

2631
def call(resolution, _), do: resolution

0 commit comments

Comments
 (0)