Speed up for calculateFinishesForMsg

This commit is contained in:
Ruben van de Ven 2019-05-12 15:06:00 +02:00
parent 79b773559f
commit fefda5a2a5
1 changed files with 8 additions and 3 deletions

View File

@ -1647,19 +1647,24 @@ class Story(object):
self.finish_time = time.time()
self.timer.pause()
def calculateFinishesForMsg(self, msgId, depth = 0):
def calculateFinishesForMsg(self, msgId, depth = 0, checked = []):
if msgId in checked:
return []
checked.append(msgId)
if not msgId in self.directionsPerMsg or len(self.directionsPerMsg[msgId]) < 1:
# is finish
return [msgId]
if depth > 40:
if depth > 200:
return []
finishes = []
for d in self.directionsPerMsg[msgId]:
if d.msgTo.id == msgId:
continue
finishes.extend(self.calculateFinishesForMsg(d.msgTo.id, depth+1))
finishes.extend(self.calculateFinishesForMsg(d.msgTo.id, depth+1, checked))
# de-duplicate before returning
return list(set(finishes))