Skip to content

Commit

Permalink
fix: 修复重复增加blob引用数 #2825
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlkl committed Dec 6, 2024
1 parent 794126e commit c5ca38b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,18 @@ import org.springframework.stereotype.Repository

@Repository
class BlobRefRepository : SimpleMongoDao<TDdcBlobRef>() {
fun addRefToBlob(projectId: String, repoName: String, bucket: String, refKey: String, blobIds: Set<String>) {

/**
* 添加blob与ref关系,返回插入成功的blobId列表
*/
fun addRefToBlob(
projectId: String,
repoName: String,
bucket: String,
refKey: String,
blobIds: Set<String>
): Set<String> {
val addedBlobIds = HashSet<String>()
if (blobIds.size > DEFAULT_BLOB_SIZE_LIMIT) {
val ref = "$projectId/$repoName/${buildRef(bucket, refKey)}"
logger.error("blobs of ref[$ref] exceed size limit, size[${blobIds.size}]]")
Expand All @@ -27,9 +38,11 @@ class BlobRefRepository : SimpleMongoDao<TDdcBlobRef>() {
ref = buildRef(bucket, refKey)
)
)
addedBlobIds.add(it)
} catch (ignore: DuplicateKeyException) {
}
}
return addedBlobIds
}

fun removeRefFromBlob(projectId: String, repoName: String, bucket: String, refKey: String): List<TDdcBlobRef> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ class BlobService(
}

fun addRefToBlobs(ref: Reference, blobIds: Set<String>) {
blobRefRepository.addRefToBlob(ref.projectId, ref.repoName, ref.bucket, ref.key.toString(), blobIds)
blobRepository.incRefCount(ref.projectId, ref.repoName, blobIds)
with(ref) {
val addedBlobIds = blobRefRepository.addRefToBlob(projectId, repoName, bucket, key.toString(), blobIds)
blobRepository.incRefCount(projectId, repoName, addedBlobIds)
}
}

fun removeRefFromBlobs(projectId: String, repoName: String, bucket: String, key: String) {
Expand Down

0 comments on commit c5ca38b

Please sign in to comment.