Browse Source

perf: cache nginx prefix for log file scanning

Jacky 1 day ago
parent
commit
792e871ce3
1 changed files with 5 additions and 2 deletions
  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
 // 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
 // Use init function to automatically register callback
 func init() {
 func init() {
+	prefix = nginx.GetPrefix()
 	// Register the callback directly with the global registry
 	// Register the callback directly with the global registry
 	cache.RegisterCallback(scanForLogDirectives)
 	cache.RegisterCallback(scanForLogDirectives)
 }
 }
@@ -32,7 +36,6 @@ func scanForLogDirectives(configPath string, content []byte) error {
 	// Find log directives using regex
 	// Find log directives using regex
 	matches := logDirectiveRegex.FindAllSubmatch(content, -1)
 	matches := logDirectiveRegex.FindAllSubmatch(content, -1)
 
 
-	prefix := nginx.GetPrefix()
 	// Parse log paths
 	// Parse log paths
 	for _, match := range matches {
 	for _, match := range matches {
 		if len(match) >= 3 {
 		if len(match) >= 3 {