|
|
@@ -362,13 +362,17 @@ public class ChatAttachmentService {
|
|
|
// ==================== 清理 ====================
|
|
|
|
|
|
/**
|
|
|
- * 孤儿清理:24h 前上传且从未关联消息的附件 → 删文件 + sidecar + 向量行。
|
|
|
- * 已关联的随会话留存(级联删除列为后续)。
|
|
|
+ * 孤儿清理:上传后超过 orphan-hours(默认 7 天)仍未关联消息的附件 →
|
|
|
+ * 删文件 + sidecar + 向量行。已关联的随会话留存(级联删除列为后续)。
|
|
|
+ *
|
|
|
+ * <p>时限特意宽(而不是 24h):用户把输入框挂几天再发是正常行为,
|
|
|
+ * 附件在发送时被清理掉(400「附件不存在或已清理」)属于误伤;
|
|
|
+ * 7 天足够覆盖任何真实使用节奏,孤儿又不会无限堆积。
|
|
|
*/
|
|
|
@Scheduled(fixedDelayString = "${zsjz.chat-attachment.purge-interval-ms:3600000}",
|
|
|
initialDelayString = "${zsjz.chat-attachment.purge-initial-delay-ms:600000}")
|
|
|
public void purgeOrphans() {
|
|
|
- LocalDateTime deadline = LocalDateTime.now().minusHours(24);
|
|
|
+ LocalDateTime deadline = LocalDateTime.now().minusHours(Math.max(24, props.getOrphanHours()));
|
|
|
List<ChatAttachment> orphans = attachmentMapper.selectList(Wrappers.<ChatAttachment>lambdaQuery()
|
|
|
.isNull(ChatAttachment::getLinkMessageId)
|
|
|
.lt(ChatAttachment::getCreateTime, deadline));
|