Explorar el Código

perf: cache nginx prefix for log file scanning

Jacky hace 1 mes
padre
commit
792e871ce3
Se han modificado 1 ficheros con 5 adiciones y 2 borrados
  1. 5 2
      internal/nginx_log/nginx_log.go

+ 5 - 2
internal/nginx_log/nginx_log.go

@@ -15,10 +15,14 @@ import (
 )
 
 // Regular expression for log directives - matches access_log or error_log
-var logDirectiveRegex = regexp.MustCompile(`(?m)(access_log|error_log)\s+([^\s;]+)(?:\s+[^;]+)?;`)
+var (
+	logDirectiveRegex = regexp.MustCompile(`(?m)(access_log|error_log)\s+([^\s;]+)(?:\s+[^;]+)?;`)
+	prefix            = ""
+)
 
 // Use init function to automatically register callback
 func init() {
+	prefix = nginx.GetPrefix()
 	// Register the callback directly with the global registry
 	cache.RegisterCallback(scanForLogDirectives)
 }
@@ -32,7 +36,6 @@ func scanForLogDirectives(configPath string, content []byte) error {
 	// Find log directives using regex
 	matches := logDirectiveRegex.FindAllSubmatch(content, -1)
 
-	prefix := nginx.GetPrefix()
 	// Parse log paths
 	for _, match := range matches {
 		if len(match) >= 3 {