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
1=== modified file 'src/db-reader.vala'
2--- src/db-reader.vala 2012-02-05 14:52:13 +0000
3+++ src/db-reader.vala 2012-03-13 18:56:18 +0000
4@@ -160,47 +160,9 @@
5 return results;
6 }
7
8- public uint32[] find_event_ids (TimeRange time_range,
9- GenericArray<Event> event_templates,
10- uint storage_state, uint max_events, uint result_type,
11- BusName? sender=null) throws EngineError
12+ public uint32[] find_event_ids_for_clause (WhereClause where,
13+ uint max_events, uint result_type) throws EngineError
14 {
15-
16- WhereClause where = new WhereClause (WhereClause.Type.AND);
17-
18- /**
19- * We are using the unary operator here to tell SQLite to not use
20- * the index on the timestamp column at the first place. This is a
21- * "fix" for (LP: #672965) based on some benchmarks, which suggest
22- * a performance win, but we might not oversee all implications.
23- * (See http://www.sqlite.org/optoverview.html, section 6.0).
24- * -- Markus Korn, 29/11/2010
25- */
26- if (time_range.start != 0)
27- where.add (("+timestamp >= %" + int64.FORMAT).printf(
28- time_range.start));
29- if (time_range.end != 0)
30- where.add (("+timestamp <= %" + int64.FORMAT).printf(
31- time_range.end));
32-
33- if (storage_state == StorageState.AVAILABLE ||
34- storage_state == StorageState.NOT_AVAILABLE)
35- {
36- where.add ("(subj_storage_state=? OR subj_storage_state IS NULL)",
37- storage_state.to_string ());
38- }
39- else if (storage_state != StorageState.ANY)
40- {
41- throw new EngineError.INVALID_ARGUMENT(
42- "Unknown storage state '%u'".printf(storage_state));
43- }
44-
45- WhereClause tpl_conditions = get_where_clause_from_event_templates (
46- event_templates);
47- where.extend (tpl_conditions);
48- //if (!where.may_have_results ())
49- // return new uint32[0];
50-
51 string sql = "SELECT id FROM event_view ";
52 string where_sql = "";
53 if (!where.is_empty ())
54@@ -352,6 +314,20 @@
55 return event_ids;
56 }
57
58+ public uint32[] find_event_ids (TimeRange time_range,
59+ GenericArray<Event> event_templates,
60+ uint storage_state, uint max_events, uint result_type,
61+ BusName? sender=null) throws EngineError
62+ {
63+ WhereClause where = get_where_clause_for_query (time_range,
64+ event_templates, storage_state);
65+
66+ //if (!where.may_have_results ())
67+ // return new uint32[0];
68+
69+ return find_event_ids_for_clause (where, max_events, result_type);
70+ }
71+
72 public GenericArray<Event?> find_events (TimeRange time_range,
73 GenericArray<Event> event_templates,
74 uint storage_state, uint max_events, uint result_type,
75@@ -361,6 +337,45 @@
76 storage_state, max_events, result_type));
77 }
78
79+ public WhereClause get_where_clause_for_query (TimeRange time_range,
80+ GenericArray<Event> event_templates, uint storage_state) throws EngineError
81+ {
82+ WhereClause where = new WhereClause (WhereClause.Type.AND);
83+
84+ /**
85+ * We are using the unary operator here to tell SQLite to not use
86+ * the index on the timestamp column at the first place. This is a
87+ * "fix" for (LP: #672965) based on some benchmarks, which suggest
88+ * a performance win, but we might not oversee all implications.
89+ * (See http://www.sqlite.org/optoverview.html, section 6.0).
90+ * -- Markus Korn, 29/11/2010
91+ */
92+ if (time_range.start != 0)
93+ where.add (("+timestamp >= %" + int64.FORMAT).printf(
94+ time_range.start));
95+ if (time_range.end != 0)
96+ where.add (("+timestamp <= %" + int64.FORMAT).printf(
97+ time_range.end));
98+
99+ if (storage_state == StorageState.AVAILABLE ||
100+ storage_state == StorageState.NOT_AVAILABLE)
101+ {
102+ where.add ("(subj_storage_state=? OR subj_storage_state IS NULL)",
103+ storage_state.to_string ());
104+ }
105+ else if (storage_state != StorageState.ANY)
106+ {
107+ throw new EngineError.INVALID_ARGUMENT(
108+ "Unknown storage state '%u'".printf(storage_state));
109+ }
110+
111+ WhereClause tpl_conditions = get_where_clause_from_event_templates (
112+ event_templates);
113+ where.extend (tpl_conditions);
114+
115+ return where;
116+ }
117+
118 private struct RelatedUri {
119 public uint32 id;
120 public int64 timestamp;
121@@ -596,7 +611,7 @@
122 }
123
124 // Used by find_event_ids
125- protected WhereClause get_where_clause_from_event_templates (
126+ public WhereClause get_where_clause_from_event_templates (
127 GenericArray<Event> templates) throws EngineError
128 {
129 WhereClause where = new WhereClause (WhereClause.Type.OR);

Subscribers

People subscribed via source and target branches