Skip to content

Commit

Permalink
mod_acl_user_groups: use psql 'any' instead of nested query (0.x) (#3215
Browse files Browse the repository at this point in the history
)

* mod_acl_user_groups: use psql 'any' instead of nested query.

Also use '= true/false' for is_published checks, as that helps with picking the correct index values
  • Loading branch information
mworrell committed Dec 19, 2022
1 parent a0d72d0 commit 4a80150
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ acl_add_sql_check(#acl_add_sql_check{alias=Alias, args=Args, search_sql=SearchSq
% User can see some content groups
Clause = lists:flatten([
" (",Alias,".content_group_id is null or ",
Alias,".content_group_id in (SELECT(unnest($",integer_to_list(length(Args)+1),"::int[]))))",
Alias,".content_group_id = any($",integer_to_list(length(Args)+1),"::int[]))",
publish_check(" and ", Alias, SearchSql, Context)]),
{Clause, Args ++ [Ids]}
end
Expand All @@ -415,7 +415,7 @@ publish_check(MaybeAnd, Alias, #search_sql{extra=Extra}, Context) ->
"";
false ->
[MaybeAnd,
Alias,".is_published and ",
Alias,".is_published = true and ",
Alias,".publication_start <= now() and ",
Alias,".publication_end >= now()"]
end.
Expand Down
4 changes: 2 additions & 2 deletions modules/mod_search/support/search_query.erl
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,12 @@ parse_query([{is_published, Boolean}|Rest], Context, Result) ->
_ ->
Result2 = case z_convert:to_bool(Boolean) of
true ->
add_where("rsc.is_published and "
add_where("rsc.is_published = true and "
"rsc.publication_start <= now() and "
"rsc.publication_end >= now()",
Result1);
false ->
add_where("(not rsc.is_published or "
add_where("(rsc.is_published = false or "
"rsc.publication_start > now() or "
"rsc.publication_end < now())",
Result1)
Expand Down

0 comments on commit 4a80150

Please sign in to comment.