Skip to content

Commit 424c043

Browse files
committed
Improve performance by caching entity exposures
- Prevent constant rebuilding of Entity's @exposures class instance variable, improving serialization performance by 25%.
1 parent b656efc commit 424c043

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/grape_entity/entity.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ def self.with_options(options)
175175
# are symbolized references to methods on the containing object, the values are
176176
# the options that were passed into expose.
177177
def self.exposures
178-
@exposures ||= {}
178+
return @exposures unless @exposures.nil?
179+
180+
@exposures = {}
179181

180182
if superclass.respond_to? :exposures
181183
@exposures = superclass.exposures.merge(@exposures)

0 commit comments

Comments
 (0)