perf:减少/api/project/getModuleContent数据库交互次数以优化速度
This commit is contained in:
@@ -35,4 +35,160 @@
|
||||
ORDER BY COUNT(*) DESC
|
||||
;
|
||||
</select>
|
||||
|
||||
<!-- 批量查询模块内容,使用JOIN优化避免N+1查询 -->
|
||||
<select id="getModuleContentBatch" resultType="java.util.Map">
|
||||
SELECT
|
||||
cs.id as sort_id,
|
||||
cs.parent_id,
|
||||
cs.relation_id,
|
||||
cs.relation_type,
|
||||
cs.sort,
|
||||
-- UserLike相关字段
|
||||
ul.id as user_like_id,
|
||||
ul.design_item_id,
|
||||
ul.design_outfit_id,
|
||||
-- TDesignPythonOutfit相关字段
|
||||
tdpo.design_url,
|
||||
-- ToProductImageResult相关字段
|
||||
tpir.id as to_product_result_id,
|
||||
tpir.url as result_url,
|
||||
tpir.element_type,
|
||||
tpir.element_id,
|
||||
tpir.status as result_status,
|
||||
tpir.create_time as result_create_time,
|
||||
tpir.to_product_image_record_id,
|
||||
-- ToProductImageRecord相关字段
|
||||
tpir2.prompt,
|
||||
-- ToProductElement相关字段
|
||||
tpe.url as element_url,
|
||||
-- PoseTransformation相关字段
|
||||
pt.unique_id as pose_task_id,
|
||||
pt.product_image as pose_product_image,
|
||||
pt.gif_url as pose_gif_url,
|
||||
pt.video_url as pose_video_url,
|
||||
pt.first_frame_url as pose_first_frame_url,
|
||||
pt.is_liked as pose_is_liked,
|
||||
pt.model_name as pose_model_name,
|
||||
pt.pose_id,
|
||||
pt.task_status as pose_status,
|
||||
pt.create_time as pose_create_time
|
||||
FROM collection_sort cs
|
||||
LEFT JOIN t_user_like ul ON cs.relation_type = 'Design' AND cs.relation_id = ul.id
|
||||
LEFT JOIN t_design_python_outfit tdpo ON ul.design_outfit_id = tdpo.id
|
||||
LEFT JOIN to_product_image_result tpir ON cs.relation_type IN ('ToProductImage', 'Relight') AND cs.relation_id = tpir.id
|
||||
LEFT JOIN to_product_image_record tpir2 ON tpir.to_product_image_record_id = tpir2.id
|
||||
LEFT JOIN to_product_element tpe ON tpir.element_type = 'ProductElement' AND tpir.element_id = tpe.id
|
||||
LEFT JOIN t_pose_transformation pt ON cs.relation_type = 'PoseTransform' AND cs.relation_id = pt.id
|
||||
WHERE cs.project_id = #{projectId}
|
||||
<if test="relationTypes != null and relationTypes.size() > 0">
|
||||
AND cs.relation_type IN
|
||||
<foreach collection="relationTypes" item="type" open="(" separator="," close=")">
|
||||
#{type}
|
||||
</foreach>
|
||||
</if>
|
||||
ORDER BY cs.parent_id, cs.sort
|
||||
</select>
|
||||
|
||||
<!-- 批量查询ToProductImageResult及相关数据 -->
|
||||
<select id="getToProductImageResultBatch" resultType="java.util.Map">
|
||||
SELECT
|
||||
tpir.id,
|
||||
tpir.url,
|
||||
tpir.element_type,
|
||||
tpir.element_id,
|
||||
tpir.status,
|
||||
tpir.create_time,
|
||||
tpir.is_like,
|
||||
tpir.to_product_image_record_id,
|
||||
tpir.project_id,
|
||||
tpir.result_type,
|
||||
-- ToProductImageRecord相关字段
|
||||
tpir2.prompt,
|
||||
-- ToProductElement相关字段
|
||||
tpe.url as element_url,
|
||||
-- TDesignPythonOutfit相关字段
|
||||
tdpo.design_url as outfit_url
|
||||
FROM to_product_image_result tpir
|
||||
LEFT JOIN to_product_image_record tpir2 ON tpir.to_product_image_record_id = tpir2.id
|
||||
LEFT JOIN to_product_element tpe ON tpir.element_type = 'ProductElement' AND tpir.element_id = tpe.id
|
||||
LEFT JOIN t_design_python_outfit tdpo ON tpir.element_type = 'DesignOutfit' AND tpir.element_id = tdpo.id
|
||||
WHERE tpir.project_id = #{projectId}
|
||||
AND tpir.result_type = #{resultType}
|
||||
</select>
|
||||
|
||||
<!-- 批量查询UserLike及相关设计数据 -->
|
||||
<select id="getUserLikeBatch" resultType="java.util.Map">
|
||||
SELECT
|
||||
ul.id,
|
||||
ul.design_item_id,
|
||||
ul.design_outfit_id,
|
||||
ul.account_id,
|
||||
ul.create_date,
|
||||
ul.update_date,
|
||||
-- TDesignPythonOutfit相关字段
|
||||
tdpo.design_url,
|
||||
tdpo.design_item_id as outfit_design_item_id
|
||||
FROM t_user_like ul
|
||||
LEFT JOIN t_design_python_outfit tdpo ON ul.design_outfit_id = tdpo.id
|
||||
WHERE ul.id IN
|
||||
<foreach collection="relationIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<!-- 批量查询ToProductElement数据 -->
|
||||
<select id="getToProductElementBatch" resultType="java.util.Map">
|
||||
SELECT
|
||||
id,
|
||||
url,
|
||||
project_id,
|
||||
create_time,
|
||||
update_time
|
||||
FROM to_product_element
|
||||
WHERE id IN
|
||||
<foreach collection="elementIds" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<!-- 批量查询design模块的python outfit数据 -->
|
||||
<select id="getDesignPythonOutfitBatch" resultType="java.util.Map">
|
||||
SELECT
|
||||
tpo.id as outfit_id,
|
||||
tpo.parent_id,
|
||||
tpo.url as outfit_url,
|
||||
tpo.is_liked as outfit_is_liked,
|
||||
cs.sort,
|
||||
cs.id as sort_id
|
||||
FROM t_design_python_outfit tpo
|
||||
LEFT JOIN collection_sort cs ON cs.relation_id = tpo.id AND cs.relation_type = 'DesignPythonOutfit'
|
||||
WHERE tpo.parent_id IN
|
||||
<foreach collection="outfitIds" item="outfitId" open="(" close=")" separator=",">
|
||||
#{outfitId}
|
||||
</foreach>
|
||||
ORDER BY tpo.parent_id, cs.sort
|
||||
</select>
|
||||
|
||||
<!-- 批量查询ToProductImageRecord数据 -->
|
||||
<select id="getToProductImageRecordBatch" resultType="java.util.Map">
|
||||
SELECT
|
||||
id as record_id,
|
||||
prompt
|
||||
FROM to_product_image_record
|
||||
WHERE id IN
|
||||
<foreach collection="recordIds" item="recordId" open="(" close=")" separator=",">
|
||||
#{recordId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<!-- 批量查询CollectionElementRelModel -->
|
||||
<select id="getCollectionElementRelModelBatch" resultType="com.ai.da.mapper.primary.entity.CollectionElementRelModel">
|
||||
SELECT id, collection_element_id, relation_id, relation_type
|
||||
FROM collection_element_rel_model
|
||||
WHERE collection_element_id IN
|
||||
<foreach collection="collectionElementIds" item="collectionElementId" open="(" separator="," close=")">
|
||||
#{collectionElementId}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user