Merge lp:~tdfischer/zeitgeist/common-where into lp:~zeitgeist/zeitgeist/bluebird

Proposed by Trever Fischer
Status: Merged
Approved by: Siegfried Gevatter
Approved revision: 422
Merged at revision: 422
Proposed branch: lp:~tdfischer/zeitgeist/common-where
Merge into: lp:~zeitgeist/zeitgeist/bluebird
Diff against target: 129 lines (+56/-41)
1 file modified
src/db-reader.vala (+56/-41)
To merge this branch: bzr merge lp:~tdfischer/zeitgeist/common-where
Reviewer Review Type Date Requested Status
Siegfried Gevatter Approve
Review via email: mp+97270@code.launchpad.net

Description of the change

Consolidates a lot of WHERE SQL generation into a common method for re-use by other components.

To post a comment you must log in.
Revision history for this message
Siegfried Gevatter (rainct) wrote :

Hey,

Thanks for splitting this out :).

> public uint32[] find_event_ids_for_clause (WhereClause where,
> uint max_events, uint result_type,
> BusName? sender=null) throws EngineError

This method isn't using `sender' anywhere (nor should it), so drop that argument.

> public WhereClause get_where_clause_for_query

Same here.

review: Needs Fixing
lp:~tdfischer/zeitgeist/common-where updated
422. By Trever Fischer

Remove unused argument

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

Updated branch with removed arguments.

Revision history for this message
Siegfried Gevatter (rainct) :
review: Approve

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-02-05 14:52:13 +0000
+++ src/db-reader.vala 2012-03-13 18:56:18 +0000
@@ -160,47 +160,9 @@
160 return results;160 return results;
161 }161 }
162162
163 public uint32[] find_event_ids (TimeRange time_range,163 public uint32[] find_event_ids_for_clause (WhereClause where,
164 GenericArray<Event> event_templates,164 uint max_events, uint result_type) throws EngineError
165 uint storage_state, uint max_events, uint result_type,
166 BusName? sender=null) throws EngineError
167 {165 {
168
169 WhereClause where = new WhereClause (WhereClause.Type.AND);
170
171 /**
172 * We are using the unary operator here to tell SQLite to not use
173 * the index on the timestamp column at the first place. This is a
174 * "fix" for (LP: #672965) based on some benchmarks, which suggest
175 * a performance win, but we might not oversee all implications.
176 * (See http://www.sqlite.org/optoverview.html, section 6.0).
177 * -- Markus Korn, 29/11/2010
178 */
179 if (time_range.start != 0)
180 where.add (("+timestamp >= %" + int64.FORMAT).printf(
181 time_range.start));
182 if (time_range.end != 0)
183 where.add (("+timestamp <= %" + int64.FORMAT).printf(
184 time_range.end));
185
186 if (storage_state == StorageState.AVAILABLE ||
187 storage_state == StorageState.NOT_AVAILABLE)
188 {
189 where.add ("(subj_storage_state=? OR subj_storage_state IS NULL)",
190 storage_state.to_string ());
191 }
192 else if (storage_state != StorageState.ANY)
193 {
194 throw new EngineError.INVALID_ARGUMENT(
195 "Unknown storage state '%u'".printf(storage_state));
196 }
197
198 WhereClause tpl_conditions = get_where_clause_from_event_templates (
199 event_templates);
200 where.extend (tpl_conditions);
201 //if (!where.may_have_results ())
202 // return new uint32[0];
203
204 string sql = "SELECT id FROM event_view ";166 string sql = "SELECT id FROM event_view ";
205 string where_sql = "";167 string where_sql = "";
206 if (!where.is_empty ())168 if (!where.is_empty ())
@@ -352,6 +314,20 @@
352 return event_ids;314 return event_ids;
353 }315 }
354316
317 public uint32[] find_event_ids (TimeRange time_range,
318 GenericArray<Event> event_templates,
319 uint storage_state, uint max_events, uint result_type,
320 BusName? sender=null) throws EngineError
321 {
322 WhereClause where = get_where_clause_for_query (time_range,
323 event_templates, storage_state);
324
325 //if (!where.may_have_results ())
326 // return new uint32[0];
327
328 return find_event_ids_for_clause (where, max_events, result_type);
329 }
330
355 public GenericArray<Event?> find_events (TimeRange time_range,331 public GenericArray<Event?> find_events (TimeRange time_range,
356 GenericArray<Event> event_templates,332 GenericArray<Event> event_templates,
357 uint storage_state, uint max_events, uint result_type,333 uint storage_state, uint max_events, uint result_type,
@@ -361,6 +337,45 @@
361 storage_state, max_events, result_type));337 storage_state, max_events, result_type));
362 }338 }
363339
340 public WhereClause get_where_clause_for_query (TimeRange time_range,
341 GenericArray<Event> event_templates, uint storage_state) throws EngineError
342 {
343 WhereClause where = new WhereClause (WhereClause.Type.AND);
344
345 /**
346 * We are using the unary operator here to tell SQLite to not use
347 * the index on the timestamp column at the first place. This is a
348 * "fix" for (LP: #672965) based on some benchmarks, which suggest
349 * a performance win, but we might not oversee all implications.
350 * (See http://www.sqlite.org/optoverview.html, section 6.0).
351 * -- Markus Korn, 29/11/2010
352 */
353 if (time_range.start != 0)
354 where.add (("+timestamp >= %" + int64.FORMAT).printf(
355 time_range.start));
356 if (time_range.end != 0)
357 where.add (("+timestamp <= %" + int64.FORMAT).printf(
358 time_range.end));
359
360 if (storage_state == StorageState.AVAILABLE ||
361 storage_state == StorageState.NOT_AVAILABLE)
362 {
363 where.add ("(subj_storage_state=? OR subj_storage_state IS NULL)",
364 storage_state.to_string ());
365 }
366 else if (storage_state != StorageState.ANY)
367 {
368 throw new EngineError.INVALID_ARGUMENT(
369 "Unknown storage state '%u'".printf(storage_state));
370 }
371
372 WhereClause tpl_conditions = get_where_clause_from_event_templates (
373 event_templates);
374 where.extend (tpl_conditions);
375
376 return where;
377 }
378
364 private struct RelatedUri {379 private struct RelatedUri {
365 public uint32 id;380 public uint32 id;
366 public int64 timestamp;381 public int64 timestamp;
@@ -596,7 +611,7 @@
596 }611 }
597612
598 // Used by find_event_ids613 // Used by find_event_ids
599 protected WhereClause get_where_clause_from_event_templates (614 public WhereClause get_where_clause_from_event_templates (
600 GenericArray<Event> templates) throws EngineError615 GenericArray<Event> templates) throws EngineError
601 {616 {
602 WhereClause where = new WhereClause (WhereClause.Type.OR);617 WhereClause where = new WhereClause (WhereClause.Type.OR);

Subscribers

People subscribed via source and target branches