Optimize perf. on name finding

This commit is contained in:
Andrew Miner
2015-02-22 22:03:54 -08:00
parent 9f0d19d9e4
commit e89d7a87c7
2 changed files with 10 additions and 4 deletions
+9 -3
View File
@@ -28,7 +28,9 @@ module.exports = class Item extends BaseModel
options.logEvents ?= false
super attributes, options
@on Event.change + ':modVersion', => @slug.mod = @modVersion?.modSlug
@on Event.change + ':modVersion', =>
@_isCraftable = null
@slug.mod = @modVersion?.modSlug
# Public Methods ###############################################################################
@@ -42,8 +44,12 @@ module.exports = class Item extends BaseModel
# Property Methods #############################################################################
getIsCraftable: ->
return false unless @modVersion?
return @modVersion.hasRecipes @slug
if not @_isCraftable?
@_isCraftable = false
if @modVersion?
@_isCraftable = @modVersion.hasRecipes @slug
return @_isCraftable
Object.defineProperties @prototype,
isCraftable: {get:@prototype.getIsCraftable}
+1 -1
View File
@@ -54,8 +54,8 @@ module.exports = class NameFinder
mod.eachName (name, itemSlug)=>
return if nameMap[name]?
item = mod.findItem itemSlug
if not @includeGatherable
item = mod.findItem itemSlug
return unless item? and item.isCraftable
scanName = "#{mod.name} : #{name}"