refactor:优化页面查询速度

This commit is contained in:
wangjiahao 2021-08-24 16:51:09 +08:00
parent 596a6ef0bf
commit 8d6d49eb14
6 changed files with 259 additions and 11 deletions

View File

@ -12,8 +12,39 @@
<select id="search" resultMap="BaseResultMapDTO"> <select id="search" resultMap="BaseResultMapDTO">
select select
id, `name`, ifnull(pid,0) as pid, `level`, `type`, create_by, create_time,`name` as label, id, `name`, ifnull(pid,0) as pid, `level`, `type`, create_by, create_time,`name` as label,
get_auths(id,'chart',#{userId}) as `privileges` authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'chart') cids) t,chart_group from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'chart') cids) t,chart_group
left join (
SELECT
auth_source,
group_concat( DISTINCT sys_auth_detail.privilege_extend ) as `privileges`
FROM
(
`sys_auth`
LEFT JOIN `sys_auth_detail` ON ((
`sys_auth`.`id` = `sys_auth_detail`.`auth_id`
)))
WHERE
sys_auth_detail.privilege_value = 1
AND sys_auth.auth_source_type = 'chart'
AND (
(
sys_auth.auth_target_type = 'dept'
AND sys_auth.auth_target IN ( SELECT dept_id FROM sys_user WHERE user_id = #{userId} )
)
OR (
sys_auth.auth_target_type = 'user'
AND sys_auth.auth_target = #{userId}
)
OR (
sys_auth.auth_target_type = 'role'
AND sys_auth.auth_target IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{userId} )
)
)
GROUP BY
`sys_auth`.`auth_source`
) authInfo
on chart_group.id = authInfo.auth_source
<where> <where>
FIND_IN_SET(chart_group.id,cids) FIND_IN_SET(chart_group.id,cids)
<if test="id != null"> <if test="id != null">

View File

@ -32,8 +32,39 @@
select select
id, `name`, scene_id, table_id, `type`, title, create_by, create_time, update_time, id, `name`, scene_id, table_id, `type`, title, create_by, create_time, update_time,
style_priority,x_axis, y_axis, custom_attr, custom_style, custom_filter, snapshot, style_priority,x_axis, y_axis, custom_attr, custom_style, custom_filter, snapshot,
get_auths(id,'chart',#{userId}) as `privileges` authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'chart') cids) t,chart_view from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'chart') cids) t,chart_view
left join (
SELECT
auth_source,
group_concat( DISTINCT sys_auth_detail.privilege_extend ) as `privileges`
FROM
(
`sys_auth`
LEFT JOIN `sys_auth_detail` ON ((
`sys_auth`.`id` = `sys_auth_detail`.`auth_id`
)))
WHERE
sys_auth_detail.privilege_value = 1
AND sys_auth.auth_source_type = 'chart'
AND (
(
sys_auth.auth_target_type = 'dept'
AND sys_auth.auth_target IN ( SELECT dept_id FROM sys_user WHERE user_id = #{userId} )
)
OR (
sys_auth.auth_target_type = 'user'
AND sys_auth.auth_target = #{userId}
)
OR (
sys_auth.auth_target_type = 'role'
AND sys_auth.auth_target IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{userId} )
)
)
GROUP BY
`sys_auth`.`auth_source`
) authInfo
on chart_view.id = authInfo.auth_source
<where> <where>
FIND_IN_SET(chart_view.id,cids) FIND_IN_SET(chart_view.id,cids)
<if test="sceneId != null"> <if test="sceneId != null">

View File

@ -12,8 +12,39 @@
<select id="search" resultMap="BaseResultMapDTO"> <select id="search" resultMap="BaseResultMapDTO">
select select
id, `name`, ifnull(pid,0) as pid, `level`, `type`, create_by, create_time,`name` as label, id, `name`, ifnull(pid,0) as pid, `level`, `type`, create_by, create_time,`name` as label,
get_auths(id,'dataset',#{userId}) as `privileges` authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'dataset') cids) t,dataset_group from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'dataset') cids) t,dataset_group
left join (
SELECT
auth_source,
group_concat( DISTINCT sys_auth_detail.privilege_extend ) as `privileges`
FROM
(
`sys_auth`
LEFT JOIN `sys_auth_detail` ON ((
`sys_auth`.`id` = `sys_auth_detail`.`auth_id`
)))
WHERE
sys_auth_detail.privilege_value = 1
AND sys_auth.auth_source_type = 'dataset'
AND (
(
sys_auth.auth_target_type = 'dept'
AND sys_auth.auth_target IN ( SELECT dept_id FROM sys_user WHERE user_id = #{userId} )
)
OR (
sys_auth.auth_target_type = 'user'
AND sys_auth.auth_target = #{userId}
)
OR (
sys_auth.auth_target_type = 'role'
AND sys_auth.auth_target IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{userId} )
)
)
GROUP BY
`sys_auth`.`auth_source`
) authInfo
on dataset_group.id = authInfo.auth_source
<where> <where>
FIND_IN_SET(dataset_group.id,cids) FIND_IN_SET(dataset_group.id,cids)
<if test="id != null"> <if test="id != null">

View File

@ -38,8 +38,39 @@
<select id="search" resultMap="BaseResultMapDTO"> <select id="search" resultMap="BaseResultMapDTO">
select select
id, `name`, scene_id, data_source_id, `type`, `mode`,`info`, create_by, create_time, id, `name`, scene_id, data_source_id, `type`, `mode`,`info`, create_by, create_time,
get_auths(id,'dataset',#{userId}) as `privileges` authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'dataset') cids) t,dataset_table from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'dataset') cids) t,dataset_table
left join (
SELECT
auth_source,
group_concat( DISTINCT sys_auth_detail.privilege_extend ) as `privileges`
FROM
(
`sys_auth`
LEFT JOIN `sys_auth_detail` ON ((
`sys_auth`.`id` = `sys_auth_detail`.`auth_id`
)))
WHERE
sys_auth_detail.privilege_value = 1
AND sys_auth.auth_source_type = 'dataset'
AND (
(
sys_auth.auth_target_type = 'dept'
AND sys_auth.auth_target IN ( SELECT dept_id FROM sys_user WHERE user_id = #{userId} )
)
OR (
sys_auth.auth_target_type = 'user'
AND sys_auth.auth_target = #{userId}
)
OR (
sys_auth.auth_target_type = 'role'
AND sys_auth.auth_target IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{userId} )
)
)
GROUP BY
`sys_auth`.`auth_source`
) authInfo
on dataset_table.id = authInfo.auth_source
<where> <where>
FIND_IN_SET(dataset_table.id,cids) FIND_IN_SET(dataset_table.id,cids)
<if test="sceneId != null"> <if test="sceneId != null">

View File

@ -9,8 +9,39 @@
<select id="query" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="BaseResultMapDTO"> <select id="query" parameterType="io.dataease.base.mapper.ext.query.GridExample" resultMap="BaseResultMapDTO">
select id , name , `desc` ,`type` , configuration ,create_time ,update_time, select id , name , `desc` ,`type` , configuration ,create_time ,update_time,
get_auths(id,'link',#{extendCondition}) as `privileges` authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{extendCondition}, 'link') cids) t,datasource from (select GET_V_AUTH_MODEL_ID_P_USE (#{extendCondition}, 'link') cids) t,datasource
left join (
SELECT
auth_source,
group_concat( DISTINCT sys_auth_detail.privilege_extend ) as `privileges`
FROM
(
`sys_auth`
LEFT JOIN `sys_auth_detail` ON ((
`sys_auth`.`id` = `sys_auth_detail`.`auth_id`
)))
WHERE
sys_auth_detail.privilege_value = 1
AND sys_auth.auth_source_type = 'link'
AND (
(
sys_auth.auth_target_type = 'dept'
AND sys_auth.auth_target IN ( SELECT dept_id FROM sys_user WHERE user_id = #{extendCondition} )
)
OR (
sys_auth.auth_target_type = 'user'
AND sys_auth.auth_target = #{extendCondition}
)
OR (
sys_auth.auth_target_type = 'role'
AND sys_auth.auth_target IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{extendCondition} )
)
)
GROUP BY
`sys_auth`.`auth_source`
) authInfo
on datasource.id = authInfo.auth_source
<if test="_parameter != null"> <if test="_parameter != null">
<include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" /> <include refid="io.dataease.base.mapper.ext.query.GridSql.gridCondition" />
</if> </if>
@ -25,8 +56,39 @@
<select id="queryUnion" resultMap="BaseResultMapDTO"> <select id="queryUnion" resultMap="BaseResultMapDTO">
select id , name , `desc` ,`type` , configuration ,create_time ,update_time, status, select id , name , `desc` ,`type` , configuration ,create_time ,update_time, status,
get_auths(id,'link',#{userId}) as `privileges` authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'link') cids) t,datasource from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'link') cids) t,datasource
left join (
SELECT
auth_source,
group_concat( DISTINCT sys_auth_detail.privilege_extend ) as `privileges`
FROM
(
`sys_auth`
LEFT JOIN `sys_auth_detail` ON ((
`sys_auth`.`id` = `sys_auth_detail`.`auth_id`
)))
WHERE
sys_auth_detail.privilege_value = 1
AND sys_auth.auth_source_type = 'chart'
AND (
(
sys_auth.auth_target_type = 'dept'
AND sys_auth.auth_target IN ( SELECT dept_id FROM sys_user WHERE user_id = #{userId} )
)
OR (
sys_auth.auth_target_type = 'user'
AND sys_auth.auth_target = #{userId}
)
OR (
sys_auth.auth_target_type = 'role'
AND sys_auth.auth_target IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{userId} )
)
)
GROUP BY
`sys_auth`.`auth_source`
) authInfo
on datasource.id = authInfo.auth_source
<where> <where>
FIND_IN_SET(datasource.id,cids) FIND_IN_SET(datasource.id,cids)
<if test="id != null"> <if test="id != null">

View File

@ -30,10 +30,41 @@
panel_group.`source`, panel_group.`source`,
panel_group.`panel_type`, panel_group.`panel_type`,
sourcePanelGroup.`name` as source_panel_name, sourcePanelGroup.`name` as source_panel_name,
get_auths(panel_group.id,'panel',#{userId}) as `privileges` authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'panel') cids) t,panel_group from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'panel') cids) t,panel_group
LEFT JOIN (select id,`name` from panel_group) sourcePanelGroup LEFT JOIN panel_group sourcePanelGroup
on sourcePanelGroup.id=panel_group.source on sourcePanelGroup.id=panel_group.source
left join (
SELECT
auth_source,
group_concat( DISTINCT sys_auth_detail.privilege_extend ) as `privileges`
FROM
(
`sys_auth`
LEFT JOIN `sys_auth_detail` ON ((
`sys_auth`.`id` = `sys_auth_detail`.`auth_id`
)))
WHERE
sys_auth_detail.privilege_value = 1
AND sys_auth.auth_source_type = 'panel'
AND (
(
sys_auth.auth_target_type = 'dept'
AND sys_auth.auth_target IN ( SELECT dept_id FROM sys_user WHERE user_id = #{userId} )
)
OR (
sys_auth.auth_target_type = 'user'
AND sys_auth.auth_target = #{userId}
)
OR (
sys_auth.auth_target_type = 'role'
AND sys_auth.auth_target IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{userId} )
)
)
GROUP BY
`sys_auth`.`auth_source`
) authInfo
on panel_group.id = authInfo.auth_source
<where> <where>
FIND_IN_SET(panel_group.id,cids) FIND_IN_SET(panel_group.id,cids)
<if test="name != null"> <if test="name != null">
@ -78,10 +109,41 @@
(case when ISNULL(defaultPanelGroup.id) then false else true end) is_default, (case when ISNULL(defaultPanelGroup.id) then false else true end) is_default,
defaultPanelGroup.id as default_panel_id, defaultPanelGroup.id as default_panel_id,
defaultPanelGroup.`name` as default_panel_name, defaultPanelGroup.`name` as default_panel_name,
get_auths(panel_group.id,'panel',#{userId}) as `privileges` authInfo.privileges as `privileges`
from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'panel') cids) t,panel_group from (select GET_V_AUTH_MODEL_ID_P_USE (#{userId}, 'panel') cids) t,panel_group
LEFT JOIN (select source,id,`name` from panel_group where source is not null) defaultPanelGroup LEFT JOIN panel_group defaultPanelGroup
on defaultPanelGroup.source=panel_group.id on defaultPanelGroup.source=panel_group.id and defaultPanelGroup.source is not null
left join (
SELECT
auth_source,
group_concat( DISTINCT sys_auth_detail.privilege_extend ) as `privileges`
FROM
(
`sys_auth`
LEFT JOIN `sys_auth_detail` ON ((
`sys_auth`.`id` = `sys_auth_detail`.`auth_id`
)))
WHERE
sys_auth_detail.privilege_value = 1
AND sys_auth.auth_source_type = 'panel'
AND (
(
sys_auth.auth_target_type = 'dept'
AND sys_auth.auth_target IN ( SELECT dept_id FROM sys_user WHERE user_id = #{userId} )
)
OR (
sys_auth.auth_target_type = 'user'
AND sys_auth.auth_target = #{userId}
)
OR (
sys_auth.auth_target_type = 'role'
AND sys_auth.auth_target IN ( SELECT role_id FROM sys_users_roles WHERE user_id = #{userId} )
)
)
GROUP BY
`sys_auth`.`auth_source`
) authInfo
on panel_group.id = authInfo.auth_source
<where> <where>
FIND_IN_SET(panel_group.id,cids) FIND_IN_SET(panel_group.id,cids)
<if test="name != null"> <if test="name != null">