PERF: avoid shelling to get hostname aggressively

Previously we had many places in the app that called `hostname` to get
hostname of a server. This commit replaces the pattern in 2 ways

1. We cache the result in `Discourse.os_hostname` so it is only ever called once

2. We prefer to use Socket.gethostname which avoids making a shell command

This improves performance as we are not spawning hostname processes throughout
the app lifetime
This commit is contained in:
Sam Saffron
2020-02-18 15:11:30 +11:00
parent cfd56e9159
commit 28292d2759
9 changed files with 26 additions and 8 deletions

View File

@ -8,7 +8,7 @@ class DiscourseLogstashLogger
uri: uri,
sync: true,
customize_event: ->(event) {
event['hostname'] = `hostname`.chomp
event['hostname'] = Discourse.os_hostname
event['severity_name'] = event['severity']
event['severity'] = Object.const_get("Logger::Severity::#{event['severity']}")
event['type'] = type