瀏覽代碼

[server] Gracefully handle stale collection entry (#1260)

## Description

## Tests
Neeraj Gupta 1 年之前
父節點
當前提交
25cedd5e2f
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      server/pkg/controller/collection.go

+ 9 - 0
server/pkg/controller/collection.go

@@ -488,6 +488,15 @@ func (c *CollectionController) GetDiffV2(ctx *gin.Context, cID int64, userID int
 		if diff[idx].OwnerID != userID {
 			diff[idx].MagicMetadata = nil
 		}
+		if diff[idx].Metadata.EncryptedData == "-" && !diff[idx].IsDeleted {
+			// This indicates that the file is deleted, but we still have a stale entry in the collection
+			log.WithFields(log.Fields{
+				"file_id":       diff[idx].ID,
+				"collection_id": cID,
+				"updated_at":    diff[idx].UpdationTime,
+			}).Warning("stale collection_file found")
+			diff[idx].IsDeleted = true
+		}
 	}
 	return diff, hasMore, nil
 }