aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/history/ephy-history-service-hosts-table.c25
-rw-r--r--lib/history/ephy-history-service-private.h1
-rw-r--r--lib/history/ephy-history-service.c1
3 files changed, 27 insertions, 0 deletions
diff --git a/lib/history/ephy-history-service-hosts-table.c b/lib/history/ephy-history-service-hosts-table.c
index 969154501..880a6392a 100644
--- a/lib/history/ephy-history-service-hosts-table.c
+++ b/lib/history/ephy-history-service-hosts-table.c
@@ -368,3 +368,28 @@ ephy_history_service_delete_host_row (EphyHistoryService *self,
}
g_object_unref (statement);
}
+
+void
+ephy_history_service_delete_orphan_hosts (EphyHistoryService *self)
+{
+ EphyHistoryServicePrivate *priv = EPHY_HISTORY_SERVICE (self)->priv;
+ GError *error = NULL;
+
+ g_assert (priv->history_thread == g_thread_self ());
+ g_assert (priv->history_database != NULL);
+
+ /* Where a JOIN would give us all hosts with urls associated, a LEFT
+ JOIN also gives us those hosts for which there are no urls. By
+ means of urls.host == NULL we filter out anything else and
+ retrieve only the ids of the hosts without associated urls. Then,
+ we delete all these rows from the hosts table. */
+ ephy_sqlite_connection_execute (priv->history_database,
+ "DELETE FROM hosts WHERE hosts.id IN "
+ " (SELECT hosts.id FROM hosts LEFT JOIN urls "
+ " ON hosts.id = urls.host WHERE urls.host is NULL);",
+ &error);
+ if (error) {
+ g_error ("Couldn't remove orphan hosts from database: %s", error->message);
+ g_error_free (error);
+ }
+}
diff --git a/lib/history/ephy-history-service-private.h b/lib/history/ephy-history-service-private.h
index b585d403d..08947701b 100644
--- a/lib/history/ephy-history-service-private.h
+++ b/lib/history/ephy-history-service-private.h
@@ -52,5 +52,6 @@ EphyHistoryHost * ephy_history_service_get_host_row (EphyHisto
GList * ephy_history_service_get_all_hosts (EphyHistoryService *self);
EphyHistoryHost * ephy_history_service_get_host_row_from_url (EphyHistoryService *self, const gchar *url);
void ephy_history_service_delete_host_row (EphyHistoryService *self, EphyHistoryHost *host);
+void ephy_history_service_delete_orphan_hosts (EphyHistoryService *self);
#endif /* EPHY_HISTORY_SERVICE_PRIVATE_H */
diff --git a/lib/history/ephy-history-service.c b/lib/history/ephy-history-service.c
index b6fc827ec..54af56a70 100644
--- a/lib/history/ephy-history-service.c
+++ b/lib/history/ephy-history-service.c
@@ -788,6 +788,7 @@ ephy_history_service_execute_delete_urls (EphyHistoryService *self,
ephy_history_service_delete_url (self, url);
}
+ ephy_history_service_delete_orphan_hosts (self);
ephy_history_service_schedule_commit (self);
return TRUE;