From 125c57a72dd94e99101e1a8c1880361e7341016e Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Tue, 24 Apr 2018 17:41:25 -0500 Subject: [PATCH] Patch Ancestry::InstanceMethods#cast_primary_key Prevents a new version of the STRING_BASED_KEYS array from being instantiated every time that cast_primary_key is called. * * * Before/After ------------ Total allocated: 324542397 bytes (3095350 objects) | Total allocated: 318431331 bytes (2943673 objects) | allocated objects by gem | allocated objects by gem ----------------------------------- | ----------------------------------- 1576834 activerecord-5.0.7 | 1576834 activerecord-5.0.7 477120 manageiq/app | 477120 manageiq/app 418737 ancestry-2.2.2 <<<<<<<<<< | 274449 activemodel-5.0.7 274449 activemodel-5.0.7 | 267060 ancestry-2.2.2 <<<<<<<<<< 106559 activesupport-5.0.7 | 106559 activesupport-5.0.7 82799 pending | 82799 pending 74117 ruby-2.3.3/lib | 74117 ruby-2.3.3/lib ... | ... --- app/models/orchestration_stack.rb | 2 ++ app/models/relationship.rb | 1 + app/models/service.rb | 1 + app/models/tenant.rb | 1 + lib/patches/ancestry_patch.rb | 14 ++++++++++++++ 5 files changed, 19 insertions(+) create mode 100644 lib/patches/ancestry_patch.rb diff --git a/app/models/orchestration_stack.rb b/app/models/orchestration_stack.rb index a74d36ab56f1..4c7b333e4aa1 100644 --- a/app/models/orchestration_stack.rb +++ b/app/models/orchestration_stack.rb @@ -1,4 +1,6 @@ require 'ancestry' +require 'ancestry_patch' + class OrchestrationStack < ApplicationRecord require_nested :Status diff --git a/app/models/relationship.rb b/app/models/relationship.rb index 08bd479049c4..de26c9aaedfa 100644 --- a/app/models/relationship.rb +++ b/app/models/relationship.rb @@ -1,4 +1,5 @@ require 'ancestry' +require 'ancestry_patch' class Relationship < ApplicationRecord has_ancestry diff --git a/app/models/service.rb b/app/models/service.rb index 0ff733d57892..371969597a94 100644 --- a/app/models/service.rb +++ b/app/models/service.rb @@ -1,4 +1,5 @@ require 'ancestry' +require 'ancestry_patch' class Service < ApplicationRecord DEFAULT_PROCESS_DELAY_BETWEEN_GROUPS = 120 diff --git a/app/models/tenant.rb b/app/models/tenant.rb index 851cb12c25c7..b0b3e5f59b6e 100644 --- a/app/models/tenant.rb +++ b/app/models/tenant.rb @@ -1,4 +1,5 @@ require 'ancestry' +require 'ancestry_patch' class Tenant < ApplicationRecord HARDCODED_LOGO = "custom_logo.png" diff --git a/lib/patches/ancestry_patch.rb b/lib/patches/ancestry_patch.rb new file mode 100644 index 000000000000..30fef9ffb96d --- /dev/null +++ b/lib/patches/ancestry_patch.rb @@ -0,0 +1,14 @@ +module Ancestry + module InstanceMethods + + STRING_BASED_KEYS = [:string, :uuid, :text].freeze + def cast_primary_key(key) + if STRING_BASED_KEYS.include? primary_key_type + key + else + key.to_i + end + end + + end +end