summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSeif Lotfy <seif@lotfy.com>2013-01-02 03:18:21 +0100
committerSeif Lotfy <seif@lotfy.com>2013-01-02 03:22:45 +0100
commit4061a6cdc04664d7fe265b1ba6960e685ac20331 (patch)
tree6f75dd572c93367cbf6eed472d44aa40f523ebc8 /src
parent6c6bb27da8d3e3ecfdcf2e2bfa14e21f1a420615 (diff)
downloadzeitgeist-4061a6cdc04664d7fe265b1ba6960e685ac20331.tar.gz
Add optimized queries and fix broken has_non_timestamp_condition method
Diffstat (limited to 'src')
-rw-r--r--src/db-reader.vala29
-rw-r--r--src/where-clause.vala1
2 files changed, 14 insertions, 16 deletions
diff --git a/src/db-reader.vala b/src/db-reader.vala
index 1a461f69..9e67cd0e 100644
--- a/src/db-reader.vala
+++ b/src/db-reader.vala
@@ -596,27 +596,13 @@ public class DbReader : Object
string aggregation_sql = "";
string order_sql = "";
string where_sql = where.get_sql_conditions ();
-
if (count_asc != null)
{
aggregation_sql = ", COUNT(%s) AS num_events".printf (field);
order_sql = "num_events %s,".printf ((count_asc) ? "ASC" : "DESC");
}
- if (where.has_non_timestamp_condition())
- return """
- SELECT id, %s(timestamp) AS timestamp
- %s
- FROM event_view WHERE %s AND %s IS NOT NULL
- GROUP BY %s
- ORDER BY %s
- """.printf (
- aggregation_type,
- aggregation_sql,
- where_sql,
- field,
- field,
- order_sql);
- else
+ if (count_asc != null || !where.has_non_timestamp_condition())
+ {
return """
SELECT id FROM event
NATURAL JOIN (
@@ -635,6 +621,17 @@ public class DbReader : Object
field,
field,
order_sql);
+ }
+ return """
+ SELECT id, %s(timestamp) AS timestamp
+ FROM event_view WHERE %s AND %s IS NOT NULL
+ GROUP BY %s
+ ORDER BY
+ """.printf (
+ aggregation_type,
+ where_sql,
+ field,
+ field);
}
// Used by find_event_ids
diff --git a/src/where-clause.vala b/src/where-clause.vala
index e08d217d..a8305995 100644
--- a/src/where-clause.vala
+++ b/src/where-clause.vala
@@ -73,6 +73,7 @@ namespace Zeitgeist
public bool has_non_timestamp_condition() {
for (int i=0; i<conditions.length; i++) {
+ if (!conditions[i].has_prefix("timestamp"))
return true;
}
return false;