mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
Update ObjectSessionHandler to avoid a caching syncing issue; should resolve #1153.
This commit is contained in:
parent
99c4042fbc
commit
19e8528b04
3 changed files with 20 additions and 4 deletions
|
|
@ -52,7 +52,15 @@ class ObjectSessionHandler(object):
|
|||
self._recache()
|
||||
|
||||
def _recache(self):
|
||||
global _SESSIONS
|
||||
if not _SESSIONS:
|
||||
from evennia.server.sessionhandler import SESSIONS as _SESSIONS
|
||||
self._sessid_cache = list(set(int(val) for val in (self.obj.db_sessid or "").split(",") if val))
|
||||
if any(sessid for sessid in self._sessid_cache if sessid not in _SESSIONS):
|
||||
# cache is out of sync with sessionhandler! Only retain the ones in the handler.
|
||||
self.sessid_cache = [sessid for sessid in self._sessid_cache if sessid in _SESSIONS]
|
||||
self.obj.db_sessid = ",".join(str(val) for val in self._sessid_cache)
|
||||
self.obj.save(update_fields=["db_sessid"])
|
||||
|
||||
def get(self, sessid=None):
|
||||
"""
|
||||
|
|
@ -73,9 +81,14 @@ class ObjectSessionHandler(object):
|
|||
if not _SESSIONS:
|
||||
from evennia.server.sessionhandler import SESSIONS as _SESSIONS
|
||||
if sessid:
|
||||
return [_SESSIONS[sessid]] if sessid in self._sessid_cache and sessid in _SESSIONS else []
|
||||
sessions = [_SESSIONS[sessid] if sessid in _SESSIONS else None] if sessid in self._sessid_cache else []
|
||||
else:
|
||||
return [_SESSIONS[sessid] for sessid in self._sessid_cache if sessid in _SESSIONS]
|
||||
sessions = [_SESSIONS[sessid] if sessid in _SESSIONS else None for sessid in self._sessid_cache]
|
||||
if None in sessions:
|
||||
# this happens only if our cache has gone out of sync with the SessionHandler.
|
||||
self._recache()
|
||||
return self.get(sessid=sessid)
|
||||
return sessions
|
||||
|
||||
def all(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -394,7 +394,7 @@ class Evennia(object):
|
|||
# flag to avoid loops.
|
||||
self.shutdown_complete = True
|
||||
# kill the server
|
||||
reactor.callLater(0, reactor.stop)
|
||||
reactor.callLater(1, reactor.stop)
|
||||
|
||||
# server start/stop hooks
|
||||
|
||||
|
|
|
|||
|
|
@ -419,7 +419,10 @@ class ServerSession(Session):
|
|||
|
||||
def __eq__(self, other):
|
||||
"Handle session comparisons"
|
||||
return self.address == other.address
|
||||
try:
|
||||
return self.address == other.address
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
def __str__(self):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue