refactor(uploader): 优化文件信息统计逻辑
- 将变量名 fInfo 重命名为 filesInfo 以提高可读性 - 调整代码顺序,将 AddLog 调用移到变量声明后 - 统一使用新变量名在所有相关位置进行引用 - 移动 g.SetLimit 注释位置以提高代码可读性
This commit is contained in:
@@ -163,11 +163,11 @@ func uploadData(ctx context.Context, logChan *chan string) {
|
|||||||
|
|
||||||
//检测到文件
|
//检测到文件
|
||||||
//统计文件行数
|
//统计文件行数
|
||||||
var fInfo = make(map[string]fileInfo)
|
var filesInfo = make(map[string]fileInfo)
|
||||||
|
|
||||||
AddLog(logChan, fmt.Sprintf("正在统计 %v 个文件行数", len(files)))
|
|
||||||
|
|
||||||
isAllEmpty := true
|
isAllEmpty := true
|
||||||
|
|
||||||
|
AddLog(logChan, fmt.Sprintf("正在统计 %v 个文件行数", len(files)))
|
||||||
for _, filePath := range files {
|
for _, filePath := range files {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@@ -189,7 +189,7 @@ func uploadData(ctx context.Context, logChan *chan string) {
|
|||||||
if lineCount == 0 {
|
if lineCount == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fInfo[filepath.Base(filePath)] = fileInfo{
|
filesInfo[filepath.Base(filePath)] = fileInfo{
|
||||||
FilePath: filePath,
|
FilePath: filePath,
|
||||||
FileLines: lineCount,
|
FileLines: lineCount,
|
||||||
}
|
}
|
||||||
@@ -207,7 +207,7 @@ func uploadData(ctx context.Context, logChan *chan string) {
|
|||||||
|
|
||||||
//刷新文件上传进度
|
//刷新文件上传进度
|
||||||
progress.Clear()
|
progress.Clear()
|
||||||
for fileName, info := range fInfo {
|
for fileName, info := range filesInfo {
|
||||||
progress.Store(fileName,
|
progress.Store(fileName,
|
||||||
Progress{
|
Progress{
|
||||||
FileName: fileName,
|
FileName: fileName,
|
||||||
@@ -220,9 +220,10 @@ func uploadData(ctx context.Context, logChan *chan string) {
|
|||||||
|
|
||||||
// 使用 errgroup 控制同时处理的文件数,并开始上传文件任务
|
// 使用 errgroup 控制同时处理的文件数,并开始上传文件任务
|
||||||
g, egctx := errgroup.WithContext(ctx)
|
g, egctx := errgroup.WithContext(ctx)
|
||||||
g.SetLimit(config.APPConfig.HandleFileCount) // 设置同时处理文件数
|
// 设置同时处理文件数
|
||||||
|
g.SetLimit(config.APPConfig.HandleFileCount)
|
||||||
// 执行文件上传任务参数(文件路径,文件行数)
|
// 执行文件上传任务参数(文件路径,文件行数)
|
||||||
for fileName, info := range fInfo {
|
for fileName, info := range filesInfo {
|
||||||
select {
|
select {
|
||||||
case <-egctx.Done():
|
case <-egctx.Done():
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user