Merge lp:~rainct/zeitgeist/insert-event-fixes into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Siegfried Gevatter
Status: Merged
Merge reported by: Siegfried Gevatter
Merged at revision: not available
Proposed branch: lp:~rainct/zeitgeist/insert-event-fixes
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 227 lines (+81/-54)
4 files modified
extensions/fts++/test/test-indexer.cpp (+12/-3)
extensions/storage-monitor.vala (+2/-1)
src/engine.vala (+64/-49)
test/dbus/blacklist-test.py (+3/-1)
To merge this branch: bzr merge lp:~rainct/zeitgeist/insert-event-fixes
Reviewer Review Type Date Requested Status
Michal Hruby (community) Approve
Review via email: mp+92468@code.launchpad.net

Description of the change

- Pre-process events before they are send to the extensions (LP: #628804).
- Fix Storage Monitor to take into account that events may be NULL.
- Fix error messages (related to MOVE_EVENT) that were interchanged.

To post a comment you must log in.
Revision history for this message
Michal Hruby (mhr3) wrote :

Looks good to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'extensions/fts++/test/test-indexer.cpp'
2--- extensions/fts++/test/test-indexer.cpp 2012-02-10 12:07:27 +0000
3+++ extensions/fts++/test/test-indexer.cpp 2012-02-10 13:40:28 +0000
4@@ -169,13 +169,22 @@
5 static guint
6 index_event (Fixture *fix, ZeitgeistEvent *event)
7 {
8+ GPtrArray *events;
9 guint event_id = 0;
10+ guint *event_ids;
11+ int num_events_inserted;
12
13 // add event to DBs
14- event_id = zeitgeist_engine_insert_event (ZEITGEIST_ENGINE (fix->db),
15- event, NULL, NULL);
16+ events = g_ptr_array_new ();
17+ g_ptr_array_add (events, event);
18+ event_ids = zeitgeist_engine_insert_events (ZEITGEIST_ENGINE (fix->db),
19+ events, NULL,
20+ &num_events_inserted, NULL);
21+ g_assert_cmpint (1, ==, num_events_inserted);
22+ event_id = *event_ids;
23+ g_ptr_array_unref (events);
24
25- GPtrArray *events = g_ptr_array_new_with_free_func (g_object_unref);
26+ events = g_ptr_array_new_with_free_func (g_object_unref);
27 g_ptr_array_add (events, event); // steal event ref
28 zeitgeist_indexer_index_events (fix->indexer, events);
29 g_ptr_array_unref (events);
30
31=== modified file 'extensions/storage-monitor.vala'
32--- extensions/storage-monitor.vala 2012-02-02 18:57:35 +0000
33+++ extensions/storage-monitor.vala 2012-02-10 13:40:28 +0000
34@@ -269,10 +269,11 @@
35 {
36 for (int i = 0; i < events.length; ++i)
37 {
38+ if (events[i] == null) continue;
39 for (int j = 0; j < events[i].subjects.length; ++j)
40 {
41 Subject subject = events[i].subjects[j];
42- if (subject.storage == "")
43+ if (Utils.is_empty_string (subject.storage))
44 subject.storage = find_storage_for_uri (subject.uri);
45 }
46 }
47
48=== modified file 'src/engine.vala'
49--- src/engine.vala 2012-02-07 17:02:05 +0000
50+++ src/engine.vala 2012-02-10 13:40:28 +0000
51@@ -27,6 +27,7 @@
52
53 using Zeitgeist;
54 using Zeitgeist.SQLite;
55+using Zeitgeist.Utils;
56
57 namespace Zeitgeist
58 {
59@@ -62,21 +63,74 @@
60 public uint32[] insert_events (GenericArray<Event> events,
61 BusName? sender=null) throws EngineError
62 {
63+ // Any changes to events need to be done here so they'll
64+ // be taken into consideration by the extensions (LP: #928804).
65+ for (int i = 0; i < events.length; ++i)
66+ {
67+ preprocess_event (events[i]);
68+ }
69+
70 extension_collection.call_pre_insert_events (events, sender);
71 uint32[] event_ids = new uint32[events.length];
72 database.begin_transaction ();
73 for (int i = 0; i < events.length; ++i)
74 {
75 if (events[i] != null)
76- event_ids[i] = insert_event (events[i], sender);
77+ event_ids[i] = insert_event (events[i]);
78 }
79 database.end_transaction ();
80 extension_collection.call_post_insert_events (events, sender);
81 return event_ids;
82 }
83
84- public uint32 insert_event (Event event,
85- BusName? sender=null) throws EngineError
86+ private void preprocess_event (Event event) throws EngineError
87+ {
88+ // Iterate through subjects and check for validity
89+ for (int i = 0; i < event.num_subjects(); ++i)
90+ {
91+ unowned Subject subject = event.subjects[i];
92+
93+ // If current_uri is unset, give it the same value as URI
94+ if (is_empty_string (subject.current_uri))
95+ subject.current_uri = subject.uri;
96+
97+ if (event.interpretation == ZG.MOVE_EVENT
98+ && subject.uri == subject.current_uri)
99+ {
100+ throw new EngineError.INVALID_ARGUMENT (
101+ "Redundant event: event.interpretation indicates " +
102+ "the uri has been moved yet the subject.uri and " +
103+ "subject.current_uri are identical");
104+ }
105+ else if (event.interpretation != ZG.MOVE_EVENT
106+ && subject.uri != subject.current_uri)
107+ {
108+ throw new EngineError.INVALID_ARGUMENT (
109+ "Illegal event: unless event.interpretation is " +
110+ "'MOVE_EVENT' then subject.uri and " +
111+ "subject.current_uri have to be the same");
112+ }
113+
114+ // If subject manifestation and interpretation are not set,
115+ // we try to automatically determine them from the other data.
116+ if (is_empty_string (subject.manifestation))
117+ {
118+ unowned string? manifestation = manifestation_for_uri (
119+ subject.uri);
120+ if (manifestation != null)
121+ subject.manifestation = manifestation;
122+ }
123+ if (is_empty_string (subject.interpretation))
124+ {
125+ unowned string? interpretation = interpretation_for_mimetype (
126+ subject.mimetype);
127+ if (interpretation != null)
128+ subject.interpretation = interpretation;
129+ }
130+ }
131+ }
132+
133+ private uint32 insert_event (Event event) throws EngineError
134 requires (event.id == 0)
135 requires (event.num_subjects () > 0)
136 {
137@@ -89,7 +143,7 @@
138 var storages = new GenericArray<string> ();
139 var subj_uris = new SList<string> ();
140
141- if (event.origin != "")
142+ if (!is_empty_string (event.origin))
143 uris.add (event.origin);
144
145 // Iterate through subjects and check for validity
146@@ -105,34 +159,14 @@
147 subj_uris.append (subject.uri);
148
149 uris.add (subject.uri);
150-
151- if (subject.current_uri == "" || subject.current_uri == null)
152- subject.current_uri = subject.uri;
153-
154- if (event.interpretation == ZG.MOVE_EVENT
155- && subject.uri == subject.current_uri)
156- {
157- throw new EngineError.INVALID_ARGUMENT (
158- "Illegal event: unless event.interpretation is " +
159- "'MOVE_EVENT' then subject.uri and " +
160- "subject.current_uri have to be the same");
161- }
162- else if (event.interpretation != ZG.MOVE_EVENT
163- && subject.uri != subject.current_uri)
164- {
165- throw new EngineError.INVALID_ARGUMENT (
166- "Redundant event: event.interpretation indicates " +
167- "the uri has been moved yet the subject.uri and " +
168- "subject.current_uri are identical");
169- }
170-
171- uris.add (subject.current_uri);
172-
173- if (subject.origin != "")
174+ if (subject.uri != subject.current_uri)
175+ uris.add (subject.current_uri);
176+
177+ if (!is_empty_string (subject.origin))
178 uris.add (subject.origin);
179- if (subject.text != "")
180+ if (!is_empty_string (subject.text))
181 texts.add (subject.text);
182- if (subject.storage != "")
183+ if (!is_empty_string(subject.storage))
184 storages.add (subject.storage);
185 }
186
187@@ -180,25 +214,6 @@
188
189 unowned Subject subject = event.subjects[i];
190
191- // If subject manifestation and interpretation are not set,
192- // we try to automatically determine them from the other data.
193-
194- if (subject.manifestation == "")
195- {
196- unowned string? manifestation = manifestation_for_uri (
197- subject.uri);
198- if (manifestation != null)
199- subject.manifestation = manifestation;
200- }
201-
202- if (subject.interpretation == "")
203- {
204- unowned string? interpretation = interpretation_for_mimetype (
205- subject.mimetype);
206- if (interpretation != null)
207- subject.interpretation = interpretation;
208- }
209-
210 insert_stmt.bind_text (8, subject.uri);
211 insert_stmt.bind_text (9, subject.current_uri);
212 insert_stmt.bind_int64 (10,
213
214=== modified file 'test/dbus/blacklist-test.py'
215--- test/dbus/blacklist-test.py 2012-02-08 12:49:38 +0000
216+++ test/dbus/blacklist-test.py 2012-02-10 13:40:28 +0000
217@@ -203,7 +203,9 @@
218 self._assert_template_count(1)
219
220 # Blocking the current_uri works
221- self._assert_insert_blocked(Event.new_for_values(subject_current_uri="t"))
222+ self._assert_insert_blocked(Event.new_for_values(
223+ interpretation=Interpretation.MOVE_EVENT,
224+ subject_current_uri="t"))
225
226 # But if we only set uri (and leave it up to Zeitgeist to set current_uri
227 # to the same value?

Subscribers

People subscribed via source and target branches