Skip to content

Commit

Permalink
Patch Ancestry::InstanceMethods#parse_ancestry_column
Browse files Browse the repository at this point in the history
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  <<<<<<<<<<
     ...                                             |        ...
  • Loading branch information
NickLaMuro committed Apr 27, 2018
1 parent 125c57a commit 6f8ad4c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/patches/ancestry_patch.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6f8ad4c

Please sign in to comment.