Skip to content

Commit

Permalink
feat: 缓存额外保留配置支持设置文件后缀 TencentBlueKing#2002
Browse files Browse the repository at this point in the history
  • Loading branch information
lannoy0523 committed Jun 7, 2024
1 parent 570369e commit 0a74311
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,16 @@ class BasedRepositoryFileExpireResolver(
// 获取每个的sha256
val sha256 = ret[SHA256].toString()
val fullPath = ret[FULL_PATH].toString()
temp.add(sha256)
logger.info("Retain node $projectId/$repoName$fullPath, $sha256.")
var fileExtensionCheck = true
it.fileExtension?.let {
if (!it.contains("/") && !it.any { fullPath.endsWith(it) }) {
fileExtensionCheck = false
}
}
if (fileExtensionCheck) {
temp.add(sha256)
logger.info("Retain node $projectId/$repoName$fullPath, $sha256.")
}
}
}
return temp
Expand All @@ -106,7 +114,6 @@ class BasedRepositoryFileExpireResolver(
projectId = repoConfig.projectId,
repoName = repoConfig.repoName,
pathPrefix = repoConfig.pathPrefix,
fileExtension = listOf("/"),
days = repoConfig.days,
size = expireConfig.size.toMegabytes()
)
Expand All @@ -122,12 +129,7 @@ class BasedRepositoryFileExpireResolver(
size = tFileCache.size,
dateTime = dateTime,
collection = collectionName,
pathPrefixs = tFileCache.pathPrefix,
fileExtension = if(tFileCache.fileExtension.orEmpty().size == 0) {
listOf("/")
} else {
tFileCache.fileExtension.orEmpty()
},
pathPrefixs = tFileCache.pathPrefix
)
}

Expand All @@ -138,26 +140,17 @@ class BasedRepositoryFileExpireResolver(
dateTime: LocalDateTime,
collection: String,
batchSize: Int = 20000,
pathPrefixs: List<String>,
fileExtension: List<String>,
pathPrefixs: List<String>
): Set<Map<String, Any?>> {
val temp = mutableSetOf<Map<String, Any?>>()
val prefixCri = pathPrefixs.map {
val escapedValue = MongoEscapeUtils.escapeRegex(it)
Criteria.where(FULL_PATH).regex("^$escapedValue")
}
val fileExtension = fileExtension.map {
val escapedValue = MongoEscapeUtils.escapeRegex(it)
Criteria.where(FULL_PATH).regex("$escapedValue$")
}
val pathMatches: ArrayList<Criteria> = arrayListOf()
pathMatches.addAll(prefixCri)
pathMatches.addAll(fileExtension)
val query = Query.query(
Criteria.where(PROJECT).isEqualTo(projectId).and(REPO).isEqualTo(repoName)
.and(FOLDER).isEqualTo(false).and(SIZE).gte(DataSize.ofMegabytes(size).toBytes())
.and(LAST_ACCESS_DATE).gt(dateTime)
.andOperator(Criteria().orOperator(pathMatches))
.and(LAST_ACCESS_DATE).gt(dateTime).andOperator(Criteria().orOperator(prefixCri))
.and(DELETED_DATE).isEqualTo(null)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class FileCacheServiceImp constructor(
projectId = fileCacheRequest.projectId,
repoName = fileCacheRequest.repoName,
pathPrefix = fileCacheRequest.pathPrefix,
fileExtension = fileCacheRequest.fileExtension,
size = fileCacheRequest.size,
days = fileCacheRequest.days
)
Expand Down

0 comments on commit 0a74311

Please sign in to comment.