Merge lp:~kamstrup/zeitgeist/payload-fix into lp:zeitgeist/0.1

Proposed by Mikkel Kamstrup Erlandsen
Status: Merged
Merged at revision: not available
Proposed branch: lp:~kamstrup/zeitgeist/payload-fix
Merge into: lp:zeitgeist/0.1
Diff against target: 76 lines (+24/-12)
3 files modified
_zeitgeist/engine/main.py (+19/-11)
_zeitgeist/engine/sql.py (+2/-1)
test/engine-test.py (+3/-0)
To merge this branch: bzr merge lp:~kamstrup/zeitgeist/payload-fix
Reviewer Review Type Date Requested Status
Zeitgeist Framework Team Pending
Review via email: mp+23276@code.launchpad.net

Description of the change

See commit log

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 '_zeitgeist/engine/main.py'
2--- _zeitgeist/engine/main.py 2010-04-08 20:10:04 +0000
3+++ _zeitgeist/engine/main.py 2010-04-12 22:29:20 +0000
4@@ -400,17 +400,7 @@
5
6 id = self.next_event_id()
7
8- if event.payload:
9- # TODO: Rigth now payloads are not unique and every event has its
10- # own one. We could optimize this to store those which are repeated
11- # for different events only once, especially considering that
12- # events cannot be modified once they've been inserted.
13- payload_id = self._cursor.execute(
14- "INSERT INTO payload (value) VALUES (?)", (event.payload,))
15- payload_id = self._cursor.lastrowid
16- else:
17- # Don't use None here, as that'd be inserted literally into the DB
18- payload_id = ""
19+ payload_id = self._store_payload (event)
20
21 # Make sure all URIs are inserted
22 _origin = [subject.origin for subject in event.subjects if subject.origin]
23@@ -480,6 +470,24 @@
24
25 return id
26
27+ def _store_payload (self, event):
28+ # TODO: Rigth now payloads are not unique and every event has its
29+ # own one. We could optimize this to store those which are repeated
30+ # for different events only once, especially considering that
31+ # events cannot be modified once they've been inserted.
32+ if event.payload:
33+ # TODO: For Python >= 2.6 bytearray() is much more efficient
34+ # than this hack...
35+ # We need binary encoding that sqlite3 will accept, for
36+ # some reason sqlite3 can not use array.array('B', event.payload)
37+ payload = sqlite3.Binary("".join(map(str, event.payload)))
38+ self._cursor.execute(
39+ "INSERT INTO payload (value) VALUES (?)", (payload,))
40+ return self._cursor.lastrowid
41+ else:
42+ # Don't use None here, as that'd be inserted literally into the DB
43+ return ""
44+
45 def delete_events (self, ids):
46 # Extract min and max timestamps for deleted events
47 self._cursor.execute("""
48
49=== modified file '_zeitgeist/engine/sql.py'
50--- _zeitgeist/engine/sql.py 2010-04-04 14:56:16 +0000
51+++ _zeitgeist/engine/sql.py 2010-04-12 22:29:20 +0000
52@@ -252,7 +252,8 @@
53 event.interpretation,
54 event.manifestation,
55 event.actor,
56- event.payload,
57+ (SELECT value FROM payload WHERE payload.id=event.id)
58+ as payload,
59 (SELECT value FROM uri WHERE uri.id=event.subj_id)
60 AS subj_uri,
61 event.subj_interpretation,
62
63=== modified file 'test/engine-test.py'
64--- test/engine-test.py 2010-04-08 20:27:43 +0000
65+++ test/engine-test.py 2010-04-12 22:29:20 +0000
66@@ -581,7 +581,10 @@
67 subject.uri = "http://www.google.com"
68 subject.interpretation = Interpretation.UNKNOWN
69 subject.manifestation = Manifestation.WEB_HISTORY
70+ subject.text = None
71 subject.mimetype = "text/html"
72+ subject.origin = None
73+ subject.storage = None
74 ev.subjects.append(subject)
75
76 sampleString = """