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
1=== modified file 'src/db-reader.vala'
2--- src/db-reader.vala 2012-03-17 14:47:09 +0000
3+++ src/db-reader.vala 2012-03-19 17:30:32 +0000
4@@ -170,112 +170,7 @@
5 where_sql = "WHERE " + where.get_sql_conditions ();
6 }
7
8- switch (result_type)
9- {
10- case ResultType.MOST_RECENT_EVENTS:
11- sql += where_sql + " ORDER BY timestamp DESC";
12- break;
13- case ResultType.LEAST_RECENT_EVENTS:
14- sql += where_sql + " ORDER BY timestamp ASC";
15- break;
16- case ResultType.MOST_RECENT_EVENT_ORIGIN:
17- sql += group_and_sort ("origin", where_sql, false);
18- break;
19- case ResultType.LEAST_RECENT_EVENT_ORIGIN:
20- sql += group_and_sort ("origin", where_sql, true);
21- break;
22- case ResultType.MOST_POPULAR_EVENT_ORIGIN:
23- sql += group_and_sort ("origin", where_sql, false, false);
24- break;
25- case ResultType.LEAST_POPULAR_EVENT_ORIGIN:
26- sql += group_and_sort ("origin", where_sql, true, true);
27- break;
28- case ResultType.MOST_RECENT_SUBJECTS:
29- sql += group_and_sort ("subj_id", where_sql, false);
30- break;
31- case ResultType.LEAST_RECENT_SUBJECTS:
32- sql += group_and_sort ("subj_id", where_sql, true);
33- break;
34- case ResultType.MOST_POPULAR_SUBJECTS:
35- sql += group_and_sort ("subj_id", where_sql, false, false);
36- break;
37- case ResultType.LEAST_POPULAR_SUBJECTS:
38- sql += group_and_sort ("subj_id", where_sql, true, true);
39- break;
40- case ResultType.MOST_RECENT_CURRENT_URI:
41- sql += group_and_sort ("subj_id_current", where_sql, false);
42- break;
43- case ResultType.LEAST_RECENT_CURRENT_URI:
44- sql += group_and_sort ("subj_id_current", where_sql, true);
45- break;
46- case ResultType.MOST_POPULAR_CURRENT_URI:
47- sql += group_and_sort ("subj_id_current", where_sql,
48- false, false);
49- break;
50- case ResultType.LEAST_POPULAR_CURRENT_URI:
51- sql += group_and_sort ("subj_id_current", where_sql,
52- true, true);
53- break;
54- case ResultType.MOST_RECENT_ACTOR:
55- sql += group_and_sort ("actor", where_sql, false);
56- break;
57- case ResultType.LEAST_RECENT_ACTOR:
58- sql += group_and_sort ("actor", where_sql, true);
59- break;
60- case ResultType.MOST_POPULAR_ACTOR:
61- sql += group_and_sort ("actor", where_sql, false, false);
62- break;
63- case ResultType.LEAST_POPULAR_ACTOR:
64- sql += group_and_sort ("actor", where_sql, true, true);
65- break;
66- case ResultType.OLDEST_ACTOR:
67- sql += group_and_sort ("actor", where_sql, true, null, "min");
68- break;
69- case ResultType.MOST_RECENT_ORIGIN:
70- sql += group_and_sort ("subj_origin", where_sql, false);
71- break;
72- case ResultType.LEAST_RECENT_ORIGIN:
73- sql += group_and_sort ("subj_origin", where_sql, true);
74- break;
75- case ResultType.MOST_POPULAR_ORIGIN:
76- sql += group_and_sort ("subj_origin", where_sql, false, false);
77- break;
78- case ResultType.LEAST_POPULAR_ORIGIN:
79- sql += group_and_sort ("subj_origin", where_sql, true, true);
80- break;
81- case ResultType.MOST_RECENT_SUBJECT_INTERPRETATION:
82- sql += group_and_sort ("subj_interpretation", where_sql, false);
83- break;
84- case ResultType.LEAST_RECENT_SUBJECT_INTERPRETATION:
85- sql += group_and_sort ("subj_interpretation", where_sql, true);
86- break;
87- case ResultType.MOST_POPULAR_SUBJECT_INTERPRETATION:
88- sql += group_and_sort ("subj_interpretation", where_sql,
89- false, false);
90- break;
91- case ResultType.LEAST_POPULAR_SUBJECT_INTERPRETATION:
92- sql += group_and_sort ("subj_interpretation", where_sql,
93- true, true);
94- break;
95- case ResultType.MOST_RECENT_MIMETYPE:
96- sql += group_and_sort ("subj_mimetype", where_sql, false);
97- break;
98- case ResultType.LEAST_RECENT_MIMETYPE:
99- sql += group_and_sort ("subj_mimetype", where_sql, true);
100- break;
101- case ResultType.MOST_POPULAR_MIMETYPE:
102- sql += group_and_sort ("subj_mimetype", where_sql,
103- false, false);
104- break;
105- case ResultType.LEAST_POPULAR_MIMETYPE:
106- sql += group_and_sort ("subj_mimetype", where_sql,
107- true, true);
108- break;
109- default:
110- string error_message = "Invalid ResultType.";
111- warning (error_message);
112- throw new EngineError.INVALID_ARGUMENT (error_message);
113- }
114+ sql += group_clause (result_type, where_sql);
115
116 int rc;
117 Sqlite.Statement stmt;
118@@ -576,6 +471,86 @@
119 database.close ();
120 }
121
122+ public string group_clause (uint type, string where_sql) throws EngineError
123+ {
124+ switch (type)
125+ {
126+ case ResultType.MOST_RECENT_EVENTS:
127+ return " ORDER BY timestamp DESC";
128+ case ResultType.LEAST_RECENT_EVENTS:
129+ return " ORDER BY timestamp ASC";
130+ case ResultType.MOST_RECENT_EVENT_ORIGIN:
131+ return group_and_sort ("origin", where_sql, false);
132+ case ResultType.LEAST_RECENT_EVENT_ORIGIN:
133+ return group_and_sort ("origin", where_sql, true);
134+ case ResultType.MOST_POPULAR_EVENT_ORIGIN:
135+ return group_and_sort ("origin", where_sql, false, false);
136+ case ResultType.LEAST_POPULAR_EVENT_ORIGIN:
137+ return group_and_sort ("origin", where_sql, true, true);
138+ case ResultType.MOST_RECENT_SUBJECTS:
139+ return group_and_sort ("subj_id", where_sql, false);
140+ case ResultType.LEAST_RECENT_SUBJECTS:
141+ return group_and_sort ("subj_id", where_sql, true);
142+ case ResultType.MOST_POPULAR_SUBJECTS:
143+ return group_and_sort ("subj_id", where_sql, false, false);
144+ case ResultType.LEAST_POPULAR_SUBJECTS:
145+ return group_and_sort ("subj_id", where_sql, true, true);
146+ case ResultType.MOST_RECENT_CURRENT_URI:
147+ return group_and_sort ("subj_id_current", where_sql, false);
148+ case ResultType.LEAST_RECENT_CURRENT_URI:
149+ return group_and_sort ("subj_id_current", where_sql, true);
150+ break;
151+ case ResultType.MOST_POPULAR_CURRENT_URI:
152+ return group_and_sort ("subj_id_current", where_sql,
153+ false, false);
154+ case ResultType.LEAST_POPULAR_CURRENT_URI:
155+ return group_and_sort ("subj_id_current", where_sql,
156+ true, true);
157+ case ResultType.MOST_RECENT_ACTOR:
158+ return group_and_sort ("actor", where_sql, false);
159+ case ResultType.LEAST_RECENT_ACTOR:
160+ return group_and_sort ("actor", where_sql, true);
161+ case ResultType.MOST_POPULAR_ACTOR:
162+ return group_and_sort ("actor", where_sql, false, false);
163+ case ResultType.LEAST_POPULAR_ACTOR:
164+ return group_and_sort ("actor", where_sql, true, true);
165+ case ResultType.OLDEST_ACTOR:
166+ return group_and_sort ("actor", where_sql, true, null, "min");
167+ case ResultType.MOST_RECENT_ORIGIN:
168+ return group_and_sort ("subj_origin", where_sql, false);
169+ case ResultType.LEAST_RECENT_ORIGIN:
170+ return group_and_sort ("subj_origin", where_sql, true);
171+ case ResultType.MOST_POPULAR_ORIGIN:
172+ return group_and_sort ("subj_origin", where_sql, false, false);
173+ case ResultType.LEAST_POPULAR_ORIGIN:
174+ return group_and_sort ("subj_origin", where_sql, true, true);
175+ case ResultType.MOST_RECENT_SUBJECT_INTERPRETATION:
176+ return group_and_sort ("subj_interpretation", where_sql, false);
177+ case ResultType.LEAST_RECENT_SUBJECT_INTERPRETATION:
178+ return group_and_sort ("subj_interpretation", where_sql, true);
179+ case ResultType.MOST_POPULAR_SUBJECT_INTERPRETATION:
180+ return group_and_sort ("subj_interpretation", where_sql,
181+ false, false);
182+ case ResultType.LEAST_POPULAR_SUBJECT_INTERPRETATION:
183+ return group_and_sort ("subj_interpretation", where_sql,
184+ true, true);
185+ case ResultType.MOST_RECENT_MIMETYPE:
186+ return group_and_sort ("subj_mimetype", where_sql, false);
187+ case ResultType.LEAST_RECENT_MIMETYPE:
188+ return group_and_sort ("subj_mimetype", where_sql, true);
189+ case ResultType.MOST_POPULAR_MIMETYPE:
190+ return group_and_sort ("subj_mimetype", where_sql,
191+ false, false);
192+ case ResultType.LEAST_POPULAR_MIMETYPE:
193+ return group_and_sort ("subj_mimetype", where_sql,
194+ true, true);
195+ default:
196+ string error_message = "Invalid ResultType.";
197+ warning (error_message);
198+ throw new EngineError.INVALID_ARGUMENT (error_message);
199+ }
200+ }
201+
202 // Used by find_event_ids
203 private string group_and_sort (string field, string where_sql,
204 bool time_asc=false, bool? count_asc=null,
205
206=== modified file 'src/engine.vala'
207--- src/engine.vala 2012-03-14 14:26:11 +0000
208+++ src/engine.vala 2012-03-19 17:30:32 +0000
209@@ -277,6 +277,46 @@
210 return event.id;
211 }
212
213+ public uint32[] delete_events_in_time_range (TimeRange range,
214+ GenericArray<Event> event_templates,
215+ uint storage_state, uint max_events, uint result_type,
216+ BusName? sender=null) throws EngineError
217+ {
218+ uint32[] event_ids = find_event_ids (range, event_templates,
219+ storage_state, max_events, result_type);
220+
221+ WhereClause where = get_where_clause_for_query (range, event_templates,
222+ storage_state, sender);
223+
224+ string sql = "DELETE FROM event_view ";
225+ string where_sql = "";
226+ if (!where.is_empty ())
227+ {
228+ where_sql = "WHERE " + where.get_sql_conditions ();
229+ }
230+
231+ sql += group_clause (result_type, where_sql);
232+
233+ if (max_events > 0)
234+ sql += " LIMIT %u".printf(max_events);
235+
236+ int rc;
237+ Sqlite.Statement stmt;
238+
239+ rc = db.prepare_v2 (sql, -1, out stmt);
240+ database.assert_query_success(rc, "SQL error");
241+
242+ var arguments = where.get_bind_arguments ();
243+ for (int i = 0; i < arguments.length; ++i)
244+ stmt.bind_text (i + 1, arguments[i]);
245+
246+#if EXPLAIN_QUERIES
247+ database.explain_query (stmt);
248+#endif
249+
250+ return event_ids;
251+ }
252+
253 public TimeRange? delete_events (uint32[] event_ids, BusName? sender)
254 throws EngineError
255 requires (event_ids.length > 0)
256
257=== modified file 'src/remote.vala'
258--- src/remote.vala 2012-02-10 17:03:50 +0000
259+++ src/remote.vala 2012-03-19 17:30:32 +0000
260@@ -38,6 +38,13 @@
261 BusName sender
262 ) throws Error;
263
264+ public abstract uint32[] delete_events_in_time_range (
265+ [DBus (signature = "(xx)")] Variant time_range,
266+ [DBus (signature = "a(asaasay)")] Variant event_templates,
267+ uint storage_state, uint num_events, uint result_type,
268+ BusName sender
269+ ) throws Error;
270+
271 public abstract uint32[] find_event_ids (
272 [DBus (signature = "(xx)")] Variant time_range,
273 [DBus (signature = "a(asaasay)")] Variant event_templates,
274
275=== modified file 'src/zeitgeist-daemon.vala'
276--- src/zeitgeist-daemon.vala 2012-03-01 14:47:30 +0000
277+++ src/zeitgeist-daemon.vala 2012-03-19 17:30:32 +0000
278@@ -205,6 +205,17 @@
279 return event_ids;
280 }
281
282+ public uint32[] delete_events_in_time_range (Variant range,
283+ Variant event_templates,
284+ uint storage_state, uint num_events, uint result_type,
285+ BusName sender) throws Error
286+ {
287+ uint32[] event_ids = engine.delete_events_in_time_range (new TimeRange.from_variant(range),
288+ Events.from_variant (event_templates),
289+ storage_state, num_events, result_type, sender);
290+ return event_ids;
291+ }
292+
293 public Variant delete_events (uint32[] event_ids, BusName sender)
294 throws Error
295 {

Subscribers

People subscribed via source and target branches