← Back to team overview

zeitgeist team mailing list archive

[Merge] lp:~seif/zeitgeist/clean-up-get-events into lp:zeitgeist

 

Seif Lotfy has proposed merging lp:~seif/zeitgeist/clean-up-get-events into lp:zeitgeist.

Requested reviews:
  Zeitgeist Framework Team (zeitgeist)


I cleaned up and shortend the code
I am not sure how much performance increase we get out of that but I think its much more compact now.
All tests run
-- 
https://code.launchpad.net/~seif/zeitgeist/clean-up-get-events/+merge/40529
Your team Zeitgeist Framework Team is requested to review the proposed merge of lp:~seif/zeitgeist/clean-up-get-events into lp:zeitgeist.
=== modified file '_zeitgeist/engine/main.py'
--- _zeitgeist/engine/main.py	2010-10-25 09:48:49 +0000
+++ _zeitgeist/engine/main.py	2010-11-10 12:16:17 +0000
@@ -173,29 +173,19 @@
 		else:
 			ids = (row[0] for row in rows)
 		
-		events = {}
+		id_hash = dict((id, n) for n, id in enumerate(ids))
+			
+		sorted_events = [None]*len(ids)
 		for row in rows:
 			# Assumption: all rows of a same event for its different
 			# subjects are in consecutive order.
 			event = self._get_event_from_row(row)
-			if event.id not in events:
-				events[event.id] = event
-			events[event.id].append_subject(self._get_subject_from_row(row))
-		
-		# Sort events into the requested order
-		sorted_events = []
-		for id in ids:
-			# if we are not able to get an event by the given id
-			# append None instead of raising an Error. The client
-			# might simply have requested an event that has been
-			# deleted
-			event = events.get(id, None)
+			event.append_subject(self._get_subject_from_row(row))
 			event = self.extensions.apply_get_hooks(event, sender)
-			
-			sorted_events.append(event)
-		
+			if event and event.id in ids:
+				sorted_events[id_hash[event.id]] = event
+				
 		log.debug("Got %d events in %fs" % (len(sorted_events), time.time()-t))
-
 		return sorted_events
 	
 	@staticmethod


Follow ups