Skip to content

Commit

Permalink
Patch Ancestry::InstanceMethods#cast_primary_key
Browse files Browse the repository at this point in the history
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
     ...                                             |        ...
  • Loading branch information
NickLaMuro committed Apr 27, 2018
1 parent 7f77ae9 commit 125c57a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/models/orchestration_stack.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
require 'ancestry'
require 'ancestry_patch'

class OrchestrationStack < ApplicationRecord
require_nested :Status

Expand Down
1 change: 1 addition & 0 deletions app/models/relationship.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'ancestry'
require 'ancestry_patch'

class Relationship < ApplicationRecord
has_ancestry
Expand Down
1 change: 1 addition & 0 deletions app/models/service.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'ancestry'
require 'ancestry_patch'

class Service < ApplicationRecord
DEFAULT_PROCESS_DELAY_BETWEEN_GROUPS = 120
Expand Down
1 change: 1 addition & 0 deletions app/models/tenant.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'ancestry'
require 'ancestry_patch'

class Tenant < ApplicationRecord
HARDCODED_LOGO = "custom_logo.png"
Expand Down
14 changes: 14 additions & 0 deletions lib/patches/ancestry_patch.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 125c57a

Please sign in to comment.