Merge lp:~seif/zeitgeist/optimize-find-related-uris into lp:zeitgeist/0.1

Proposed by Seif Lotfy
Status: Merged
Merge reported by: Seif Lotfy
Merged at revision: not available
Proposed branch: lp:~seif/zeitgeist/optimize-find-related-uris
Merge into: lp:zeitgeist/0.1
Diff against target: 29 lines (+10/-7)
1 file modified
_zeitgeist/engine/main.py (+10/-7)
To merge this branch: bzr merge lp:~seif/zeitgeist/optimize-find-related-uris
Reviewer Review Type Date Requested Status
Seif Lotfy Approve
Review via email: mp+38820@code.launchpad.net

Description of the change

This is nothing else but a tiny optimization. Instead of calling get_events for the ids and thus resulting in having "Events" returned I did manual querying of the DB to get timestamp, id and uri. Thus saving us time and memory. The results are 2x faster than before

To post a comment you must log in.
Revision history for this message
Seif Lotfy (seif) wrote :

RainCT gave me an ACK on IRC
<seif_> thekorn, RainCT
<seif_> https://code.edge.launchpad.net/~seif/zeitgeist/optimize-find-related-uris/+merge/38820
<RainCT> seif_: cool
<RainCT> seif_: go for it
<RainCT> (if the tests work)

Revision history for this message
Seif Lotfy (seif) wrote :

<seif_> thekorn, RainCT
<seif_> https://code.edge.launchpad.net/~seif/zeitgeist/optimize-find-related-uris/+merge/38820
<RainCT> seif_: cool
<RainCT> seif_: go for it
<RainCT> (if the tests work)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '_zeitgeist/engine/main.py'
2--- _zeitgeist/engine/main.py 2010-10-18 20:09:25 +0000
3+++ _zeitgeist/engine/main.py 2010-10-19 10:29:41 +0000
4@@ -432,15 +432,18 @@
5 pot.append(x)
6
7 # Out of the pot we get all respected events and count which uris occur most
8- events = self.get_events(pot)
9+ rows = self._cursor.execute("""
10+ SELECT id, timestamp, subj_uri FROM event_view
11+ WHERE id IN (%s)
12+ """ % ",".join("%d" % id for id in pot)).fetchall()
13+
14 subject_uri_counter = defaultdict(int)
15 latest_uris = defaultdict(int)
16- for event in events:
17- if event and event.id not in ids:
18- subj = event.subjects[0]
19- subject_uri_counter[subj.uri] += 1
20- if latest_uris[subj.uri] < event.timestamp:
21- latest_uris[subj.uri] = event.timestamp
22+ for id, timestamp, uri in rows:
23+ if id not in ids:
24+ subject_uri_counter[uri] += 1
25+ if latest_uris[uri] < timestamp:
26+ latest_uris[uri] = timestamp
27
28 log.debug("FindRelatedUris: Finished ranking subjects %fs." % \
29 (time.time()-t1))

Subscribers

People subscribed via source and target branches