fix: 继续修复上传文件无记录问题

This commit is contained in:
Luke.Ye 2025-09-01 06:19:41 +08:00
parent 3bc1e4ca43
commit 9e33822bdd
3 changed files with 13 additions and 6 deletions

View File

@ -72,6 +72,9 @@ public class DynamicConfig {
@Value("${thread.pool.monitor.enabled:true}")
private boolean enableThreadPoolMonitor;
@Value("${es.show.context.length:150}")
private String esShowContextLen;
// 监听配置刷新事件主动刷新线程池监控
@EventListener
public void onRefresh(RefreshScopeRefreshedEvent event) {

View File

@ -11,6 +11,7 @@ import com.knowledge.base.domain.common.model.PageResult;
import com.knowledge.base.domain.doc.model.FileEsField;
import com.knowledge.base.infrastructure.cache.iface.FileCacheService;
import com.knowledge.base.infrastructure.config.ConstantConfig;
import com.knowledge.base.infrastructure.config.DynamicConfig;
import com.knowledge.base.infrastructure.north.dto.SearchReq;
import com.knowledge.base.infrastructure.north.dto.doc.OSRecordDTO;
import com.knowledge.base.infrastructure.north.dto.user.UserDTO;
@ -44,6 +45,8 @@ public class FileQueryController {
private final FileElasticsearchGateway esGateway;
private final DynamicConfig dynamicConfig;
@Autowired
private FileCacheService fileCacheService;
@ -171,7 +174,7 @@ public class FileQueryController {
result.put("url", source.get(FileEsField.URL));
String content = (String) source.get(FileEsField.CONTENT);
String summary = extractMultiSnippet(content, keywords, 50);
String summary = extractMultiSnippet(content, keywords, Integer.parseInt(dynamicConfig.getEsShowContextLen().trim()));
result.put("summary", summary);
results.add(result);
@ -205,7 +208,7 @@ public class FileQueryController {
}
if (matchedSnippets.isEmpty()) {
return content.length() <= 100 ? content : content.substring(0, 100) + "...";
return content.length() <= contextLength ? content : content.substring(0, contextLength) + "...";
}
return String.join(" ... ", matchedSnippets);

View File

@ -145,8 +145,9 @@ public class FileWriteController {
byte[] fileBytes = file.getBytes();
logger.info("[uploadFolderToOS] 已上传至对象存储: {}", originalName);
ThreadPoolUtil.execute(() ->
handleAsyncRecord(finalToken, bucket, originFileNameWithSuffix, suffix, s3FullPath, finalUrl, fileBytes, searchable)
ThreadPoolUtil.execute(() -> {
handleAsyncRecord(finalToken, bucket, originFileNameWithSuffix, suffix, s3FullPath, finalUrl, fileBytes, searchable);
}
);
}
@ -155,7 +156,7 @@ public class FileWriteController {
"count", filePathMap.size(),
"files", filePathMap
));
} catch (Exception e) {
} catch (Throwable e) {
logger.error("上传失败", e);
return ResponseEntity.status(500).body("上传失败: " + e.getMessage());
}
@ -246,7 +247,7 @@ public class FileWriteController {
logger.info("本地文件信息已保存并导入ES: localRelaPath = {}, ESImportRes = {}", localRelaFilePath, res);
}
} catch (Exception e) {
} catch (Throwable e) {
logger.error("异步写入失败: {}", originFileNameWithSuffix, e);
}
}