Skip to content

Commit

Permalink
Optimize org channel accessibility query
Browse files Browse the repository at this point in the history
  • Loading branch information
nadvornik committed Aug 10, 2023
1 parent e675676 commit c164afc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
40 changes: 34 additions & 6 deletions java/code/src/com/redhat/rhn/domain/channel/Channel.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,40 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
</sql-query>

<sql-query name="Channel.isAccessibleBy">
<return-scalar type="int" column="count"/>
SELECT COUNT(*) AS count
FROM rhnChannel c
JOIN rhnAvailableChannels ac ON c.id = ac.channel_id
WHERE c.label = :channel_label
AND ac.org_id = :org_id
<return-scalar type="int" column="result"/>
<![CDATA[SELECT case when (EXISTS (
SELECT 1
FROM rhnChannel c
JOIN rhnChannelFamilyMembers cfm ON cfm.channel_id = c.id
JOIN rhnPublicChannelFamily pcf ON pcf.channel_family_id = cfm.channel_family_id
WHERE c.label = :channel_label
LIMIT 1
) OR EXISTS (
SELECT 1
FROM rhnChannel c
JOIN rhnChannelFamilyMembers cfm ON cfm.channel_id = c.id
JOIN rhnPrivateChannelFamily pcf ON pcf.channel_family_id = cfm.channel_family_id
WHERE c.label = :channel_label
AND pcf.org_id = :org_id
LIMIT 1
) OR EXISTS (
SELECT 1
FROM rhnChannel c
JOIN rhnTrustedOrgs tr ON c.org_id = tr.org_id
WHERE c.parent_channel IS NULL AND c.channel_access = 'public'
AND c.label = :channel_label
AND tr.org_trust_id = :org_id
LIMIT 1
) OR EXISTS (
SELECT 1
FROM rhnChannel c
JOIN rhnChannelTrust tr ON c.id = tr.channel_id
WHERE c.channel_access = 'protected'
AND c.label = :channel_label
AND tr.org_trust_id = :org_id
LIMIT 1
)) then 1 else 0 end AS result
]]>
</sql-query>

<sql-query name="Channel.isAccessibleByUser">
Expand Down
1 change: 1 addition & 0 deletions java/spacewalk-java.changes.nadvornik.channel_access
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Optimize org channel accessibility query (bsc#1211874)

0 comments on commit c164afc

Please sign in to comment.