Skip to content

Commit

Permalink
refactor: 优化删除过期历史密码 SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed May 19, 2024
1 parent 0b76d5c commit c1e9d31
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="top.continew.admin.system.mapper.UserPasswordHistoryMapper">
<delete id="deleteExpired">
DELETE FROM sys_user_password_history
WHERE id NOT IN (
SELECT * FROM (
SELECT id
FROM sys_user_password_history
WHERE user_id = #{userId}
ORDER BY create_time DESC
LIMIT #{count}
) t1
)
DELETE t1 FROM sys_user_password_history t1
LEFT JOIN (
SELECT id
FROM sys_user_password_history
WHERE user_id = #{userId}
ORDER BY create_time DESC
LIMIT #{count}
) t2 ON t2.id = t1.id
WHERE t2.id IS NULL
</delete>
</mapper>

0 comments on commit c1e9d31

Please sign in to comment.