Skip to content

Player.from_userid caching #297

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 3 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions addons/source-python/packages/source-python/entities/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ def __init__(cls, classname, bases, attributes):

# Set whether or not this class is caching its instances by default
try:
cls._caching = signature(
cls.__init__
).parameters['caching'].default
cls._caching = bool(
signature(
vars(cls)['__init__']
).parameters['caching'].default
)
except KeyError:
cls._caching = True
cls._caching = bool(vars(cls).get('caching', False))

# Add the class to the registered classes
_entity_classes.add(cls)
Expand Down Expand Up @@ -305,14 +307,16 @@ def find_or_create(cls, classname):
return entity

@classmethod
def from_inthandle(cls, inthandle):
def from_inthandle(cls, inthandle, caching=None):
"""Create an entity instance from an inthandle.

:param int inthandle:
The inthandle.
:param bool caching:
Whether to lookup the cache for an existing instance or not.
:rtype: Entity
"""
return cls(index_from_inthandle(inthandle))
return cls(index_from_inthandle(inthandle), caching=caching)

@classmethod
def _obj(cls, ptr):
Expand Down
6 changes: 4 additions & 2 deletions addons/source-python/packages/source-python/players/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,16 @@ def __init__(self, index, caching=True):
object.__setattr__(self, '_playerinfo', None)

@classmethod
def from_userid(cls, userid):
def from_userid(cls, userid, caching=None):
"""Create an instance from a userid.

:param int userid:
The userid.
:param bool caching:
Whether to lookup the cache for an existing instance or not.
:rtype: Player
"""
return cls(index_from_userid(userid))
return cls(index_from_userid(userid), caching=caching)

@property
def net_info(self):
Expand Down