From 54e7023ac883f7eb1f714eaacd28c5766eb25c66 Mon Sep 17 00:00:00 2001 From: Claudio Saavedra Date: Wed, 11 Jan 2012 14:59:57 +0200 Subject: 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 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/history') diff --git a/lib/history/ephy-history-service-urls-table.c b/lib/history/ephy-history-service-urls-table.c index c11713b93..de0d516ac 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 "); -- cgit v1.2.3