Merge lp:~tdfischer/zeitgeist/timerange-deletion-api into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Trever Fischer
Status: Needs review
Proposed branch: lp:~tdfischer/zeitgeist/timerange-deletion-api
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Prerequisite: lp:~tdfischer/zeitgeist/common-where
Diff against target: 295 lines (+139/-106)
4 files modified
src/db-reader.vala (+81/-106)
src/engine.vala (+40/-0)
src/remote.vala (+7/-0)
src/zeitgeist-daemon.vala (+11/-0)
To merge this branch: bzr merge lp:~tdfischer/zeitgeist/timerange-deletion-api
Reviewer Review Type Date Requested Status
Siegfried Gevatter Needs Fixing
Review via email: mp+97272@code.launchpad.net

Description of the change

Fixes #799531

To post a comment you must log in.
423. By Trever Fischer

--rolling_face_on_keyboard

Revision history for this message
Siegfried Gevatter (rainct) wrote :

Hi Trever,

First of all, thank you for working on this!

As commented on IRC, I don't really see a point for storage_state, num_events and result_type in the event deletion method. The original proposal just had time_range and event_templates.

(I'm also unconvinced that this methods performance is critical enough to warrant the complexity of duplicating the query. I think I may prefer a FindEventIds+DeleteEvents implementation, like Seif proposed.)

review: Needs Fixing
Revision history for this message
Trever Fischer (tdfischer) wrote :

As noted in the original bug, simply querying all the event ids in a time range and then handing it to delete_events causes the SQL error described: "Too many variables"

Revision history for this message
Siegfried Gevatter (rainct) wrote :

(Follow up from IRC: the "too many variables" bug has already been fixed)

Unmerged revisions

423. By Trever Fischer

--rolling_face_on_keyboard

422. By Trever Fischer

Implement timerange deletion

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/db-reader.vala'
--- src/db-reader.vala 2012-03-17 14:47:09 +0000
+++ src/db-reader.vala 2012-03-19 17:30:32 +0000
@@ -170,112 +170,7 @@
170 where_sql = "WHERE " + where.get_sql_conditions ();170 where_sql = "WHERE " + where.get_sql_conditions ();
171 }171 }
172172
173 switch (result_type)173 sql += group_clause (result_type, where_sql);
174 {
175 case ResultType.MOST_RECENT_EVENTS:
176 sql += where_sql + " ORDER BY timestamp DESC";
177 break;
178 case ResultType.LEAST_RECENT_EVENTS:
179 sql += where_sql + " ORDER BY timestamp ASC";
180 break;
181 case ResultType.MOST_RECENT_EVENT_ORIGIN:
182 sql += group_and_sort ("origin", where_sql, false);
183 break;
184 case ResultType.LEAST_RECENT_EVENT_ORIGIN:
185 sql += group_and_sort ("origin", where_sql, true);
186 break;
187 case ResultType.MOST_POPULAR_EVENT_ORIGIN:
188 sql += group_and_sort ("origin", where_sql, false, false);
189 break;
190 case ResultType.LEAST_POPULAR_EVENT_ORIGIN:
191 sql += group_and_sort ("origin", where_sql, true, true);
192 break;
193 case ResultType.MOST_RECENT_SUBJECTS:
194 sql += group_and_sort ("subj_id", where_sql, false);
195 break;
196 case ResultType.LEAST_RECENT_SUBJECTS:
197 sql += group_and_sort ("subj_id", where_sql, true);
198 break;
199 case ResultType.MOST_POPULAR_SUBJECTS:
200 sql += group_and_sort ("subj_id", where_sql, false, false);
201 break;
202 case ResultType.LEAST_POPULAR_SUBJECTS:
203 sql += group_and_sort ("subj_id", where_sql, true, true);
204 break;
205 case ResultType.MOST_RECENT_CURRENT_URI:
206 sql += group_and_sort ("subj_id_current", where_sql, false);
207 break;
208 case ResultType.LEAST_RECENT_CURRENT_URI:
209 sql += group_and_sort ("subj_id_current", where_sql, true);
210 break;
211 case ResultType.MOST_POPULAR_CURRENT_URI:
212 sql += group_and_sort ("subj_id_current", where_sql,
213 false, false);
214 break;
215 case ResultType.LEAST_POPULAR_CURRENT_URI:
216 sql += group_and_sort ("subj_id_current", where_sql,
217 true, true);
218 break;
219 case ResultType.MOST_RECENT_ACTOR:
220 sql += group_and_sort ("actor", where_sql, false);
221 break;
222 case ResultType.LEAST_RECENT_ACTOR:
223 sql += group_and_sort ("actor", where_sql, true);
224 break;
225 case ResultType.MOST_POPULAR_ACTOR:
226 sql += group_and_sort ("actor", where_sql, false, false);
227 break;
228 case ResultType.LEAST_POPULAR_ACTOR:
229 sql += group_and_sort ("actor", where_sql, true, true);
230 break;
231 case ResultType.OLDEST_ACTOR:
232 sql += group_and_sort ("actor", where_sql, true, null, "min");
233 break;
234 case ResultType.MOST_RECENT_ORIGIN:
235 sql += group_and_sort ("subj_origin", where_sql, false);
236 break;
237 case ResultType.LEAST_RECENT_ORIGIN:
238 sql += group_and_sort ("subj_origin", where_sql, true);
239 break;
240 case ResultType.MOST_POPULAR_ORIGIN:
241 sql += group_and_sort ("subj_origin", where_sql, false, false);
242 break;
243 case ResultType.LEAST_POPULAR_ORIGIN:
244 sql += group_and_sort ("subj_origin", where_sql, true, true);
245 break;
246 case ResultType.MOST_RECENT_SUBJECT_INTERPRETATION:
247 sql += group_and_sort ("subj_interpretation", where_sql, false);
248 break;
249 case ResultType.LEAST_RECENT_SUBJECT_INTERPRETATION:
250 sql += group_and_sort ("subj_interpretation", where_sql, true);
251 break;
252 case ResultType.MOST_POPULAR_SUBJECT_INTERPRETATION:
253 sql += group_and_sort ("subj_interpretation", where_sql,
254 false, false);
255 break;
256 case ResultType.LEAST_POPULAR_SUBJECT_INTERPRETATION:
257 sql += group_and_sort ("subj_interpretation", where_sql,
258 true, true);
259 break;
260 case ResultType.MOST_RECENT_MIMETYPE:
261 sql += group_and_sort ("subj_mimetype", where_sql, false);
262 break;
263 case ResultType.LEAST_RECENT_MIMETYPE:
264 sql += group_and_sort ("subj_mimetype", where_sql, true);
265 break;
266 case ResultType.MOST_POPULAR_MIMETYPE:
267 sql += group_and_sort ("subj_mimetype", where_sql,
268 false, false);
269 break;
270 case ResultType.LEAST_POPULAR_MIMETYPE:
271 sql += group_and_sort ("subj_mimetype", where_sql,
272 true, true);
273 break;
274 default:
275 string error_message = "Invalid ResultType.";
276 warning (error_message);
277 throw new EngineError.INVALID_ARGUMENT (error_message);
278 }
279174
280 int rc;175 int rc;
281 Sqlite.Statement stmt;176 Sqlite.Statement stmt;
@@ -576,6 +471,86 @@
576 database.close ();471 database.close ();
577 }472 }
578473
474 public string group_clause (uint type, string where_sql) throws EngineError
475 {
476 switch (type)
477 {
478 case ResultType.MOST_RECENT_EVENTS:
479 return " ORDER BY timestamp DESC";
480 case ResultType.LEAST_RECENT_EVENTS:
481 return " ORDER BY timestamp ASC";
482 case ResultType.MOST_RECENT_EVENT_ORIGIN:
483 return group_and_sort ("origin", where_sql, false);
484 case ResultType.LEAST_RECENT_EVENT_ORIGIN:
485 return group_and_sort ("origin", where_sql, true);
486 case ResultType.MOST_POPULAR_EVENT_ORIGIN:
487 return group_and_sort ("origin", where_sql, false, false);
488 case ResultType.LEAST_POPULAR_EVENT_ORIGIN:
489 return group_and_sort ("origin", where_sql, true, true);
490 case ResultType.MOST_RECENT_SUBJECTS:
491 return group_and_sort ("subj_id", where_sql, false);
492 case ResultType.LEAST_RECENT_SUBJECTS:
493 return group_and_sort ("subj_id", where_sql, true);
494 case ResultType.MOST_POPULAR_SUBJECTS:
495 return group_and_sort ("subj_id", where_sql, false, false);
496 case ResultType.LEAST_POPULAR_SUBJECTS:
497 return group_and_sort ("subj_id", where_sql, true, true);
498 case ResultType.MOST_RECENT_CURRENT_URI:
499 return group_and_sort ("subj_id_current", where_sql, false);
500 case ResultType.LEAST_RECENT_CURRENT_URI:
501 return group_and_sort ("subj_id_current", where_sql, true);
502 break;
503 case ResultType.MOST_POPULAR_CURRENT_URI:
504 return group_and_sort ("subj_id_current", where_sql,
505 false, false);
506 case ResultType.LEAST_POPULAR_CURRENT_URI:
507 return group_and_sort ("subj_id_current", where_sql,
508 true, true);
509 case ResultType.MOST_RECENT_ACTOR:
510 return group_and_sort ("actor", where_sql, false);
511 case ResultType.LEAST_RECENT_ACTOR:
512 return group_and_sort ("actor", where_sql, true);
513 case ResultType.MOST_POPULAR_ACTOR:
514 return group_and_sort ("actor", where_sql, false, false);
515 case ResultType.LEAST_POPULAR_ACTOR:
516 return group_and_sort ("actor", where_sql, true, true);
517 case ResultType.OLDEST_ACTOR:
518 return group_and_sort ("actor", where_sql, true, null, "min");
519 case ResultType.MOST_RECENT_ORIGIN:
520 return group_and_sort ("subj_origin", where_sql, false);
521 case ResultType.LEAST_RECENT_ORIGIN:
522 return group_and_sort ("subj_origin", where_sql, true);
523 case ResultType.MOST_POPULAR_ORIGIN:
524 return group_and_sort ("subj_origin", where_sql, false, false);
525 case ResultType.LEAST_POPULAR_ORIGIN:
526 return group_and_sort ("subj_origin", where_sql, true, true);
527 case ResultType.MOST_RECENT_SUBJECT_INTERPRETATION:
528 return group_and_sort ("subj_interpretation", where_sql, false);
529 case ResultType.LEAST_RECENT_SUBJECT_INTERPRETATION:
530 return group_and_sort ("subj_interpretation", where_sql, true);
531 case ResultType.MOST_POPULAR_SUBJECT_INTERPRETATION:
532 return group_and_sort ("subj_interpretation", where_sql,
533 false, false);
534 case ResultType.LEAST_POPULAR_SUBJECT_INTERPRETATION:
535 return group_and_sort ("subj_interpretation", where_sql,
536 true, true);
537 case ResultType.MOST_RECENT_MIMETYPE:
538 return group_and_sort ("subj_mimetype", where_sql, false);
539 case ResultType.LEAST_RECENT_MIMETYPE:
540 return group_and_sort ("subj_mimetype", where_sql, true);
541 case ResultType.MOST_POPULAR_MIMETYPE:
542 return group_and_sort ("subj_mimetype", where_sql,
543 false, false);
544 case ResultType.LEAST_POPULAR_MIMETYPE:
545 return group_and_sort ("subj_mimetype", where_sql,
546 true, true);
547 default:
548 string error_message = "Invalid ResultType.";
549 warning (error_message);
550 throw new EngineError.INVALID_ARGUMENT (error_message);
551 }
552 }
553
579 // Used by find_event_ids554 // Used by find_event_ids
580 private string group_and_sort (string field, string where_sql,555 private string group_and_sort (string field, string where_sql,
581 bool time_asc=false, bool? count_asc=null,556 bool time_asc=false, bool? count_asc=null,
582557
=== modified file 'src/engine.vala'
--- src/engine.vala 2012-03-14 14:26:11 +0000
+++ src/engine.vala 2012-03-19 17:30:32 +0000
@@ -277,6 +277,46 @@
277 return event.id;277 return event.id;
278 }278 }
279279
280 public uint32[] delete_events_in_time_range (TimeRange range,
281 GenericArray<Event> event_templates,
282 uint storage_state, uint max_events, uint result_type,
283 BusName? sender=null) throws EngineError
284 {
285 uint32[] event_ids = find_event_ids (range, event_templates,
286 storage_state, max_events, result_type);
287
288 WhereClause where = get_where_clause_for_query (range, event_templates,
289 storage_state, sender);
290
291 string sql = "DELETE FROM event_view ";
292 string where_sql = "";
293 if (!where.is_empty ())
294 {
295 where_sql = "WHERE " + where.get_sql_conditions ();
296 }
297
298 sql += group_clause (result_type, where_sql);
299
300 if (max_events > 0)
301 sql += " LIMIT %u".printf(max_events);
302
303 int rc;
304 Sqlite.Statement stmt;
305
306 rc = db.prepare_v2 (sql, -1, out stmt);
307 database.assert_query_success(rc, "SQL error");
308
309 var arguments = where.get_bind_arguments ();
310 for (int i = 0; i < arguments.length; ++i)
311 stmt.bind_text (i + 1, arguments[i]);
312
313#if EXPLAIN_QUERIES
314 database.explain_query (stmt);
315#endif
316
317 return event_ids;
318 }
319
280 public TimeRange? delete_events (uint32[] event_ids, BusName? sender)320 public TimeRange? delete_events (uint32[] event_ids, BusName? sender)
281 throws EngineError321 throws EngineError
282 requires (event_ids.length > 0)322 requires (event_ids.length > 0)
283323
=== modified file 'src/remote.vala'
--- src/remote.vala 2012-02-10 17:03:50 +0000
+++ src/remote.vala 2012-03-19 17:30:32 +0000
@@ -38,6 +38,13 @@
38 BusName sender38 BusName sender
39 ) throws Error;39 ) throws Error;
4040
41 public abstract uint32[] delete_events_in_time_range (
42 [DBus (signature = "(xx)")] Variant time_range,
43 [DBus (signature = "a(asaasay)")] Variant event_templates,
44 uint storage_state, uint num_events, uint result_type,
45 BusName sender
46 ) throws Error;
47
41 public abstract uint32[] find_event_ids (48 public abstract uint32[] find_event_ids (
42 [DBus (signature = "(xx)")] Variant time_range,49 [DBus (signature = "(xx)")] Variant time_range,
43 [DBus (signature = "a(asaasay)")] Variant event_templates,50 [DBus (signature = "a(asaasay)")] Variant event_templates,
4451
=== modified file 'src/zeitgeist-daemon.vala'
--- src/zeitgeist-daemon.vala 2012-03-01 14:47:30 +0000
+++ src/zeitgeist-daemon.vala 2012-03-19 17:30:32 +0000
@@ -205,6 +205,17 @@
205 return event_ids;205 return event_ids;
206 }206 }
207207
208 public uint32[] delete_events_in_time_range (Variant range,
209 Variant event_templates,
210 uint storage_state, uint num_events, uint result_type,
211 BusName sender) throws Error
212 {
213 uint32[] event_ids = engine.delete_events_in_time_range (new TimeRange.from_variant(range),
214 Events.from_variant (event_templates),
215 storage_state, num_events, result_type, sender);
216 return event_ids;
217 }
218
208 public Variant delete_events (uint32[] event_ids, BusName sender)219 public Variant delete_events (uint32[] event_ids, BusName sender)
209 throws Error220 throws Error
210 {221 {

Subscribers

People subscribed via source and target branches