From 6f8ad4c9cbe6d500a74f656b67fbdd3fbd0ed334 Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Tue, 24 Apr 2018 18:05:37 -0500 Subject: [PATCH] Patch Ancestry::InstanceMethods#parse_ancestry_column Calls `.map!` instead of `.map` since we already have a temp array from the `.split`, and this avoids creating a completely new array for the second time in this method. * * * Before/After ------------ Total allocated: 318431331 bytes (2943673 objects) | Total allocated: 316196585 bytes (2917071 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 274449 activemodel-5.0.7 | 274449 activemodel-5.0.7 267060 ancestry-2.2.2 <<<<<<<<<< | 208479 manageiq/lib 106559 activesupport-5.0.7 | 106557 activesupport-5.0.7 82799 pending | 82799 pending 74117 ruby-2.3.3/lib | 74117 ruby-2.3.3/lib 52875 manageiq-providers-vmware-0be2f13a0dc9 | 52875 manageiq-providers-vmware-0be2f13a0dc9 14424 fast_gettext-1.2.0 | 35578 ancestry-2.2.2 <<<<<<<<<< ... | ... --- lib/patches/ancestry_patch.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/patches/ancestry_patch.rb b/lib/patches/ancestry_patch.rb index 30fef9ffb96..fb9781261fb 100644 --- a/lib/patches/ancestry_patch.rb +++ b/lib/patches/ancestry_patch.rb @@ -1,6 +1,10 @@ module Ancestry module InstanceMethods + def parse_ancestry_column obj + obj.to_s.split('/').map! { |id| cast_primary_key(id) } + end + STRING_BASED_KEYS = [:string, :uuid, :text].freeze def cast_primary_key(key) if STRING_BASED_KEYS.include? primary_key_type