# HG changeset patch # User Sylvain Thénault # Date 1255631440 -7200 # Node ID ccd72f500daa411765bebb8e46d211807d3fbc79 # Parent a5ef45850d236daa1404bc4191920dbd1d2406a4 reimplements some methods to traverse operations in reverse order, much efficient w/ transactions where there is a lot of pending operation diff -r a5ef45850d23 -r ccd72f500daa server/pool.py --- a/server/pool.py Thu Oct 15 20:29:51 2009 +0200 +++ b/server/pool.py Thu Oct 15 20:30:40 2009 +0200 @@ -180,10 +180,15 @@ """return the index of the lastest instance which is not a LateOperation instance """ - for i, op in enumerate(self.session.pending_operations): + # faster by inspecting operation in reverse order for heavy transactions + i = None + for i, op in enumerate(reversed(self.session.pending_operations)): if isinstance(op, (LateOperation, SingleLastOperation)): - return i - return None + continue + return -i or None + if i is None: + return None + return -(i + 1) def handle_event(self, event): """delegate event handling to the opertaion""" @@ -238,10 +243,15 @@ """return the index of the lastest instance which is not a SingleLastOperation instance """ - for i, op in enumerate(self.session.pending_operations): + # faster by inspecting operation in reverse order for heavy transactions + i = None + for i, op in enumerate(reversed(self.session.pending_operations)): if isinstance(op, SingleLastOperation): - return i - return None + continue + return -i or None + if i is None: + return None + return -(i + 1) class SingleOperation(Operation): @@ -261,10 +271,9 @@ def equivalent_index(self, operations): """return the index of the equivalent operation if any""" - equivalents = [i for i, op in enumerate(operations) - if op.__class__ is self.__class__] - if equivalents: - return equivalents[0] + for i, op in enumerate(reversed(operations)): + if op.__class__ is self.__class__: + return -(i+1) return None