Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 缓存额外保留配置支持设置文件后缀 #2002 #2056

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,25 @@ 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 { fileExtensionCheck = checkFileExtension(it, fullPath) }
if (fileExtensionCheck) {
temp.add(sha256)
logger.info("Retain node $projectId/$repoName$fullPath, $sha256.")
}
}
}
return temp
}

private fun checkFileExtension(fileExtension: List<String> , fullPath: String ) : Boolean {
var fileExtensionCheck = true
if (!fileExtension.contains("/") && !fileExtension.any { fullPath.endsWith(it) }) {
fileExtensionCheck = false
}
return fileExtensionCheck
}

private fun convertRepoConfigToFileCache(repoConfig: RepoConfig):TFileCache {
return TFileCache(
id = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ data class FileCacheRequest(
var repoName: String = "",
// 路径前缀匹配
var pathPrefix: List<String> = emptyList(),
// 文件后缀
var fileExtension: List<String> = emptyList(),
// 保留最近多少天内访问
var days: Int = 30,
var size: Long = 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ data class TFileCache(
var repoName: String,
// 路径前缀匹配
var pathPrefix: List<String> = emptyList(),
// 文件后缀
var fileExtension: List<String> ?= emptyList(),
// 保留最近多少天内访问
var days: Int = 30,
var size: Long = 10
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 Expand Up @@ -78,6 +79,7 @@ class FileCacheServiceImp constructor(
projectId = fileCacheRequest.projectId,
repoName = fileCacheRequest.repoName,
pathPrefix = fileCacheRequest.pathPrefix,
fileExtension = fileCacheRequest.fileExtension,
size = fileCacheRequest.size,
days = fileCacheRequest.days
)
Expand Down
20 changes: 17 additions & 3 deletions src/frontend/devops-op/src/views/node/FileCache.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<el-table v-loading="loading" :data="fileCaches" style="width: 100%">
<el-table-column prop="projectId" label="项目Id" />
<el-table-column prop="repoName" label="仓库名称" />
<el-table-column prop="pathPrefix" label="路径前缀匹配" width="780">
<el-table-column prop="pathPrefix" label="路径前缀匹配" width="480">
<template slot-scope="scope">
<div
v-for="(item,index) in scope.row.pathPrefix"
Expand All @@ -56,6 +56,16 @@
</div>
</template>
</el-table-column>
<el-table-column prop="fileExtension" label="文件后缀匹配" width="280">
<template slot-scope="scope">
<div
v-for="(item,index) in scope.row.fileExtension"
:key="index"
>
<span> {{ item }}</span>
</div>
</template>
</el-table-column>
<el-table-column prop="size" label="大小(MB)" />
<el-table-column prop="days" label="保存时间(天)" />
<el-table-column align="right">
Expand Down Expand Up @@ -87,8 +97,8 @@
:visible.sync="showDialog"
:updating-file-caches="updatingFileCache"
:repo-config="fileCacheConf"
@created="getDates"
@updated="getDates"
@created="updated"
@updated="updated"
/>
</div>
</template>
Expand All @@ -101,6 +111,7 @@ import { searchProjects } from '@/api/project'
import { listRepositories } from '@/api/repository'

export default {
inject: ['reload'],
name: 'FileCache',
components: { CreateOrUpdateFileCacheDialog },
data() {
Expand Down Expand Up @@ -254,6 +265,9 @@ export default {
return projectFilter && repoFilter
})
}
},
updated() {
this.reload()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,60 @@
<el-form-item label="保存时间(天)" prop="days" :rules="[{ required: true, message: '保存天数不能为空'}]">
<el-input-number v-model="fileCache.days" controls-position="right" :min="0" />
</el-form-item>
<el-form-item
v-for="(item,index) in fileCache.pathPrefix"
:key="index"
label="路径前缀"
prop="pathPrefix"
>
<el-input
v-model="fileCache.pathPrefix[index]"
style="height: 40px ; width: 500px;"
placeholder="请输入数据(如/1)"
min="0"
@input="updateInput()"
/>
<i
class="el-icon-circle-close"
style="color: red"
@click.prevent="removeDomain(item)"
/>
<i
v-if="index === fileCache.pathPrefix.length - 1"
class="el-icon-circle-plus-outline"
style="margin: 0px 20px"
@click.prevent="addDomain()"
/>
</el-form-item>
<div style="overflow-y: auto; max-height: 180px">
<el-form-item
v-for="(item,index) in fileCache.pathPrefix"
:key="index"
label="路径前缀"
prop="pathPrefix"
>
<el-input
v-model="fileCache.pathPrefix[index]"
style="height: 40px ; width: 500px;"
placeholder="请输入数据(如/1)"
min="0"
@input="updateInput()"
/>
<i
class="el-icon-circle-close"
style="color: red"
@click.prevent="removeDomain(item)"
/>
<i
v-if="index === fileCache.pathPrefix.length - 1"
class="el-icon-circle-plus-outline"
style="margin: 0px 20px"
@click.prevent="addDomain()"
/>
</el-form-item>
</div>
<div style="overflow-y: auto; max-height: 180px; margin-top: 10px">
<el-form-item
v-for="(item,index) in fileCache.fileExtension"
:key="index"
label="文件后缀"
prop="pathPrefix"
>
<el-input
v-model="fileCache.fileExtension[index]"
style="height: 40px ; width: 500px;"
placeholder="请输入数据(如.txt)"
min="0"
@input="updateInput()"
/>
<i
class="el-icon-circle-close"
style="color: red"
@click.prevent="removeFileDomain(item)"
/>
<i
v-if="index === fileCache.fileExtension.length - 1"
class="el-icon-circle-plus-outline"
style="margin: 0px 20px"
@click.prevent="addFileDomain()"
/>
</el-form-item>
</div>
</el-form>
<div slot="footer">
<el-button @click="close">取 消</el-button>
Expand Down Expand Up @@ -170,7 +199,10 @@ export default {
if (fileCache.pathPrefix.length === 1 && fileCache.pathPrefix[0].trim() === '') {
fileCache.pathPrefix = ['/']
}
fileCache.pathPrefix = Array.from(new Set(fileCache.pathPrefix)).filter(path => path.trim() !== '')
if (fileCache.fileExtension.length === 1 && fileCache.fileExtension[0].trim() === '') {
fileCache.fileExtension = ['/']
}
fileCache.fileExtension = Array.from(new Set(fileCache.fileExtension)).filter(path => path.trim() !== '')
// 根据是否为创建模式发起不同请求
let reqPromise
let msg
Expand Down Expand Up @@ -217,6 +249,9 @@ export default {
if (this.createMode) {
this.fileCache = this.newFileCache()
} else {
if (!this.updatingFileCaches.fileExtension || this.updatingFileCaches.fileExtension.length === 0) {
this.updatingFileCaches.fileExtension = ['']
}
this.fileCache = _.cloneDeep(this.updatingFileCaches)
}
this.$nextTick(() => {
Expand All @@ -229,6 +264,7 @@ export default {
repoName: '',
paths: '',
pathPrefix: [''],
fileExtension: [''],
days: '',
size: ''
}
Expand All @@ -254,8 +290,17 @@ export default {
this.fileCache.pathPrefix.splice(index, 1)
}
},
removeFileDomain(item) {
const index = this.fileCache.fileExtension.indexOf(item)
if (index !== -1 && this.fileCache.fileExtension.length !== 1) {
this.fileCache.fileExtension.splice(index, 1)
}
},
addDomain() {
this.fileCache.pathPrefix.push('')
},
addFileDomain() {
this.fileCache.fileExtension.push('')
}
}
}</script>
Expand Down
Loading