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

View file

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