Skip to content

Commit

Permalink
update soft delete
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Sep 20, 2024
1 parent 39ea6f1 commit 8789adb
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ public void updateMessages(Object threadId, List<ChatMessage> messages) {

@Override
public void deleteMessages(Object threadId) {
chatMessageDao.deleteByThreadId((Long) threadId);
List<ChatMessagePO> chatMessagePOS = chatMessageDao.findAllByThreadId((Long) threadId);
chatMessagePOS.forEach(chatMessage -> chatMessage.setIsDeleted(true));
chatMessageDao.partialUpdateByIds(chatMessagePOS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,4 @@

public interface ChatMessageDao extends BaseDao<ChatMessagePO> {
List<ChatMessagePO> findAllByThreadId(@Param("threadId") Long threadId);

void deleteByThreadId(@Param("threadId") Long threadId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,5 @@ List<ChatThreadPO> findAllByPlatformAuthorizedIdAndUserId(

void saveWithThreadInfo(ChatThreadPO chatThreadPO);

void deleteByThreadId(@Param("id") Long theadId);

void deleteByPlatformId(@Param("platformId") Long platformId);
List<ChatThreadPO> findAllByPlatformId(@Param("platformId") Long platformId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,5 @@ public interface PlatformAuthorizedDao extends BaseDao<PlatformAuthorizedPO> {

void saveWithCredentials(PlatformAuthorizedPO platformAuthorizedPO);

void deleteByPlatformId(@Param("id") Long platformId);

List<PlatformAuthorizedPO> findAllPlatform();
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,4 @@
AND is_deleted = 0
</select>

<update id="deleteByThreadId" parameterType="java.lang.Long">
UPDATE llm_chat_message
SET is_deleted = 1
WHERE thread_id = #{threadId}
</update>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,10 @@
thread_info = VALUES(thread_info)
</insert>

<update id="deleteByPlatformId" parameterType="java.lang.Long">
UPDATE llm_chat_thread
SET is_deleted = 1
WHERE platform_id = #{platformId}
</update>

<update id="deleteByThreadId" parameterType="java.lang.Long">
UPDATE llm_chat_thread
SET is_deleted = 1
WHERE id = #{id}
</update>
<select id="findAllByPlatformId" resultType="org.apache.bigtop.manager.dao.po.ChatThreadPO">
SELECT *
FROM llm_chat_thread
WHERE platform_id = #{platformId} AND is_deleted = 0
</select>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,9 @@
<insert id="saveWithCredentials" parameterType="org.apache.bigtop.manager.dao.po.PlatformAuthorizedPO" useGeneratedKeys="true" keyProperty="id">
INSERT INTO llm_platform_authorized (platform_id, credentials)
VALUES (#{platformId}, #{credentials, typeHandler=org.apache.bigtop.manager.dao.handler.JsonTypeHandler})
ON DUPLICATE KEY UPDATE
platform_id = VALUES(platform_id),
credentials = VALUES(credentials)
ON DUPLICATE KEY UPDATE
platform_id = VALUES(platform_id),
credentials = VALUES(credentials)
</insert>

<update id="deleteByPlatformId" parameterType="java.lang.Long">
UPDATE llm_platform_authorized
SET is_deleted = 1
WHERE id = #{id}
</update>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,4 @@
AND is_deleted = false
</select>

<update id="deleteByThreadId" parameterType="java.lang.Long">
UPDATE llm_chat_message
SET is_deleted = true
WHERE thread_id = #{threadId}
</update>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -50,22 +50,16 @@
INSERT INTO llm_chat_thread (platform_id, user_id, model, thread_info)
VALUES (#{platformId}, #{userId}, #{model}, #{threadInfo, typeHandler=org.apache.bigtop.manager.dao.handler.JsonTypeHandler})
ON DUPLICATE KEY UPDATE
platform_id = VALUES(platform_id),
user_id = VALUES(user_id),
model = VALUES(model),
thread_info = VALUES(thread_info)
platform_id = VALUES(platform_id),
user_id = VALUES(user_id),
model = VALUES(model),
thread_info = VALUES(thread_info)
</insert>

<update id="deleteByPlatformId" parameterType="java.lang.Long">
UPDATE llm_chat_thread
SET is_deleted = true
WHERE platform_id = #{platformId}
</update>

<update id="deleteByThreadId" parameterType="java.lang.Long">
UPDATE llm_chat_thread
SET is_deleted = true
WHERE id = #{id}
</update>
<select id="findAllByPlatformId" resultType="org.apache.bigtop.manager.dao.po.ChatThreadPO">
SELECT *
FROM llm_chat_thread
WHERE platform_id = #{platformId} AND is_deleted = 0
</select>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,8 @@
INSERT INTO llm_platform_authorized (platform_id, credentials)
VALUES (#{platformId}, #{credentials, typeHandler=org.apache.bigtop.manager.dao.handler.JsonTypeHandler})
ON DUPLICATE KEY UPDATE
platform_id = VALUES(platform_id),
credentials = VALUES(credentials)
platform_id = VALUES(platform_id),
credentials = VALUES(credentials)
</insert>

<update id="deleteByPlatformId" parameterType="java.lang.Long">
UPDATE llm_platform_authorized
SET is_deleted =true
WHERE id = #{id}
</update>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,11 @@ public boolean deleteAuthorizedPlatform(Long platformId) {
List<PlatformAuthorizedPO> authorizedPlatformPOs = platformAuthorizedDao.findAllPlatform();
for (PlatformAuthorizedPO authorizedPlatformPO : authorizedPlatformPOs) {
if (authorizedPlatformPO.getId().equals(platformId)) {
platformAuthorizedDao.deleteByPlatformId(authorizedPlatformPO.getId());
chatThreadDao.deleteByPlatformId(authorizedPlatformPO.getId());
authorizedPlatformPO.setIsDeleted(true);
platformAuthorizedDao.partialUpdateById(authorizedPlatformPO);
List<ChatThreadPO> chatThreadPOS = chatThreadDao.findAllByPlatformId(authorizedPlatformPO.getId());
chatThreadPOS.forEach(chatThread -> chatThread.setIsDeleted(true));
chatThreadDao.partialUpdateByIds(chatThreadPOS);
return true;
}
}
Expand Down Expand Up @@ -254,8 +257,11 @@ public boolean deleteChatThreads(Long platformId, Long threadId) {
for (ChatThreadPO chatThreadPO : chatThreadPOS) {
if (chatThreadPO.getId().equals(threadId)
&& chatThreadPO.getPlatformId().equals(platformId)) {
chatThreadDao.deleteByThreadId(threadId);
chatMessageDao.deleteByThreadId(threadId);
chatThreadPO.setIsDeleted(true);
chatThreadDao.partialUpdateById(chatThreadPO);
List<ChatMessagePO> chatMessagePOS = chatMessageDao.findAllByThreadId(threadId);
chatMessagePOS.forEach(chatMessage -> chatMessage.setIsDeleted(true));
chatMessageDao.partialUpdateByIds(chatMessagePOS);
return true;
}
}
Expand Down

0 comments on commit 8789adb

Please sign in to comment.