Merge lp:~zeitgeist/zeitgeist/398440 into lp:zeitgeist/0.1

Proposed by Siegfried Gevatter
Status: Merged
Merged at revision: 1029
Proposed branch: lp:~zeitgeist/zeitgeist/398440
Merge into: lp:zeitgeist/0.1
Diff against target: None lines
To merge this branch: bzr merge lp:~zeitgeist/zeitgeist/398440
Reviewer Review Type Date Requested Status
Seif Lotfy Pending
Markus Korn Pending
Zeitgeist Framework Team Pending
Review via email: mp+8744@code.launchpad.net
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/engine.py'
2--- _zeitgeist/engine/engine.py 2009-07-13 20:00:46 +0000
3+++ _zeitgeist/engine/engine.py 2009-07-14 12:27:06 +0000
4@@ -32,6 +32,7 @@
5 import sqlite3
6
7 from _zeitgeist.engine.base import *
8+from _zeitgeist.lrucache import LRUCache
9 from zeitgeist.dbusutils import EventDict
10
11 logging.basicConfig(level=logging.DEBUG)
12@@ -50,7 +51,7 @@
13 self.store = storm_store
14 self._apps = set()
15 self._last_time_from_app = {}
16- self._apps_id = {}
17+ self._applications = LRUCache(10)
18
19 '''
20 path = BaseDirectory.save_data_path("zeitgeist")
21@@ -59,16 +60,6 @@
22 self.cursor = self.connection.cursor()
23 '''
24
25- def _get_app(self, id):
26- if self._apps_id.has_key(id):
27- return self._apps_id[id]
28-
29- info = self.store.execute("SELECT info FROM app WHERE item_id=?",
30- (id,)).get_one()
31- if info:
32- self._apps_id[id] = info[0]
33- return info[0]
34-
35 def _get_ids(self, uri, content, source):
36 uri_id = URI.lookup_or_create(uri).id if uri else None
37 content_id = Content.lookup_or_create(content).id if content else None
38@@ -175,18 +166,17 @@
39 return 2 if event_exists else 1
40
41 # Insert the application
42- # FIXME: Is reading the .desktop file and storing that stuff into
43- # the DB really required?
44- app_info = DesktopEntry(ritem["app"])
45- app_uri_id, app_content_id, app_source_id = self._get_ids(ritem["app"],
46- unicode(app_info.getType()), unicode(app_info.getExec()).split()[0])
47- app_item = self._get_item(app_uri_id, app_content_id, app_source_id,
48- unicode(app_info.getName()), icon=unicode(app_info.getIcon()))
49- try:
50- self.store.execute("INSERT INTO app (item_id, info) VALUES (?,?)",
51- (app_uri_id, unicode(ritem["app"])), noresult=True)
52- except sqlite3.IntegrityError:
53- pass
54+ if ritem["app"] in self._applications:
55+ app_uri_id = self._applications[ritem["app"]]
56+ else:
57+ try:
58+ self.store.execute("INSERT INTO app (info) VALUES (?)",
59+ (ritem["app"],), noresult=True)
60+ except sqlite3.IntegrityError:
61+ pass
62+ app_uri_id = self.store.execute(
63+ "SELECT item_id FROM app WHERE info=?", (ritem["app"],)).get_one()[0]
64+ self._applications[ritem["app"]] = app_uri_id
65
66 # Insert the event
67 e_id, e_content_id, e_subject_id = self._get_ids(event_uri, ritem["use"], None)
68@@ -494,10 +484,12 @@
69 0 is returned.
70 """
71
72- app = App.lookup(application)
73-
74- return self.store.find(Event.start, Event.app == app.item.id
75- ).order_by(Event.start).last() if app else 0
76+ query = self.store.execute("""
77+ SELECT start FROM event
78+ WHERE app_id = (SELECT item_id FROM app WHERE info = ?)
79+ ORDER BY start DESC LIMIT 1
80+ """, (application,)).get_one()
81+ return query[0] if query else 0
82
83 _engine = None
84 def get_default_engine():

Subscribers

People subscribed via source and target branches