Merge lp:~achiang/laika/cache-wrapper-proxy into lp:laika

Proposed by Alex Chiang on 2010-11-24
Status: Merged
Merged at revision: 16
Proposed branch: lp:~achiang/laika/cache-wrapper-proxy
Merge into: lp:laika
Diff against target: 51 lines (+20/-0)
1 file modified
laika (+20/-0)
To merge this branch: bzr merge lp:~achiang/laika/cache-wrapper-proxy
Reviewer Review Type Date Requested Status
Alex Chiang Pending
Review via email: mp+41669@code.launchpad.net

Description of the change

Cache wrapper for launchpadlib objects, 200% performance gain

Cleverly cache launchpadlib objects to improve our performance
by up to 200%.

Thanks James Ferguson.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'laika'
2--- laika 2010-11-16 16:37:02 +0000
3+++ laika 2010-11-24 00:06:20 +0000
4@@ -22,6 +22,23 @@
5
6 UTCNOW = datetime.datetime.utcnow()
7
8+class LPWrap:
9+ '''Simple wrapper Cache-Proxy for LP objects'''
10+ def __init__(self, lpObj):
11+ self.lpObj = lpObj
12+
13+ def __getattr__(self, attr):
14+ result = getattr(self.lpObj, attr)
15+ # Tricky. We look at the attr, and if it is another launchpadlib
16+ # object, then we wrap *it* too. e.g., you asked for task.bug, where
17+ # bug is a launchpadlib object contained within the task lplib object.
18+ # Eventually, we'll just get a normal attribute that isn't an lplib
19+ # object, which we cache with setattr and then later retrieve with
20+ # the above getattr.
21+ if result.__class__.__name__ == "Entry":
22+ result = LPWrap(result)
23+ setattr(self, attr, result)
24+ return result
25
26 class Report(object):
27 '''An activity report for a specified Launchpad user.
28@@ -98,6 +115,7 @@
29 tasks = self.user.searchTasks(assignee=self.user,
30 status=self.status,
31 modified_since=self.since)
32+ tasks = [LPWrap(t) for t in tasks]
33 self.print_header("Assigned Bugs")
34
35 for t in tasks:
36@@ -124,6 +142,7 @@
37 tasks = self.user.searchTasks(bug_commenter=self.user,
38 status=self.status,
39 modified_since=self.since)
40+ tasks = [LPWrap(t) for t in tasks]
41 self.print_header("Commented Bugs")
42 for t in tasks:
43 if self.bugs.has_key(t.bug.id):
44@@ -141,6 +160,7 @@
45 tasks = self.user.searchTasks(bug_reporter=self.user,
46 status=self.status,
47 modified_since=self.since)
48+ tasks = [LPWrap(t) for t in tasks]
49 self.print_header("Reported Bugs")
50 for t in tasks:
51 if self.bugs.has_key(t.bug.id):

Subscribers

People subscribed via source and target branches

to all changes: