From 81906a7bd2d64d3d3f4e144b474219cf8657a716 Mon Sep 17 00:00:00 2001 From: DarkPhoenix Date: Mon, 26 Aug 2019 12:27:43 +0300 Subject: [PATCH] Do not store item-specific resistance attrs on effects --- eos/modifiedAttributeDict.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/eos/modifiedAttributeDict.py b/eos/modifiedAttributeDict.py index 3be62b295..20af2d112 100644 --- a/eos/modifiedAttributeDict.py +++ b/eos/modifiedAttributeDict.py @@ -29,6 +29,7 @@ from eos.db.gamedata.queries import getAttributeInfo defaultValuesCache = {} cappingAttrKeyCache = {} +resistanceCache = {} def getAttrDefault(key, fallback=None): @@ -46,19 +47,23 @@ def getAttrDefault(key, fallback=None): def getResistanceAttrID(modifyingItem, effect): - # If it doesn't exist on the effect, check the modifying modules attributes. If it's there, set it on the - # effect for this session so that we don't have to look here again (won't always work when it's None, but - # will catch most) - if not effect.resistanceID and not effect.getattr('resistanceCalculated'): + # If it doesn't exist on the effect, check the modifying module's attributes. + # If it's there, cache it and return + if effect.resistanceID: + return effect.resistanceID + cacheKey = (modifyingItem.item.ID, effect.ID) + try: + return resistanceCache[cacheKey] + except KeyError: attrPrefix = effect.getattr('prefix') if attrPrefix: - effect.resistanceID = int(modifyingItem.getModifiedItemAttr('{}ResistanceID'.format(attrPrefix))) or None - if not effect.resistanceID: - effect.resistanceID = int(modifyingItem.getModifiedItemAttr('{}RemoteResistanceID'.format(attrPrefix))) or None + resistanceID = int(modifyingItem.getModifiedItemAttr('{}ResistanceID'.format(attrPrefix))) or None + if not resistanceID: + resistanceID = int(modifyingItem.getModifiedItemAttr('{}RemoteResistanceID'.format(attrPrefix))) or None else: - effect.resistanceID = int(modifyingItem.getModifiedItemAttr("remoteResistanceID")) or None - effect.resistanceCalculated = True - return effect.resistanceID + resistanceID = int(modifyingItem.getModifiedItemAttr("remoteResistanceID")) or None + resistanceCache[cacheKey] = resistanceID + return resistanceID class ItemAttrShortcut: