Project

General

Profile

Actions

Bug #10636

open

Multiple calls of template_url via Template API

Added by Lukas Zapletal about 9 years ago. Updated about 9 years ago.

Status:
New
Priority:
Low
Assignee:
-
Category:
Templates
Target version:
-
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

When proxy templating is enabled via the smart-proxy plugin, we do HTTP REST request for each call of foreman_url method. I see multiple HTTP calls per provisioning if there are multiple calls of foreman_url in the templates. It's worse in foreman_bootdisk where we do twenty calls.

I think we can cache the value in lib/proxy_api/template.rb per request as this only changes when smart-proxy restarts.

Actions #1

Updated by Dominic Cleal about 9 years ago

  • Category set to Templates
Actions #2

Updated by Lukas Zapletal about 9 years ago

  • Priority changed from Normal to Low

Ok apparently this does not help as we create instance for each call:

diff --git a/lib/proxy_api/template.rb b/lib/proxy_api/template.rb
index cff8101..a95f1a3 100644
--- a/lib/proxy_api/template.rb
+++ b/lib/proxy_api/template.rb
@@ -7,8 +7,12 @@ module ProxyAPI

     # returns the Template URL for this proxy
     def template_url
-      if (response = parse(get("templateServer"))) and response["templateServer"].present?
-        return response["templateServer"]
+      if @template_url
+        @template_url
+      else
+        if (response = parse(get("templateServer"))) and response["templateServer"].present?
+          return @template_url = response["templateServer"]
+        end
       end
     rescue SocketError, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET,
       EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError,
@@ -16,7 +20,6 @@ module ProxyAPI
       logger.error("Failed to obtain template server from smart-proxy #{@url}")
       logger.error e.message
       logger.error e.backtrace.join("\n")
-
       nil
     end
   end

Actions

Also available in: Atom PDF