Browse Source

perf: reduce recursion depth #1178

Jacky 11 hours ago
parent
commit
69250a6cbe
2 changed files with 5 additions and 4 deletions
  1. 3 2
      internal/cache/index.go
  2. 2 2
      internal/nginx_log/nginx_log.go

+ 3 - 2
internal/cache/index.go

@@ -296,13 +296,14 @@ func (s *Scanner) watchForChanges() {
 
 // scanSingleFile scans a single file and executes all registered callbacks
 func (s *Scanner) scanSingleFile(filePath string) error {
-	return s.scanSingleFileWithDepth(filePath, make(map[string]bool), 0)
+	visited := make(map[string]bool)
+	return s.scanSingleFileWithDepth(filePath, visited, 0)
 }
 
 // scanSingleFileWithDepth scans a single file with recursion protection
 func (s *Scanner) scanSingleFileWithDepth(filePath string, visited map[string]bool, depth int) error {
 	// Maximum recursion depth to prevent infinite recursion
-	const maxDepth = 10
+	const maxDepth = 5
 
 	if depth > maxDepth {
 		logger.Warn("Maximum recursion depth reached for file:", filePath)

+ 2 - 2
internal/nginx_log/nginx_log.go

@@ -167,8 +167,8 @@ func IsLogPathUnderWhiteList(path string) bool {
 	if errorLogPath != "" {
 		logDirWhiteList = append(logDirWhiteList, filepath.Dir(errorLogPath))
 	}
-	if nginx.GetPrefix() != "" {
-		logDirWhiteList = append(logDirWhiteList, nginx.GetPrefix())
+	if prefix != "" {
+		logDirWhiteList = append(logDirWhiteList, prefix)
 	}
 
 	// Check if path is under any whitelist directory