Skip to content

Commit

Permalink
Merge pull request #9749 from keynslug/fix/count-respect-matchspec
Browse files Browse the repository at this point in the history
fix(paging): respect matchspec even if qs is empty when counting
  • Loading branch information
zmstone committed Jan 13, 2023
2 parents f25bd28 + 8c68f8e commit bb3dceb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
27 changes: 19 additions & 8 deletions apps/emqx_authz/test/emqx_authz_api_mnesia_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,17 @@ t_api(_) ->
]),
[]
),
#{
<<"data">> := [],
<<"meta">> := #{
<<"limit">> := 20,
<<"page">> := 1,
<<"hasnext">> := false
}
} = jsx:decode(Request1_1),
?assertEqual(
#{
<<"data">> => [],
<<"meta">> => #{
<<"limit">> => 20,
<<"page">> => 1,
<<"hasnext">> => false
}
},
jsx:decode(Request1_1)
),

{ok, 200, Request2} =
request(
Expand Down Expand Up @@ -160,6 +163,14 @@ t_api(_) ->
[]
),

% ensure that db contain a mix of records
{ok, 204, _} =
request(
post,
uri(["authorization", "sources", "built_in_database", "username"]),
[?USERNAME_RULES_EXAMPLE]
),

{ok, 204, _} =
request(
post,
Expand Down
6 changes: 3 additions & 3 deletions apps/emqx_management/src/emqx_mgmt_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,6 @@ apply_total_query(QueryState = #{table := Tab}) ->
Fun(Tab)
end.

counting_total_fun(_QueryState = #{qs := {[], []}}) ->
fun(Tab) -> ets:info(Tab, size) end;
counting_total_fun(_QueryState = #{match_spec := Ms, fuzzy_fun := undefined}) ->
%% XXX: Calculating the total number of data that match a certain
%% condition under a large table is very expensive because the
Expand All @@ -400,7 +398,9 @@ counting_total_fun(_QueryState = #{match_spec := Ms, fuzzy_fun := undefined}) ->
counting_total_fun(_QueryState = #{fuzzy_fun := FuzzyFun}) when FuzzyFun =/= undefined ->
%% XXX: Calculating the total number for a fuzzy searching is very very expensive
%% so it is not supported now
false.
false;
counting_total_fun(_QueryState = #{qs := {[], []}}) ->
fun(Tab) -> ets:info(Tab, size) end.

%% ResultAcc :: #{count := integer(),
%% cursor := integer(),
Expand Down
1 change: 1 addition & 0 deletions changes/v5.0.15/fix-9749-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
In some cases search APIs could respond with an incorrect `count` value in the metadata, that is usually much bigger than expected, this is now fixed.
1 change: 1 addition & 0 deletions changes/v5.0.15/fix-9749-zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
在某些情况下,搜索 API 可能会在元数据中响应不正确的 `count` 值,这通常比预期的要大得多,现在已经修复了。

0 comments on commit bb3dceb

Please sign in to comment.