Skip to content

Commit

Permalink
Use skel.refresh() in updateRelations (#524)
Browse files Browse the repository at this point in the history
- Use skel.refresh()
- Added logging for useful stuff (i.e. which entity is going to be refreshed)
- Removed logging for not so useful stuff
  • Loading branch information
phorward authored Oct 7, 2022
1 parent 21f8b3e commit 6528ee4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion core/bones/relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,7 +788,8 @@ def updateInplace(relDict):

if not skel[boneName] or self.updateLevel == 2:
return
logging.debug("Refreshing RelationalBone %s of %s" % (boneName, skel.kindName))

# logging.debug("Refreshing RelationalBone %s of %s" % (boneName, skel.kindName))
if isinstance(skel[boneName], dict):
updateInplace(skel[boneName])
elif isinstance(skel[boneName], list):
Expand Down
18 changes: 10 additions & 8 deletions core/skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,21 @@ def fromClient(cls, skelValues: SkeletonInstance, data: Dict[str, Union[List[str
return complete

@classmethod
def refresh(cls, skelValues):
def refresh(cls, skel: SkeletonInstance):
"""
Refresh the bones current content.
This function causes a refresh of all relational bones and their associated
information.
"""
for key, bone in skelValues.items():
logging.debug(f"""Refreshing {skel["key"]=}""")

for key, bone in skel.items():
if not isinstance(bone, BaseBone):
continue
skelValues[key] # Ensure value gets loaded
if "refresh" in dir(bone):
bone.refresh(skelValues, key)

_ = skel[key] # Ensure value gets loaded
bone.refresh(skel, key)

def __new__(cls, *args, **kwargs) -> SkeletonInstance:
return SkeletonInstance(cls, *args, **kwargs)
Expand Down Expand Up @@ -1305,10 +1307,10 @@ def updateRelations(destKey: db.Key, minChangeTime: int, changedBone: Optional[s

def updateTxn(skel, key, srcRelKey):
if not skel.fromDB(key):
logging.warning("Cannot update stale reference to %s (referenced from %s)" % (key, srcRelKey))
logging.warning(f"Cannot update stale reference to {key=} (referenced from {srcRelKey=})")
return
for key, _bone in skel.items():
_bone.refresh(skel, key)

skel.refresh()
skel.toDB(clearUpdateTag=True)

for srcRel in updateList:
Expand Down

0 comments on commit 6528ee4

Please sign in to comment.