[epiphany] history-service: do not join urls and visits table unnecessarily



commit 54e7023ac883f7eb1f714eaacd28c5766eb25c66
Author: Claudio Saavedra <csaavedra igalia com>
Date:   Wed Jan 11 14:59:57 2012 +0200

    history-service: do not join urls and visits table unnecessarily
    
    If there is no visit time range there is no need to perform a inner
    join between these two tables, so spare the hassle.

 lib/history/ephy-history-service-urls-table.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
---
diff --git a/lib/history/ephy-history-service-urls-table.c b/lib/history/ephy-history-service-urls-table.c
index c11713b..de0d516 100644
--- a/lib/history/ephy-history-service-urls-table.c
+++ b/lib/history/ephy-history-service-urls-table.c
@@ -238,8 +238,7 @@ ephy_history_service_find_url_rows (EphyHistoryService *self, EphyHistoryQuery *
       "urls.zoom_level, "
       "urls.host "
     "FROM "
-      "urls JOIN visits ON visits.url = urls.id "
-    "WHERE ";
+      "urls ";
 
   int i = 0;
 
@@ -248,10 +247,15 @@ ephy_history_service_find_url_rows (EphyHistoryService *self, EphyHistoryQuery *
 
   statement_str = g_string_new (base_statement);
 
-  if (query->from > 0)
-    statement_str = g_string_append (statement_str, "visits.visit_time >= ? AND ");
-  if (query->to > 0)
-    statement_str = g_string_append (statement_str, "visits.visit_time <= ? AND ");
+  if (query->from > 0 || query->to > 0) {
+    statement_str = g_string_append (statement_str, "JOIN visits ON visits.url = urls.id WHERE ");
+    if (query->from > 0)
+      statement_str = g_string_append (statement_str, "visits.visit_time >= ? AND ");
+    if (query->to > 0)
+      statement_str = g_string_append (statement_str, "visits.visit_time <= ? AND ");
+  } else {
+    statement_str = g_string_append (statement_str, "WHERE ");
+  }
 
   for (substring = query->substring_list; substring != NULL; substring = substring->next)
     statement_str = g_string_append (statement_str, "(urls.url LIKE ? OR urls.title LIKE ?) AND ");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]