[epiphany/wip/sync] sync: Fix history migration being too slow
- From: Gabriel Ivașcu <gabrielivascu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [epiphany/wip/sync] sync: Fix history migration being too slow
- Date: Tue, 25 Jul 2017 15:04:10 +0000 (UTC)
commit c710b2785aafa87ea10e6a417122ee681559f1f1
Author: Gabriel Ivascu <ivascu gabriel59 gmail com>
Date: Tue Jul 25 17:34:43 2017 +0300
sync: Fix history migration being too slow
lib/history/ephy-history-service-urls-table.c | 5 ++-
lib/history/ephy-history-service.c | 8 ++++-
lib/sync/ephy-history-manager.c | 5 +++
src/profile-migrator/ephy-profile-migrator.c | 42 +------------------------
4 files changed, 16 insertions(+), 44 deletions(-)
---
diff --git a/lib/history/ephy-history-service-urls-table.c b/lib/history/ephy-history-service-urls-table.c
index 447e5b6..fa16806 100644
--- a/lib/history/ephy-history-service-urls-table.c
+++ b/lib/history/ephy-history-service-urls-table.c
@@ -175,7 +175,7 @@ ephy_history_service_update_url_row (EphyHistoryService *self, EphyHistoryURL *u
g_assert (self->history_database != NULL);
statement = ephy_sqlite_connection_create_statement (self->history_database,
- "UPDATE urls SET title=?, visit_count=?,
typed_count=?, last_visit_time=?, hidden_from_overview=?, thumbnail_update_time=? "
+ "UPDATE urls SET title=?, visit_count=?,
typed_count=?, last_visit_time=?, hidden_from_overview=?, thumbnail_update_time=?, sync_id=? "
"WHERE id=?", &error);
if (error) {
g_warning ("Could not build urls table modification statement: %s", error->message);
@@ -189,7 +189,8 @@ ephy_history_service_update_url_row (EphyHistoryService *self, EphyHistoryURL *u
ephy_sqlite_statement_bind_int64 (statement, 3, url->last_visit_time, &error) == FALSE ||
ephy_sqlite_statement_bind_int (statement, 4, url->hidden, &error) == FALSE ||
ephy_sqlite_statement_bind_int64 (statement, 5, url->thumbnail_time, &error) == FALSE ||
- ephy_sqlite_statement_bind_int (statement, 6, url->id, &error) == FALSE) {
+ ephy_sqlite_statement_bind_string (statement, 6, url->sync_id, &error) == FALSE ||
+ ephy_sqlite_statement_bind_int (statement, 7, url->id, &error) == FALSE) {
g_warning ("Could not modify URL in urls table: %s", error->message);
g_error_free (error);
g_object_unref (statement);
diff --git a/lib/history/ephy-history-service.c b/lib/history/ephy-history-service.c
index 7b95b37..27b562a 100644
--- a/lib/history/ephy-history-service.c
+++ b/lib/history/ephy-history-service.c
@@ -575,10 +575,13 @@ ephy_history_service_execute_add_visit_helper (EphyHistoryService *self, EphyHis
visit->url->host->visit_count++;
ephy_history_service_update_host_row (self, visit->url->host);
- /* A NULL return here means that the URL does not yet exist in the database */
+ /* A NULL return here means that the URL does not yet exist in the database.
+ * This overwrites visit->url so we have to test the sync id against NULL on
+ * both branches. */
if (ephy_history_service_get_url_row (self, visit->url->url, visit->url) == NULL) {
visit->url->last_visit_time = visit->visit_time;
visit->url->visit_count = 1;
+
if (!visit->url->sync_id)
visit->url->sync_id = ephy_sync_utils_get_random_sync_id ();
@@ -594,6 +597,9 @@ ephy_history_service_execute_add_visit_helper (EphyHistoryService *self, EphyHis
if (visit->visit_time > visit->url->last_visit_time)
visit->url->last_visit_time = visit->visit_time;
+ if (!visit->url->sync_id)
+ visit->url->sync_id = ephy_sync_utils_get_random_sync_id ();
+
ephy_history_service_update_url_row (self, visit->url);
}
diff --git a/lib/sync/ephy-history-manager.c b/lib/sync/ephy-history-manager.c
index 60d5452..1fb439d 100644
--- a/lib/sync/ephy-history-manager.c
+++ b/lib/sync/ephy-history-manager.c
@@ -494,6 +494,11 @@ merge_history_cb (EphyHistoryService *service,
for (GList *l = urls; l && l->data; l = l->next) {
EphyHistoryURL *url = (EphyHistoryURL *)l->data;
+
+ /* Ignore migrated history, i.e. URLs with a NULL id. */
+ if (!url->sync_id)
+ continue;
+
records = g_slist_prepend (records, ephy_history_record_new (url->sync_id,
url->title,
url->url,
diff --git a/src/profile-migrator/ephy-profile-migrator.c b/src/profile-migrator/ephy-profile-migrator.c
index 8a21265..adb8d26 100644
--- a/src/profile-migrator/ephy-profile-migrator.c
+++ b/src/profile-migrator/ephy-profile-migrator.c
@@ -1056,11 +1056,9 @@ migrate_history_to_firefox_sync_history (void)
{
EphySQLiteConnection *history_db = NULL;
EphySQLiteStatement *statement = NULL;
- GSList *ids = NULL;
GError *error = NULL;
char *history_filename;
const char *sql_query;
- int id;
history_filename = g_build_filename (ephy_dot_dir (), EPHY_HISTORY_FILE, NULL);
if (!g_file_test (history_filename, G_FILE_TEST_EXISTS)) {
@@ -1075,26 +1073,7 @@ migrate_history_to_firefox_sync_history (void)
goto out;
}
- /* Get the ID of each row in table. */
- sql_query = "SELECT DISTINCT urls.id FROM urls ORDER BY urls.id";
- statement = ephy_sqlite_connection_create_statement (history_db, sql_query, &error);
- if (error) {
- g_warning ("Failed to create SQLite statement: %s", error->message);
- goto out;
- }
-
- while (ephy_sqlite_statement_step (statement, &error)) {
- if (error) {
- g_warning ("Error in ephy_sqlite_statement_step: %s", error->message);
- g_error_free (error);
- error = NULL;
- } else {
- id = ephy_sqlite_statement_get_column_as_int (statement, 0);
- ids = g_slist_prepend (ids, GINT_TO_POINTER (id));
- }
- }
-
- /* Add new sync_id column. */
+ /* Add new sync_id column. All sync ids will default to NULL. */
sql_query = "ALTER TABLE urls ADD COLUMN sync_id LONGVARCAR";
ephy_sqlite_connection_execute (history_db, sql_query, &error);
if (error) {
@@ -1102,23 +1081,6 @@ migrate_history_to_firefox_sync_history (void)
goto out;
}
- /* Set sync_id for each row. */
- for (GSList *l = ids; l && l->data; l = l->next) {
- char *sync_id = ephy_sync_utils_get_random_sync_id ();
- char *sql = g_strdup_printf ("UPDATE urls SET sync_id = \"%s\" WHERE id=%d",
- sync_id, GPOINTER_TO_INT (l->data));
-
- ephy_sqlite_connection_execute (history_db, sql, &error);
- if (error) {
- g_warning ("Failed to set sync ID: %s", error->message);
- g_error_free (error);
- error = NULL;
- }
-
- g_free (sync_id);
- g_free (sql);
- }
-
/* Update visit timestamps to microseconds. */
sql_query = "UPDATE urls SET last_visit_time = last_visit_time * 1000000";
ephy_sqlite_connection_execute (history_db, sql_query, &error);
@@ -1138,8 +1100,6 @@ out:
g_object_unref (history_db);
if (statement)
g_object_unref (statement);
- if (ids)
- g_slist_free (ids);
if (error)
g_error_free (error);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]