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
=== modified file '_zeitgeist/engine/main.py'
--- _zeitgeist/engine/main.py 2010-04-08 20:10:04 +0000
+++ _zeitgeist/engine/main.py 2010-04-12 22:29:20 +0000
@@ -400,17 +400,7 @@
400 400
401 id = self.next_event_id()401 id = self.next_event_id()
402 402
403 if event.payload:403 payload_id = self._store_payload (event)
404 # TODO: Rigth now payloads are not unique and every event has its
405 # own one. We could optimize this to store those which are repeated
406 # for different events only once, especially considering that
407 # events cannot be modified once they've been inserted.
408 payload_id = self._cursor.execute(
409 "INSERT INTO payload (value) VALUES (?)", (event.payload,))
410 payload_id = self._cursor.lastrowid
411 else:
412 # Don't use None here, as that'd be inserted literally into the DB
413 payload_id = ""
414 404
415 # Make sure all URIs are inserted405 # Make sure all URIs are inserted
416 _origin = [subject.origin for subject in event.subjects if subject.origin]406 _origin = [subject.origin for subject in event.subjects if subject.origin]
@@ -480,6 +470,24 @@
480 470
481 return id471 return id
482 472
473 def _store_payload (self, event):
474 # TODO: Rigth now payloads are not unique and every event has its
475 # own one. We could optimize this to store those which are repeated
476 # for different events only once, especially considering that
477 # events cannot be modified once they've been inserted.
478 if event.payload:
479 # TODO: For Python >= 2.6 bytearray() is much more efficient
480 # than this hack...
481 # We need binary encoding that sqlite3 will accept, for
482 # some reason sqlite3 can not use array.array('B', event.payload)
483 payload = sqlite3.Binary("".join(map(str, event.payload)))
484 self._cursor.execute(
485 "INSERT INTO payload (value) VALUES (?)", (payload,))
486 return self._cursor.lastrowid
487 else:
488 # Don't use None here, as that'd be inserted literally into the DB
489 return ""
490
483 def delete_events (self, ids):491 def delete_events (self, ids):
484 # Extract min and max timestamps for deleted events492 # Extract min and max timestamps for deleted events
485 self._cursor.execute("""493 self._cursor.execute("""
486494
=== modified file '_zeitgeist/engine/sql.py'
--- _zeitgeist/engine/sql.py 2010-04-04 14:56:16 +0000
+++ _zeitgeist/engine/sql.py 2010-04-12 22:29:20 +0000
@@ -252,7 +252,8 @@
252 event.interpretation,252 event.interpretation,
253 event.manifestation,253 event.manifestation,
254 event.actor,254 event.actor,
255 event.payload,255 (SELECT value FROM payload WHERE payload.id=event.id)
256 as payload,
256 (SELECT value FROM uri WHERE uri.id=event.subj_id)257 (SELECT value FROM uri WHERE uri.id=event.subj_id)
257 AS subj_uri,258 AS subj_uri,
258 event.subj_interpretation,259 event.subj_interpretation,
259260
=== modified file 'test/engine-test.py'
--- test/engine-test.py 2010-04-08 20:27:43 +0000
+++ test/engine-test.py 2010-04-12 22:29:20 +0000
@@ -581,7 +581,10 @@
581 subject.uri = "http://www.google.com"581 subject.uri = "http://www.google.com"
582 subject.interpretation = Interpretation.UNKNOWN582 subject.interpretation = Interpretation.UNKNOWN
583 subject.manifestation = Manifestation.WEB_HISTORY583 subject.manifestation = Manifestation.WEB_HISTORY
584 subject.text = None
584 subject.mimetype = "text/html"585 subject.mimetype = "text/html"
586 subject.origin = None
587 subject.storage = None
585 ev.subjects.append(subject)588 ev.subjects.append(subject)
586589
587 sampleString = """590 sampleString = """