Speed up for calculateFinishesForMsg
This commit is contained in:
parent
79b773559f
commit
fefda5a2a5
1 changed files with 8 additions and 3 deletions
|
@ -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))
|
||||||
|
|
Loading…
Reference in a new issue