Skip to content

Added entity instances caching. #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 26, 2019
Prev Previous commit
Next Next commit
Made the cache lookup slightly faster.
  • Loading branch information
jordanbriere committed Nov 25, 2019
commit d8cef55653f52e9500faa18d39ec0c8d8c20b471
12 changes: 6 additions & 6 deletions addons/source-python/packages/source-python/entities/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def __init__(self, index):

def __new__(self, index):
# Let's first lookup for a cached instance
caching = self in metaclass.cache
if caching:
cache = metaclass.cache[self]
if index in cache:
return cache[index]
cache = metaclass.cache.get(self, None)
if cache is not None:
obj = cache.get(index, None)
if obj is not None:
return obj

# Nothing in cache, let's create a new instance
obj = cls.__base__.__new__(self, index)
Expand All @@ -118,7 +118,7 @@ def __new__(self, index):
)

# Let's cache the new instance we just created
if caching:
if cache is not None:
cache[index] = obj

# We are done, let's return the instance
Expand Down