From 16c4f8d2aebcdc710aadd07e7d44a8b08ea1342f Mon Sep 17 00:00:00 2001 From: Marco Bonardo Date: Mon, 9 Aug 2010 17:59:59 +0200 Subject: [PATCH] Bug 552023 - Kill Places partitioned temp tables. r=sdwilsh a=blocking --- .../test/browser_tabMatchesInAwesomebar.js | 5 +- browser/components/nsBrowserGlue.js | 5 +- .../tests/unit/test_clearHistory_shutdown.js | 4 +- browser/installer/package-manifest.in | 1 - browser/installer/removed-files.in | 1 + docshell/test/bug94514-postpage.html | 2 +- docshell/test/test_bug94514.html | 18 + toolkit/components/places/src/Makefile.in | 1 - .../components/places/src/PlacesDBUtils.jsm | 21 +- toolkit/components/places/src/PlacesUtils.jsm | 1 - .../places/src/nsAnnotationService.cpp | 72 +- .../places/src/nsFaviconService.cpp | 41 +- .../components/places/src/nsFaviconService.h | 1 - .../components/places/src/nsNavBookmarks.cpp | 79 +- .../components/places/src/nsNavHistory.cpp | 887 +++++------------- toolkit/components/places/src/nsNavHistory.h | 4 +- .../places/src/nsPlacesAutoComplete.js | 170 ++-- .../components/places/src/nsPlacesDBFlush.js | 399 -------- .../places/src/nsPlacesExpiration.js | 75 +- .../components/places/src/nsPlacesIndexes.h | 36 - .../components/places/src/nsPlacesTables.h | 31 +- .../components/places/src/nsPlacesTriggers.h | 193 +--- .../places/src/toolkitplaces.manifest | 6 - toolkit/components/places/tests/Makefile.in | 1 - ...st_autocomplete_on_value_removed_479089.js | 2 +- .../places/tests/browser/browser_settitle.js | 2 - .../places/tests/browser/browser_visituri.js | 2 - .../places/tests/cpp/places_test_harness.h | 11 +- .../expiration/test_annos_expire_policy.js | 2 +- .../tests/expiration/test_removeAllPages.js | 2 +- .../components/places/tests/head_common.js | 31 - .../tests/mochitest/bug_411966/redirect.js | 8 +- .../tests/network/test_history_redirects.js | 4 +- .../places/tests/queries/head_queries.js | 4 +- .../places/tests/queries/test_transitions.js | 6 +- .../components/places/tests/sync/head_sync.js | 136 --- .../sync/test_bookmarks_sorted_by_none.js | 126 --- .../test_database_sync_after_addBookmark.js | 89 -- ...database_sync_after_addBookmark_batched.js | 110 --- .../sync/test_database_sync_after_addVisit.js | 96 -- ...st_database_sync_after_addVisit_batched.js | 109 --- ...test_database_sync_after_modifyBookmark.js | 109 --- .../sync/test_database_sync_after_shutdown.js | 95 -- ...sync_after_shutdown_with_removeAllPages.js | 164 ---- .../sync/test_database_sync_embed_visits.js | 173 ---- .../test_database_sync_expireAllFavicons.js | 134 --- .../sync/test_database_sync_onitemadded.js | 108 --- ...atabase_sync_with_specialHistoryQueries.js | 116 --- .../test_multiple_bookmarks_around_sync.js | 150 --- .../sync/test_multiple_visits_around_sync.js | 152 --- .../places/tests/unit/test_248970.js | 35 +- .../places/tests/unit/test_412132.js | 4 +- .../places/tests/unit/test_454977.js | 2 +- ...est_doSetAndLoadFaviconForPage_failures.js | 4 +- .../tests/unit/test_history_removeAllPages.js | 201 ++-- .../places/tests/unit/test_migrateFrecency.js | 2 +- .../unit/test_removeVisitsByTimeframe.js | 4 +- .../unit/test_update_frecency_after_delete.js | 2 +- 58 files changed, 513 insertions(+), 3736 deletions(-) delete mode 100644 toolkit/components/places/src/nsPlacesDBFlush.js delete mode 100644 toolkit/components/places/tests/sync/head_sync.js delete mode 100644 toolkit/components/places/tests/sync/test_bookmarks_sorted_by_none.js delete mode 100644 toolkit/components/places/tests/sync/test_database_sync_after_addBookmark.js delete mode 100644 toolkit/components/places/tests/sync/test_database_sync_after_addBookmark_batched.js delete mode 100644 toolkit/components/places/tests/sync/test_database_sync_after_addVisit.js delete mode 100644 toolkit/components/places/tests/sync/test_database_sync_after_addVisit_batched.js delete mode 100644 toolkit/components/places/tests/sync/test_database_sync_after_modifyBookmark.js delete mode 100644 toolkit/components/places/tests/sync/test_database_sync_after_shutdown.js delete mode 100644 toolkit/components/places/tests/sync/test_database_sync_after_shutdown_with_removeAllPages.js delete mode 100644 toolkit/components/places/tests/sync/test_database_sync_embed_visits.js delete mode 100644 toolkit/components/places/tests/sync/test_database_sync_expireAllFavicons.js delete mode 100644 toolkit/components/places/tests/sync/test_database_sync_onitemadded.js delete mode 100644 toolkit/components/places/tests/sync/test_database_sync_with_specialHistoryQueries.js delete mode 100644 toolkit/components/places/tests/sync/test_multiple_bookmarks_around_sync.js delete mode 100644 toolkit/components/places/tests/sync/test_multiple_visits_around_sync.js diff --git a/browser/base/content/test/browser_tabMatchesInAwesomebar.js b/browser/base/content/test/browser_tabMatchesInAwesomebar.js index ea32f606d02..393f1574004 100644 --- a/browser/base/content/test/browser_tabMatchesInAwesomebar.js +++ b/browser/base/content/test/browser_tabMatchesInAwesomebar.js @@ -191,10 +191,9 @@ function ensure_opentabs_match_db() { try { var stmt = db.createStatement( - "SELECT IFNULL(p_t.url, p.url) AS url, open_count, place_id " + + "SELECT p.url AS url, open_count, place_id " + "FROM moz_openpages_temp " + - "LEFT JOIN moz_places p ON p.id=place_id " + - "LEFT JOIN moz_places_temp p_t ON p_t.id=place_id"); + "LEFT JOIN moz_places p ON p.id = place_id"); } catch (e) { ok(false, "error creating db statement: " + e); return; diff --git a/browser/components/nsBrowserGlue.js b/browser/components/nsBrowserGlue.js index 0ca39bf8437..a5652b34339 100644 --- a/browser/components/nsBrowserGlue.js +++ b/browser/components/nsBrowserGlue.js @@ -356,10 +356,7 @@ BrowserGlue.prototype = { } // Load the "more info" page for a locked places.sqlite - // This property is set earlier in the startup process: - // nsPlacesDBFlush loads after profile-after-change and initializes - // the history service, which sends out places-database-locked - // which sets this property. + // This property is set earlier by places-database-locked topic. if (this._isPlacesDatabaseLocked) { this._showPlacesLockedNotificationBox(); } diff --git a/browser/components/places/tests/unit/test_clearHistory_shutdown.js b/browser/components/places/tests/unit/test_clearHistory_shutdown.js index 3ad83b0c1e3..0f08e16f89a 100644 --- a/browser/components/places/tests/unit/test_clearHistory_shutdown.js +++ b/browser/components/places/tests/unit/test_clearHistory_shutdown.js @@ -58,9 +58,7 @@ let expirationObserver = { .DBConnection; let stmt = db.createStatement( - "SELECT id FROM moz_places_temp WHERE url = :page_url " - + "UNION ALL " - + "SELECT id FROM moz_places WHERE url = :page_url " + "SELECT id FROM moz_places WHERE url = :page_url " ); try { diff --git a/browser/installer/package-manifest.in b/browser/installer/package-manifest.in index f103aada2c6..560bee59636 100644 --- a/browser/installer/package-manifest.in +++ b/browser/installer/package-manifest.in @@ -342,7 +342,6 @@ @BINPATH@/components/toolkitplaces.manifest @BINPATH@/components/nsLivemarkService.js @BINPATH@/components/nsTaggingService.js -@BINPATH@/components/nsPlacesDBFlush.js @BINPATH@/components/nsPlacesAutoComplete.manifest @BINPATH@/components/nsPlacesAutoComplete.js @BINPATH@/components/nsPlacesExpiration.js diff --git a/browser/installer/removed-files.in b/browser/installer/removed-files.in index 2873a1cadef..f5576f79001 100644 --- a/browser/installer/removed-files.in +++ b/browser/installer/removed-files.in @@ -864,3 +864,4 @@ extensions/inspector@mozilla.org/components/@DLL_PREFIX@inspector@DLL_SUFFIX@ extensions/inspector@mozilla.org/chrome/icons/default/winInspectorMain.ico components/nsPlacesTransactionsService.js components/browserplaces.xpt +components/nsPlacesDBFlush.js diff --git a/docshell/test/bug94514-postpage.html b/docshell/test/bug94514-postpage.html index 10b418e4598..9e99c0ea4fd 100644 --- a/docshell/test/bug94514-postpage.html +++ b/docshell/test/bug94514-postpage.html @@ -22,7 +22,7 @@ if (!window.location.href.match("posted=1")) { form.action = window.location.href + "?posted=1"; form.submit(); } else { - window.opener.finishTest(); + window.location.href = "http://mochi.test:8888/tests/docshell/test/bug94514-postpage.html"; } diff --git a/docshell/test/test_bug94514.html b/docshell/test/test_bug94514.html index 7a7a6b4e296..4de4534c453 100644 --- a/docshell/test/test_bug94514.html +++ b/docshell/test/test_bug94514.html @@ -44,6 +44,24 @@ SimpleTest.ok(!gh.isVisited(startPage), SimpleTest.ok(!gh.isVisited(postedPage), "Posted page does not start in global history."); +// Because adding visits is async, we will not be notified imemdiately. +var os = Cc["@mozilla.org/observer-service;1"]. + getService(Ci.nsIObserverService); +var visitObserver = { + _visitCount: 0, + observe: function(aSubject, aTopic, aData) + { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + if (!startPage.equals(aSubject.QueryInterface(Ci.nsIURI)) || + ++this._visitCount < 2) { + return; + } + os.removeObserver(this, aTopic, false); + finishTest(); + }, +}; +os.addObserver(visitObserver, "uri-visit-saved", false); + var w = window.open(startURI, "", "width=10,height=10"); function finishTest() diff --git a/toolkit/components/places/src/Makefile.in b/toolkit/components/places/src/Makefile.in index 7cc1047eb92..c617985dfc9 100644 --- a/toolkit/components/places/src/Makefile.in +++ b/toolkit/components/places/src/Makefile.in @@ -86,7 +86,6 @@ EXTRA_COMPONENTS = \ toolkitplaces.manifest \ nsLivemarkService.js \ nsTaggingService.js \ - nsPlacesDBFlush.js \ nsPlacesExpiration.js \ nsMicrosummaryService.js \ $(NULL) diff --git a/toolkit/components/places/src/PlacesDBUtils.jsm b/toolkit/components/places/src/PlacesDBUtils.jsm index 849b443055d..6889e3b13d1 100644 --- a/toolkit/components/places/src/PlacesDBUtils.jsm +++ b/toolkit/components/places/src/PlacesDBUtils.jsm @@ -212,8 +212,6 @@ nsPlacesDBUtils.prototype = { "DELETE FROM moz_annos WHERE id IN ( " + "SELECT id FROM moz_annos a " + "WHERE NOT EXISTS " + - "(SELECT id FROM moz_places_temp WHERE id = a.place_id LIMIT 1) " + - "AND NOT EXISTS " + "(SELECT id FROM moz_places WHERE id = a.place_id LIMIT 1) " + ")"); cleanupStatements.push(deleteOrphanAnnos); @@ -288,7 +286,6 @@ nsPlacesDBUtils.prototype = { ") AND id IN (" + "SELECT b.id FROM moz_bookmarks b " + "WHERE fk NOT NULL AND b.type = :bookmark_type " + - "AND NOT EXISTS (SELECT url FROM moz_places_temp WHERE id = b.fk LIMIT 1) " + "AND NOT EXISTS (SELECT url FROM moz_places WHERE id = b.fk LIMIT 1) " + ")"); deleteNoPlaceItems.params["bookmark_type"] = this._bms.TYPE_BOOKMARK; @@ -447,7 +444,6 @@ nsPlacesDBUtils.prototype = { // D.11 remove old livemarks status items // Livemark status items are now static but some livemark has still old // status items bookmarks inside it. We should remove them. - // Note: This does not need to query the temp table. let removeLivemarkStaticItems = this._dbConn.createStatement( "DELETE FROM moz_bookmarks WHERE type = :bookmark_type AND fk IN ( " + "SELECT id FROM moz_places WHERE url = :lmloading OR url = :lmfailed " + @@ -463,8 +459,6 @@ nsPlacesDBUtils.prototype = { "DELETE FROM moz_favicons WHERE id IN (" + "SELECT id FROM moz_favicons f " + "WHERE NOT EXISTS " + - "(SELECT id FROM moz_places_temp WHERE favicon_id = f.id LIMIT 1) " + - "AND NOT EXISTS" + "(SELECT id FROM moz_places WHERE favicon_id = f.id LIMIT 1) " + ")"); cleanupStatements.push(deleteOrphanIcons); @@ -475,8 +469,6 @@ nsPlacesDBUtils.prototype = { "DELETE FROM moz_historyvisits WHERE id IN (" + "SELECT id FROM moz_historyvisits v " + "WHERE NOT EXISTS " + - "(SELECT id FROM moz_places_temp WHERE id = v.place_id LIMIT 1) " + - "AND NOT EXISTS " + "(SELECT id FROM moz_places WHERE id = v.place_id LIMIT 1) " + ")"); cleanupStatements.push(deleteOrphanVisits); @@ -487,8 +479,6 @@ nsPlacesDBUtils.prototype = { "DELETE FROM moz_inputhistory WHERE place_id IN (" + "SELECT place_id FROM moz_inputhistory i " + "WHERE NOT EXISTS " + - "(SELECT id FROM moz_places_temp WHERE id = i.place_id LIMIT 1) " + - "AND NOT EXISTS " + "(SELECT id FROM moz_places WHERE id = i.place_id LIMIT 1) " + ")"); cleanupStatements.push(deleteOrphanInputHistory); @@ -536,22 +526,17 @@ nsPlacesDBUtils.prototype = { /* XXX needs test // L.2 recalculate visit_count - // We're detecting errors only in disk table since temp tables could have - // different values based on the number of visits not yet synced to disk. let detectWrongCountPlaces = this._dbConn.createStatement( "SELECT id FROM moz_places h " + - "WHERE id NOT IN (SELECT id FROM moz_places_temp) " + - "AND h.visit_count <> " + + "WHERE h.visit_count <> " + "(SELECT count(*) FROM moz_historyvisits " + "WHERE place_id = h.id AND visit_type NOT IN (0,4,7,8))"); while (detectWrongCountPlaces.executeStep()) { let placeId = detectWrongCountPlaces.getInt64(0); let fixCountForPlace = this._dbConn.createStatement( - "UPDATE moz_places_view SET visit_count = ( " + + "UPDATE moz_places SET visit_count = ( " + "(SELECT count(*) FROM moz_historyvisits " + - "WHERE place_id = :place_id AND visit_type NOT IN (0,4,7,8)) + " + - "(SELECT count(*) FROM moz_historyvisits_temp " + - "WHERE place_id = :place_id AND visit_type NOT IN (0,4,7,8)) + " + + "WHERE place_id = :place_id AND visit_type NOT IN (0,4,7,8)) + " ") WHERE id = :place_id"); fixCountForPlace.params["place_id"] = placeId; cleanupStatements.push(fixCountForPlace); diff --git a/toolkit/components/places/src/PlacesUtils.jsm b/toolkit/components/places/src/PlacesUtils.jsm index 0541c7bc6c4..ca48e465850 100644 --- a/toolkit/components/places/src/PlacesUtils.jsm +++ b/toolkit/components/places/src/PlacesUtils.jsm @@ -150,7 +150,6 @@ var PlacesUtils = { TOPIC_DATABASE_LOCKED: "places-database-locked", TOPIC_EXPIRATION_FINISHED: "places-expiration-finished", TOPIC_FEEDBACK_UPDATED: "places-autocomplete-feedback-updated", - TOPIC_SYNC_FINISHED: "places-sync-finished", TOPIC_FAVICONS_EXPIRED: "places-favicons-expired", TOPIC_VACUUM_STARTING: "places-vacuum-starting", diff --git a/toolkit/components/places/src/nsAnnotationService.cpp b/toolkit/components/places/src/nsAnnotationService.cpp index 5feaf273bf7..994d8b4e325 100644 --- a/toolkit/components/places/src/nsAnnotationService.cpp +++ b/toolkit/components/places/src/nsAnnotationService.cpp @@ -136,23 +136,17 @@ nsAnnotationService::GetStatement(const nsCOMPtr& aStmt) "SELECT n.name " "FROM moz_anno_attributes n " "JOIN moz_annos a ON a.anno_attribute_id = n.id " - "JOIN ( " - "SELECT id FROM moz_places_temp WHERE url = :page_url " - "UNION " - "SELECT id FROM moz_places WHERE url = :page_url " - ") AS h ON h.id = a.place_id")); + "JOIN moz_places h ON h.id = a.place_id " + "WHERE h.url = :page_url")); RETURN_IF_STMT(mDBGetPageAnnotationValue, NS_LITERAL_CSTRING( "SELECT a.id, a.place_id, :anno_name, a.mime_type, a.content, a.flags, " "a.expiration, a.type " "FROM moz_anno_attributes n " "JOIN moz_annos a ON n.id = a.anno_attribute_id " - "JOIN ( " - "SELECT id FROM moz_places_temp WHERE url = :page_url " - "UNION " - "SELECT id FROM moz_places WHERE url = :page_url " - ") AS h ON h.id = a.place_id " - "WHERE n.name = :anno_name")); + "JOIN moz_places h ON h.id = a.place_id " + "WHERE h.url = :page_url " + "AND n.name = :anno_name")); RETURN_IF_STMT(mDBGetItemAnnotationValue, NS_LITERAL_CSTRING( "SELECT a.id, a.item_id, :anno_name, a.mime_type, a.content, a.flags, " @@ -181,26 +175,22 @@ nsAnnotationService::GetStatement(const nsCOMPtr& aStmt) RETURN_IF_STMT(mDBRemovePageAnnotation, NS_LITERAL_CSTRING( "DELETE FROM moz_annos " - "WHERE place_id = ( " - "SELECT id FROM moz_places_temp WHERE url = :page_url " - "UNION " - "SELECT id FROM moz_places WHERE url = :page_url) " - "AND anno_attribute_id = " - "(SELECT id FROM moz_anno_attributes WHERE name = :anno_name)")); + "WHERE place_id = (SELECT id FROM moz_places WHERE url = :page_url) " + "AND anno_attribute_id = " + "(SELECT id FROM moz_anno_attributes WHERE name = :anno_name)")); RETURN_IF_STMT(mDBRemoveItemAnnotation, NS_LITERAL_CSTRING( "DELETE FROM moz_items_annos " "WHERE item_id = :item_id " - "AND anno_attribute_id = " - "(SELECT id FROM moz_anno_attributes WHERE name = :anno_name)")); + "AND anno_attribute_id = " + "(SELECT id FROM moz_anno_attributes WHERE name = :anno_name)")); RETURN_IF_STMT(mDBGetPagesWithAnnotation, NS_LITERAL_CSTRING( - "SELECT IFNULL(h_t.url, h.url) AS coalesced_url " + "SELECT h.url " "FROM moz_anno_attributes n " "JOIN moz_annos a ON n.id = a.anno_attribute_id " - "LEFT JOIN moz_places h ON h.id = a.place_id " - "LEFT JOIN moz_places_temp h_t ON h_t.id = a.place_id " - "WHERE n.name = :anno_name AND coalesced_url NOT NULL")); + "JOIN moz_places h ON h.id = a.place_id " + "WHERE n.name = :anno_name")); RETURN_IF_STMT(mDBGetItemsWithAnnotation, NS_LITERAL_CSTRING( "SELECT a.item_id " @@ -212,12 +202,10 @@ nsAnnotationService::GetStatement(const nsCOMPtr& aStmt) "SELECT h.id, " "(SELECT id FROM moz_anno_attributes WHERE name = :anno_name) AS nameid, " "a.id, a.dateAdded " - "FROM (SELECT id FROM moz_places_temp WHERE url = :page_url " - "UNION " - "SELECT id FROM moz_places WHERE url = :page_url " - ") AS h " + "FROM moz_places h " "LEFT JOIN moz_annos a ON a.place_id = h.id " - "AND a.anno_attribute_id = nameid")); + "AND a.anno_attribute_id = nameid " + "WHERE h.url = :page_url")); RETURN_IF_STMT(mDBCheckItemAnnotation, NS_LITERAL_CSTRING( "SELECT b.id, " @@ -1582,9 +1570,7 @@ nsAnnotationService::RemovePageAnnotations(nsIURI* aURI) nsCOMPtr statement; nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( "DELETE FROM moz_annos WHERE place_id = " - "(SELECT id FROM moz_places_temp WHERE url = :page_url " - "UNION " - "SELECT id FROM moz_places WHERE url = :page_url)"), + "(SELECT id FROM moz_places WHERE url = :page_url)"), getter_AddRefs(statement)); NS_ENSURE_SUCCESS(rv, rv); rv = URIBinder::Bind(statement, NS_LITERAL_CSTRING("page_url"), aURI); @@ -1644,18 +1630,13 @@ nsAnnotationService::CopyPageAnnotations(nsIURI* aSourceURI, nsCOMPtr sourceStmt; nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( "SELECT h.id, n.id, n.name, a2.id " - "FROM ( " - "SELECT id from moz_places_temp WHERE url = :source_url " - "UNION " - "SELECT id FROM moz_places WHERE url = :source_url " - ") AS h " + "FROM moz_places h " "JOIN moz_annos a ON a.place_id = h.id " "JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id " - "LEFT JOIN moz_annos a2 ON a2.place_id = ( " - "SELECT id FROM moz_places_temp WHERE url = :dest_url " - "UNION " - "SELECT id FROM moz_places WHERE url = :dest_url " - ") AND a2.anno_attribute_id = n.id"), + "LEFT JOIN moz_annos a2 ON a2.place_id = " + "(SELECT id FROM moz_places WHERE url = :dest_url) " + "AND a2.anno_attribute_id = n.id " + "WHERE url = :source_url"), getter_AddRefs(sourceStmt)); NS_ENSURE_SUCCESS(rv, rv); @@ -1669,12 +1650,9 @@ nsAnnotationService::CopyPageAnnotations(nsIURI* aSourceURI, "INSERT INTO moz_annos " "(place_id, anno_attribute_id, mime_type, content, flags, expiration, " "type, dateAdded, lastModified) " - "SELECT ( " - "SELECT id FROM moz_places_temp WHERE url = :page_url " - "UNION " - "SELECT id FROM moz_places WHERE url = :page_url " - "), anno_attribute_id, mime_type, content, flags, expiration, type, " - ":date, :date " + "SELECT (SELECT id FROM moz_places WHERE url = :page_url), " + "anno_attribute_id, mime_type, content, flags, expiration, type, " + ":date, :date " "FROM moz_annos " "WHERE place_id = :page_id " "AND anno_attribute_id = :name_id"), diff --git a/toolkit/components/places/src/nsFaviconService.cpp b/toolkit/components/places/src/nsFaviconService.cpp index f824802bdf9..021dd02f68c 100644 --- a/toolkit/components/places/src/nsFaviconService.cpp +++ b/toolkit/components/places/src/nsFaviconService.cpp @@ -171,30 +171,20 @@ nsFaviconService::GetStatement(const nsCOMPtr& aStmt) RETURN_IF_STMT(mDBGetIconInfoWithPage, NS_LITERAL_CSTRING( "SELECT id, length(data), expiration, data, mime_type, " "IFNULL(url = (SELECT f.url " - "FROM ( " - "SELECT favicon_id FROM moz_places_temp " - "WHERE url = :page_url " - "UNION ALL " - "SELECT favicon_id FROM moz_places " - "WHERE url = :page_url " - ") AS h " + "FROM moz_places h " "JOIN moz_favicons f ON h.favicon_id = f.id " + "WHERE h.url = :page_url " "LIMIT 1), " - "0)" + "0) " "FROM moz_favicons WHERE url = :icon_url")); RETURN_IF_STMT(mDBGetURL, NS_LITERAL_CSTRING( "SELECT f.id, f.url, length(f.data), f.expiration " - "FROM ( " - "SELECT " MOZ_PLACES_COLUMNS " FROM moz_places_temp " - "WHERE url = :page_url " - "UNION ALL " - "SELECT " MOZ_PLACES_COLUMNS " FROM moz_places " - "WHERE url = :page_url " - ") AS h JOIN moz_favicons f ON h.favicon_id = f.id " + "FROM moz_places h " + "JOIN moz_favicons f ON h.favicon_id = f.id " + "WHERE h.url = :page_url " "LIMIT 1")); - RETURN_IF_STMT(mDBGetData, NS_LITERAL_CSTRING( "SELECT f.data, f.mime_type FROM moz_favicons f WHERE url = :icon_url")); @@ -208,10 +198,10 @@ nsFaviconService::GetStatement(const nsCOMPtr& aStmt) "WHERE id = :icon_id")); RETURN_IF_STMT(mDBSetPageFavicon, NS_LITERAL_CSTRING( - "UPDATE moz_places_view SET favicon_id = :icon_id WHERE id = :page_id")); + "UPDATE moz_places SET favicon_id = :icon_id WHERE id = :page_id")); RETURN_IF_STMT(mDBAssociateFaviconURIToPageURI, NS_LITERAL_CSTRING( - "UPDATE moz_places_view " + "UPDATE moz_places " "SET favicon_id = (SELECT id FROM moz_favicons WHERE url = :icon_url) " "WHERE url = :page_url")); @@ -220,15 +210,8 @@ nsFaviconService::GetStatement(const nsCOMPtr& aStmt) "SET favicon_id = NULL " "WHERE favicon_id NOT NULL")); - RETURN_IF_STMT(mDBRemoveTempReferences, NS_LITERAL_CSTRING( - "UPDATE moz_places_temp " - "SET favicon_id = NULL " - "WHERE favicon_id NOT NULL")); - RETURN_IF_STMT(mDBRemoveAllFavicons, NS_LITERAL_CSTRING( "DELETE FROM moz_favicons WHERE id NOT IN (" - "SELECT favicon_id FROM moz_places_temp WHERE favicon_id NOT NULL " - "UNION ALL " "SELECT favicon_id FROM moz_places WHERE favicon_id NOT NULL " ")")); @@ -262,16 +245,11 @@ nsFaviconService::ExpireAllFavicons() { mFaviconsExpirationRunning = true; - // We do this in 2 steps, first we null-out all favicons in the disk table, - // then we do the same in the temp table. This is because the view UPDATE - // trigger does not allow setting a NULL value to prevent dataloss. - mozIStorageBaseStatement *stmts[] = { GetStatement(mDBRemoveOnDiskReferences), - GetStatement(mDBRemoveTempReferences), GetStatement(mDBRemoveAllFavicons), }; - NS_ENSURE_STATE(stmts[0] && stmts[1] && stmts[2]); + NS_ENSURE_STATE(stmts[0] && stmts[1]); nsCOMPtr ps; nsCOMPtr callback = new ExpireFaviconsStatementCallbackNotifier(&mFaviconsExpirationRunning); @@ -1051,7 +1029,6 @@ nsFaviconService::FinalizeStatements() { mDBUpdateIcon, mDBSetPageFavicon, mDBRemoveOnDiskReferences, - mDBRemoveTempReferences, mDBRemoveAllFavicons, mDBAssociateFaviconURIToPageURI, }; diff --git a/toolkit/components/places/src/nsFaviconService.h b/toolkit/components/places/src/nsFaviconService.h index da9a88738b3..f4d53e2c8c3 100644 --- a/toolkit/components/places/src/nsFaviconService.h +++ b/toolkit/components/places/src/nsFaviconService.h @@ -190,7 +190,6 @@ private: nsCOMPtr mDBSetPageFavicon; nsCOMPtr mDBAssociateFaviconURIToPageURI; nsCOMPtr mDBRemoveOnDiskReferences; - nsCOMPtr mDBRemoveTempReferences; nsCOMPtr mDBRemoveAllFavicons; static nsFaviconService* gFaviconService; diff --git a/toolkit/components/places/src/nsNavBookmarks.cpp b/toolkit/components/places/src/nsNavBookmarks.cpp index c1cbaa7dabf..b8e5d524cd4 100644 --- a/toolkit/components/places/src/nsNavBookmarks.cpp +++ b/toolkit/components/places/src/nsNavBookmarks.cpp @@ -251,17 +251,12 @@ nsNavBookmarks::GetStatement(const nsCOMPtr& aStmt) // Double ordering covers possible lastModified ties, that could happen when // importing, syncing or due to extensions. + // Note: not using a JOIN is cheaper in this case. RETURN_IF_STMT(mDBFindURIBookmarks, NS_LITERAL_CSTRING( "SELECT b.id " "FROM moz_bookmarks b " - "WHERE b.type = :item_type AND b.fk = ( " - "SELECT id FROM moz_places_temp " - "WHERE url = :page_url " - "UNION " - "SELECT id FROM moz_places " - "WHERE url = :page_url " - "LIMIT 1 " - ") " + "WHERE b.fk = (SELECT id FROM moz_places WHERE url = :page_url) " + "AND b.fk NOTNULL " "ORDER BY b.lastModified DESC, b.id DESC ")); // Select all children of a given folder, sorted by position. @@ -271,15 +266,10 @@ nsNavBookmarks::GetStatement(const nsCOMPtr& aStmt) // by mDBGetURLPageInfo, and additionally contains columns for position, // item_child, and folder_child from moz_bookmarks. RETURN_IF_STMT(mDBGetChildren, NS_LITERAL_CSTRING( - "SELECT IFNULL(h_t.id, h.id), IFNULL(h_t.url, h.url), " - "COALESCE(b.title, h_t.title, h.title), " - "IFNULL(h_t.rev_host, h.rev_host), " - "IFNULL(h_t.visit_count, h.visit_count), " - "IFNULL(h_t.last_visit_date, h.last_visit_date), " - "f.url, null, b.id, b.dateAdded, b.lastModified, b.parent, null, " - "b.position, b.type, b.fk, b.folder_type " + "SELECT h.id, h.url, IFNULL(b.title, h.title), h.rev_host, h.visit_count, " + "h.last_visit_date, f.url, null, b.id, b.dateAdded, b.lastModified, " + "b.parent, null, b.position, b.type, b.fk, b.folder_type " "FROM moz_bookmarks b " - "LEFT JOIN moz_places_temp h_t ON b.fk = h_t.id " "LEFT JOIN moz_places h ON b.fk = h.id " "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " "WHERE b.parent = :parent " @@ -298,8 +288,7 @@ nsNavBookmarks::GetStatement(const nsCOMPtr& aStmt) // Get bookmark/folder/separator properties. RETURN_IF_STMT(mDBGetItemProperties, NS_LITERAL_CSTRING( "SELECT b.id, " - "IFNULL((SELECT url FROM moz_places_temp WHERE id = b.fk), " - "(SELECT url FROM moz_places WHERE id = b.fk)), " + "(SELECT url FROM moz_places WHERE id = b.fk), " "b.title, b.position, b.fk, b.parent, b.type, b.folder_type, " "b.dateAdded, b.lastModified " "FROM moz_bookmarks b " @@ -323,12 +312,9 @@ nsNavBookmarks::GetStatement(const nsCOMPtr& aStmt) "SELECT 1 FROM moz_bookmarks WHERE fk = :page_id")); RETURN_IF_STMT(mDBIsURIBookmarkedInDatabase, NS_LITERAL_CSTRING( - "SELECT 1 FROM moz_bookmarks WHERE fk = (" - "SELECT id FROM moz_places_temp WHERE url = :page_url " - "UNION ALL " - "SELECT id FROM moz_places WHERE url = :page_url " - "LIMIT 1" - ")")); + "SELECT 1 FROM moz_bookmarks b " + "JOIN moz_places h ON b.fk = h.id " + "WHERE h.url = :page_url")); // Checks to make sure a place id is a bookmark, and isn't a livemark. RETURN_IF_STMT(mDBIsRealBookmark, NS_LITERAL_CSTRING( @@ -363,19 +349,12 @@ nsNavBookmarks::GetStatement(const nsCOMPtr& aStmt) RETURN_IF_STMT(mDBSetItemIndex, NS_LITERAL_CSTRING( "UPDATE moz_bookmarks SET position = :item_index WHERE id = :item_id")); - // Get keyword text for bookmarked URI. RETURN_IF_STMT(mDBGetKeywordForURI, NS_LITERAL_CSTRING( "SELECT k.keyword " - "FROM ( " - "SELECT id FROM moz_places_temp " - "WHERE url = :page_url " - "UNION ALL " - "SELECT id FROM moz_places " - "WHERE url = :page_url " - "LIMIT 1 " - ") AS h " + "FROM FROM moz_places h " "JOIN moz_bookmarks b ON b.fk = h.id " - "JOIN moz_keywords k ON k.id = b.keyword_id")); + "JOIN moz_keywords k ON k.id = b.keyword_id " + "WHERE h.url = :page_url ")); RETURN_IF_STMT(mDBAdjustPosition, NS_LITERAL_CSTRING( "UPDATE moz_bookmarks SET position = position + :delta " @@ -422,14 +401,6 @@ nsNavBookmarks::GetStatement(const nsCOMPtr& aStmt) // For most cases these levels of redirects should be fine though, it's hard // to hit a page that is 4 or 5 levels of redirects below a bookmarked page. // - // Moreover this query does not mix-up all possible cases of disk and temp - // tables. This is because we expect a redirects chain to be completely on - // disk or completely in memory. We never bring back visits from disk to - // memory, we sync visits on a timer (the chained visits have narrow times), - // or on bookmarks changes. The likely possiblity that we break a chain in - // the middle is so much smaller than the perf and readability hit we would - // get making complete crossing joins. - // // As a bonus the query also checks first if place_id is already a bookmark, // so you don't have to check that apart. @@ -442,31 +413,13 @@ nsNavBookmarks::GetStatement(const nsCOMPtr& aStmt) nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY); RETURN_IF_STMT(mDBFindRedirectedBookmark, NS_LITERAL_CSTRING( - "SELECT IFNULL( " - "(SELECT url FROM moz_places_temp WHERE id = :page_id), " + "SELECT " "(SELECT url FROM moz_places WHERE id = :page_id) " - ") " "FROM moz_bookmarks b " "WHERE b.fk = :page_id " "UNION ALL " // Not directly bookmarked. - "SELECT IFNULL( " - "(SELECT url FROM moz_places_temp WHERE id = " COALESCE_PLACEID "), " + "SELECT " "(SELECT url FROM moz_places WHERE id = " COALESCE_PLACEID ") " - ") " - "FROM moz_historyvisits_temp self " - "JOIN moz_bookmarks b ON b.fk = " COALESCE_PLACEID - "LEFT JOIN moz_historyvisits_temp parent ON parent.id = self.from_visit " - "LEFT JOIN moz_historyvisits_temp grandparent ON parent.from_visit = grandparent.id " - "AND parent.visit_type IN (") + redirectsFragment + NS_LITERAL_CSTRING(") " - "LEFT JOIN moz_historyvisits_temp greatgrandparent ON grandparent.from_visit = greatgrandparent.id " - "AND grandparent.visit_type IN (") + redirectsFragment + NS_LITERAL_CSTRING(") " - "WHERE self.visit_type IN (") + redirectsFragment + NS_LITERAL_CSTRING(") " - "AND self.place_id = :page_id " - "UNION ALL " // Not in the temp table. - "SELECT IFNULL( " - "(SELECT url FROM moz_places_temp WHERE id = " COALESCE_PLACEID "), " - "(SELECT url FROM moz_places WHERE id = " COALESCE_PLACEID ") " - ") " "FROM moz_historyvisits self " "JOIN moz_bookmarks b ON b.fk = " COALESCE_PLACEID "LEFT JOIN moz_historyvisits parent ON parent.id = self.from_visit " @@ -2631,8 +2584,6 @@ nsNavBookmarks::GetBookmarkIdsForURITArray(nsIURI* aURI, DECLARE_AND_ASSIGN_SCOPED_LAZY_STMT(stmt, mDBFindURIBookmarks); nsresult rv = URIBinder::Bind(stmt, NS_LITERAL_CSTRING("page_url"), aURI); NS_ENSURE_SUCCESS(rv, rv); - rv = stmt->BindInt32ByName(NS_LITERAL_CSTRING("item_type"), TYPE_BOOKMARK); - NS_ENSURE_SUCCESS(rv, rv); PRBool more; while (NS_SUCCEEDED((rv = stmt->ExecuteStep(&more))) && more) { diff --git a/toolkit/components/places/src/nsNavHistory.cpp b/toolkit/components/places/src/nsNavHistory.cpp index 8bedf32fed2..3260239afa4 100644 --- a/toolkit/components/places/src/nsNavHistory.cpp +++ b/toolkit/components/places/src/nsNavHistory.cpp @@ -65,6 +65,7 @@ #include "nsThreadUtils.h" #include "nsAppDirectoryServiceDefs.h" #include "nsMathUtils.h" +#include "mozIStorageCompletionCallback.h" #include "nsNavBookmarks.h" #include "nsAnnotationService.h" @@ -133,7 +134,7 @@ using namespace mozilla::places; // This is the schema version, update it at any schema change and add a // corresponding migrateVxx method below. -#define DATABASE_SCHEMA_VERSION 10 +#define DATABASE_SCHEMA_VERSION 11 // Filename of the database. #define DATABASE_FILENAME NS_LITERAL_STRING("places.sqlite") @@ -312,8 +313,11 @@ protected: class PlacesEvent : public nsRunnable + , public mozIStorageCompletionCallback { public: + NS_DECL_ISUPPORTS + PlacesEvent(const char* aTopic) : mTopic(aTopic) , mDoubleEnqueue(false) @@ -333,6 +337,12 @@ public: return NS_OK; } + NS_IMETHODIMP Complete() + { + Notify(); + return NS_OK; + } + protected: void Notify() { @@ -351,6 +361,12 @@ protected: bool mDoubleEnqueue; }; +NS_IMPL_ISUPPORTS2( + PlacesEvent +, mozIStorageCompletionCallback +, nsIRunnable +) + } // anonymouse namespace @@ -770,6 +786,12 @@ nsNavHistory::InitDB() NS_ENSURE_SUCCESS(rv, rv); } + // Migrate places up to V11 + if (currentSchemaVersion < 11) { + rv = MigrateV11Up(mDBConn); + NS_ENSURE_SUCCESS(rv, rv); + } + // Schema Upgrades must add migration code here. } else { @@ -825,6 +847,12 @@ nsNavHistory::InitDB() rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_PLACEDATE); NS_ENSURE_SUCCESS(rv, rv); + // Visits triggers. + rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERINSERT_TRIGGER); + NS_ENSURE_SUCCESS(rv, rv); + rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERDELETE_TRIGGER); + NS_ENSURE_SUCCESS(rv, rv); + // This makes a big difference in startup time for large profiles because of // finding bookmark redirects using the referring page. rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_FROMVISIT); @@ -855,8 +883,6 @@ nsNavHistory::InitAdditionalDBItems() { nsresult rv = InitTempTables(); NS_ENSURE_SUCCESS(rv, rv); - rv = InitViews(); - NS_ENSURE_SUCCESS(rv, rv); rv = InitFunctions(); NS_ENSURE_SUCCESS(rv, rv); rv = InitStatements(); @@ -949,87 +975,14 @@ mozStorageFunctionGetUnreversedHost::OnFunctionCall( nsresult nsNavHistory::InitTempTables() { - nsresult rv; - - // moz_places_temp - rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_TEMP); + nsresult rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_OPENPAGES_TEMP); NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_TEMP_URL); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_TEMP_FAVICON); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_TEMP_REVHOST); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_TEMP_VISITCOUNT); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_PLACES_TEMP_FRECENCY); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_SYNC_TRIGGER); - NS_ENSURE_SUCCESS(rv, rv); - - - // moz_historyvisits_temp - rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITS_TEMP); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_TEMP_PLACEDATE); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_TEMP_FROMVISIT); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_IDX_MOZ_HISTORYVISITS_TEMP_VISITDATE); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITS_SYNC_TRIGGER); - NS_ENSURE_SUCCESS(rv, rv); - - // moz_openpages_temp - rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_OPENPAGES_TEMP); - NS_ENSURE_SUCCESS(rv, rv); - rv = mDBConn->ExecuteSimpleSQL(CREATE_REMOVEOPENPAGE_CLEANUP_TRIGGER); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; } -nsresult -nsNavHistory::InitViews() -{ - nsresult rv; - - // moz_places_view - rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_PLACES_VIEW); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_PLACES_VIEW_INSERT_TRIGGER); - NS_ENSURE_SUCCESS(rv, rv); - rv = mDBConn->ExecuteSimpleSQL(CREATE_PLACES_VIEW_DELETE_TRIGGER); - NS_ENSURE_SUCCESS(rv, rv); - rv = mDBConn->ExecuteSimpleSQL(CREATE_PLACES_VIEW_UPDATE_TRIGGER); - NS_ENSURE_SUCCESS(rv, rv); - - // moz_historyvisits_view - rv = mDBConn->ExecuteSimpleSQL(CREATE_MOZ_HISTORYVISITS_VIEW); - NS_ENSURE_SUCCESS(rv, rv); - - rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_VIEW_INSERT_TRIGGER); - NS_ENSURE_SUCCESS(rv, rv); - rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_VIEW_DELETE_TRIGGER); - NS_ENSURE_SUCCESS(rv, rv); - rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_VIEW_UPDATE_TRIGGER); - NS_ENSURE_SUCCESS(rv, rv); - - return NS_OK; -} - nsresult nsNavHistory::InitFunctions() { @@ -1054,202 +1007,123 @@ nsNavHistory::InitFunctions() nsresult nsNavHistory::InitStatements() { - // mDBGetURLPageInfo - // We are not checking for duplicated ids into the unified table - // for perf reasons, LIMIT 1 will discard duplicates faster since we - // have unique urls. nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT id, url, title, rev_host, visit_count " - "FROM moz_places_temp " - "WHERE url = :page_url " - "UNION ALL " "SELECT id, url, title, rev_host, visit_count " "FROM moz_places " "WHERE url = :page_url " - "LIMIT 1"), - getter_AddRefs(mDBGetURLPageInfo)); + ), getter_AddRefs(mDBGetURLPageInfo)); NS_ENSURE_SUCCESS(rv, rv); - // mDBGetIdPageInfo - // We are not checking for duplicated ids into the unified table - // for perf reasons, LIMIT 1 will discard duplicates faster since we - // have unique place ids. rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT id, url, title, rev_host, visit_count " - "FROM moz_places_temp " - "WHERE id = :page_id " - "UNION ALL " - "SELECT id, url, title, rev_host, visit_count " - "FROM moz_places " - "WHERE id = :page_id " - "LIMIT 1"), - getter_AddRefs(mDBGetIdPageInfo)); + "SELECT id, url, title, rev_host, visit_count " + "FROM moz_places " + "WHERE id = :page_id " + ), getter_AddRefs(mDBGetIdPageInfo)); NS_ENSURE_SUCCESS(rv, rv); - // mDBRecentVisitOfURL - // We are not checking for duplicated ids into the unified table - // for perf reasons, LIMIT 1 will discard duplicates faster since we - // expect visits in temp table being the most recent. rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT id, session, visit_date " - "FROM moz_historyvisits_temp " - "WHERE place_id = IFNULL( " - "(SELECT id FROM moz_places_temp WHERE url = :page_url), " - "(SELECT id FROM moz_places WHERE url = :page_url) " - ") " - "UNION ALL " - "SELECT id, session, visit_date " - "FROM moz_historyvisits " - "WHERE place_id = IFNULL( " - "(SELECT id FROM moz_places_temp WHERE url = :page_url), " - "(SELECT id FROM moz_places WHERE url = :page_url) " - ") " - "ORDER BY visit_date DESC " - "LIMIT 1 "), - getter_AddRefs(mDBRecentVisitOfURL)); + "SELECT id, session, visit_date " + "FROM moz_historyvisits " + "WHERE place_id = (SELECT id FROM moz_places WHERE url = :page_url) " + "ORDER BY visit_date DESC " + ), getter_AddRefs(mDBRecentVisitOfURL)); NS_ENSURE_SUCCESS(rv, rv); - // mDBRecentVisitOfPlace - // We are not checking for duplicated ids into the unified table - // for perf reasons, LIMIT 1 will discard duplicates faster since we - // expect visits in temp table being the most recent. rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT id FROM moz_historyvisits_temp " - "WHERE place_id = :page_id " - "AND visit_date = :visit_date " - "AND session = :session " - "UNION ALL " - "SELECT id FROM moz_historyvisits " - "WHERE place_id = :page_id " - "AND visit_date = :visit_date " - "AND session = :session " - "LIMIT 1"), - getter_AddRefs(mDBRecentVisitOfPlace)); + "SELECT id FROM moz_historyvisits " + "WHERE place_id = :page_id " + "AND visit_date = :visit_date " + "AND session = :session " + ), getter_AddRefs(mDBRecentVisitOfPlace)); NS_ENSURE_SUCCESS(rv, rv); - // mDBInsertVisit rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "INSERT INTO moz_historyvisits_view " - "(from_visit, place_id, visit_date, visit_type, session) " - "VALUES (:from_visit, :page_id, :visit_date, :visit_type, :session)"), - getter_AddRefs(mDBInsertVisit)); + "INSERT INTO moz_historyvisits " + "(from_visit, place_id, visit_date, visit_type, session) " + "VALUES (:from_visit, :page_id, :visit_date, :visit_type, :session) " + ), getter_AddRefs(mDBInsertVisit)); NS_ENSURE_SUCCESS(rv, rv); - // mDBGetPageVisitStats (see InternalAdd) - // We are not checking for duplicated ids into the unified table - // for perf reasons, LIMIT 1 will discard duplicates faster since we - // have unique place ids. rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT id, visit_count, typed, hidden " - "FROM moz_places_temp " - "WHERE url = :page_url " - "UNION ALL " - "SELECT id, visit_count, typed, hidden " - "FROM moz_places " - "WHERE url = :page_url " - "LIMIT 1"), - getter_AddRefs(mDBGetPageVisitStats)); + "SELECT id, visit_count, typed, hidden " + "FROM moz_places " + "WHERE url = :page_url " + ), getter_AddRefs(mDBGetPageVisitStats)); NS_ENSURE_SUCCESS(rv, rv); - // mDBIsPageVisited - // We are not checking for duplicated ids into the unified table - // for perf reasons, LIMIT 1 will discard duplicates faster since we - // only need to know if a visit exists. - // Use indexed params here for performance. rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT h.id " - "FROM moz_places_temp h " - "WHERE url = ?1 " - "AND ( " - "EXISTS(SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id LIMIT 1) " - "OR EXISTS(SELECT id FROM moz_historyvisits WHERE place_id = h.id LIMIT 1) " - ") " - "UNION ALL " - "SELECT h.id " - "FROM moz_places h " - "WHERE url = ?1 " - "AND ( " - "EXISTS(SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id LIMIT 1) " - "OR EXISTS(SELECT id FROM moz_historyvisits WHERE place_id = h.id LIMIT 1) " - ") " - "LIMIT 1"), - getter_AddRefs(mDBIsPageVisited)); + "SELECT h.id " + "FROM moz_places h " + "WHERE url = ?1 " + "AND EXISTS(SELECT id FROM moz_historyvisits WHERE place_id = h.id LIMIT 1) " + ), getter_AddRefs(mDBIsPageVisited)); NS_ENSURE_SUCCESS(rv, rv); - // mDBUpdatePageVisitStats (see InternalAdd) - // we don't need to update visit_count since it's maintained - // in sync by triggers, and we must NEVER touch it + // We don't need to update visit_count since it's maintained in sync by + // triggers. Indeed we must NEVER touch it! rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "UPDATE moz_places_view " - "SET hidden = :hidden, typed = :typed " - "WHERE id = :page_id"), - getter_AddRefs(mDBUpdatePageVisitStats)); + "UPDATE moz_places " + "SET hidden = :hidden, typed = :typed " + "WHERE id = :page_id " + ), getter_AddRefs(mDBUpdatePageVisitStats)); NS_ENSURE_SUCCESS(rv, rv); - // mDBAddNewPage (see InternalAddNewPage) rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "INSERT INTO moz_places_view " - "(url, title, rev_host, hidden, typed, frecency) " - "VALUES (:page_url, :page_title, :rev_host, :hidden, :typed, :frecency)"), - getter_AddRefs(mDBAddNewPage)); + "INSERT INTO moz_places " + "(url, title, rev_host, hidden, typed, frecency) " + "VALUES (:page_url, :page_title, :rev_host, :hidden, :typed, :frecency) " + ), getter_AddRefs(mDBAddNewPage)); NS_ENSURE_SUCCESS(rv, rv); - // mDBGetTags rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "/* do not warn (bug 487594) */ " - "SELECT GROUP_CONCAT(tag_title, ', ') " - "FROM ( " - "SELECT t.title AS tag_title " - "FROM moz_bookmarks b " - "JOIN moz_bookmarks t ON t.id = b.parent " - "WHERE b.fk = IFNULL((SELECT id FROM moz_places_temp WHERE url = :page_url), " - "(SELECT id FROM moz_places WHERE url = :page_url)) " - "AND LENGTH(t.title) > 0 " - "AND b.type = ") + - nsPrintfCString("%d", nsINavBookmarksService::TYPE_BOOKMARK) + - NS_LITERAL_CSTRING(" AND t.parent = :tags_folder " - "ORDER BY t.title COLLATE NOCASE ASC)"), - getter_AddRefs(mDBGetTags)); + "/* do not warn (bug 487594) */ " + "SELECT GROUP_CONCAT(tag_title, ', ') " + "FROM ( " + "SELECT t.title AS tag_title " + "FROM moz_bookmarks b " + "JOIN moz_bookmarks t ON t.id = b.parent " + "WHERE b.fk = (SELECT id FROM moz_places WHERE url = :page_url) " + "AND LENGTH(t.title) > 0 " + "AND b.type = ") + + nsPrintfCString("%d", nsINavBookmarksService::TYPE_BOOKMARK) + + NS_LITERAL_CSTRING(" AND t.parent = :tags_folder " + "ORDER BY t.title COLLATE NOCASE ASC) " + ), getter_AddRefs(mDBGetTags)); NS_ENSURE_SUCCESS(rv, rv); - // mDBGetItemsWithAnno rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT a.item_id, a.content " - "FROM moz_anno_attributes n " - "JOIN moz_items_annos a ON n.id = a.anno_attribute_id " - "WHERE n.name = :anno_name"), - getter_AddRefs(mDBGetItemsWithAnno)); - NS_ENSURE_SUCCESS(rv, rv); - - // mDBSetPlaceTitle - rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "UPDATE moz_places_view " - "SET title = :page_title " - "WHERE url = :page_url"), - getter_AddRefs(mDBSetPlaceTitle)); + "SELECT a.item_id, a.content " + "FROM moz_anno_attributes n " + "JOIN moz_items_annos a ON n.id = a.anno_attribute_id " + "WHERE n.name = :anno_name " + ), getter_AddRefs(mDBGetItemsWithAnno)); NS_ENSURE_SUCCESS(rv, rv); - // mDBRegisterOpenPage rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "INSERT OR REPLACE INTO moz_openpages_temp (place_id, open_count) " - "VALUES (:page_id, " - "IFNULL(" - "(SELECT open_count + 1 FROM moz_openpages_temp WHERE place_id = :page_id), " - "1" - ")" - ")"), - getter_AddRefs(mDBRegisterOpenPage)); + "UPDATE moz_places " + "SET title = :page_title " + "WHERE url = :page_url " + ), getter_AddRefs(mDBSetPlaceTitle)); NS_ENSURE_SUCCESS(rv, rv); - // mDBUnregisterOpenPage rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "UPDATE moz_openpages_temp " - "SET open_count = open_count - 1 " - "WHERE place_id = :page_id"), - getter_AddRefs(mDBUnregisterOpenPage)); + "INSERT OR REPLACE INTO moz_openpages_temp (place_id, open_count) " + "VALUES (:page_id, " + "IFNULL(" + "(SELECT open_count + 1 FROM moz_openpages_temp WHERE place_id = :page_id), " + "1" + ")" + ")" + ), getter_AddRefs(mDBRegisterOpenPage)); + NS_ENSURE_SUCCESS(rv, rv); + + rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( + "UPDATE moz_openpages_temp " + "SET open_count = open_count - 1 " + "WHERE place_id = :page_id " + ), getter_AddRefs(mDBUnregisterOpenPage)); NS_ENSURE_SUCCESS(rv, rv); - // mDBVisitsForFrecency // NOTE: This is not limited to visits with "visit_type NOT IN (0,4,7,8)" // because otherwise mDBVisitsForFrecency would return no visits // for places with only embed (or undefined) visits. That would @@ -1259,70 +1133,38 @@ nsNavHistory::InitStatements() // In case of a temporary or permanent redirect, calculate the frecency as if // the original page was visited. rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT v.visit_date, COALESCE( " - "(SELECT r.visit_type FROM moz_historyvisits_temp r " - "WHERE v.visit_type IN ") + - nsPrintfCString("(%d,%d) ", TRANSITION_REDIRECT_PERMANENT, - TRANSITION_REDIRECT_TEMPORARY) + - NS_LITERAL_CSTRING(" AND r.id = v.from_visit), " - "(SELECT r.visit_type FROM moz_historyvisits r " - "WHERE v.visit_type IN ") + - nsPrintfCString("(%d,%d) ", TRANSITION_REDIRECT_PERMANENT, - TRANSITION_REDIRECT_TEMPORARY) + - NS_LITERAL_CSTRING(" AND r.id = v.from_visit), " - "visit_type) " - "FROM moz_historyvisits_temp v " - "WHERE v.place_id = :page_id " - "UNION ALL " - "SELECT v.visit_date, COALESCE( " - "(SELECT r.visit_type FROM moz_historyvisits_temp r " - "WHERE v.visit_type IN ") + - nsPrintfCString("(%d,%d) ", TRANSITION_REDIRECT_PERMANENT, - TRANSITION_REDIRECT_TEMPORARY) + - NS_LITERAL_CSTRING(" AND r.id = v.from_visit), " - "(SELECT r.visit_type FROM moz_historyvisits r " - "WHERE v.visit_type IN ") + - nsPrintfCString("(%d,%d) ", TRANSITION_REDIRECT_PERMANENT, - TRANSITION_REDIRECT_TEMPORARY) + - NS_LITERAL_CSTRING(" AND r.id = v.from_visit), " - "visit_type) " - "FROM moz_historyvisits v " - "WHERE v.place_id = :page_id " - "AND v.id NOT IN (SELECT id FROM moz_historyvisits_temp) " - "ORDER BY visit_date DESC LIMIT ") + - nsPrintfCString("%d", mNumVisitsForFrecency), - getter_AddRefs(mDBVisitsForFrecency)); + "SELECT v.visit_date, COALESCE( " + "(SELECT r.visit_type FROM moz_historyvisits r " + "WHERE v.visit_type IN ") + + nsPrintfCString("(%d,%d) ", TRANSITION_REDIRECT_PERMANENT, + TRANSITION_REDIRECT_TEMPORARY) + + NS_LITERAL_CSTRING(" AND r.id = v.from_visit), " + "visit_type) " + "FROM moz_historyvisits v " + "WHERE v.place_id = :page_id " + "ORDER BY visit_date DESC LIMIT " + ) + nsPrintfCString("%d", mNumVisitsForFrecency) + , getter_AddRefs(mDBVisitsForFrecency)); NS_ENSURE_SUCCESS(rv, rv); - // mDBUpdateFrecencyAndHidden rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "UPDATE moz_places_view SET frecency = :frecency, hidden = :hidden " - "WHERE id = :page_id"), - getter_AddRefs(mDBUpdateFrecencyAndHidden)); + "UPDATE moz_places " + "SET frecency = :frecency, hidden = :hidden " + "WHERE id = :page_id " + ), getter_AddRefs(mDBUpdateFrecencyAndHidden)); NS_ENSURE_SUCCESS(rv, rv); - // mDBGetPlaceVisitStats - // We are not checking for duplicated ids into the unified table - // for perf reasons, LIMIT 1 will discard duplicates faster since we - // have unique place ids. rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT typed, hidden, frecency " - "FROM moz_places_temp WHERE id = :page_id " - "UNION ALL " - "SELECT typed, hidden, frecency " - "FROM moz_places WHERE id = :page_id " - "LIMIT 1"), - getter_AddRefs(mDBGetPlaceVisitStats)); + "SELECT typed, hidden, frecency " + "FROM moz_places " + "WHERE id = :page_id " + ), getter_AddRefs(mDBGetPlaceVisitStats)); NS_ENSURE_SUCCESS(rv, rv); - // when calculating frecency, we want the visit count to be - // all the visits. + // When calculating frecency, we want the visit count to be all the visits. rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT " - "(SELECT COUNT(*) FROM moz_historyvisits WHERE place_id = :page_id) + " - "(SELECT COUNT(*) FROM moz_historyvisits_temp WHERE place_id = :page_id " - "AND id NOT IN (SELECT id FROM moz_historyvisits))"), - getter_AddRefs(mDBFullVisitCount)); + "SELECT COUNT(*) FROM moz_historyvisits WHERE place_id = :page_id " + ), getter_AddRefs(mDBFullVisitCount)); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; @@ -1755,8 +1597,7 @@ nsNavHistory::MigrateV9Up(mozIStorageConnection *aDBConn) // Added in Bug 488966. The last_visit_date column caches the last // visit date, this enhances SELECT performances when we // need to sort visits by visit date. - // The cached value is synced by INSERT and DELETE triggers on - // moz_historyvisits_view, on every added or removed visit. + // The cached value is synced by triggers on every added or removed visit. // See nsPlacesTriggers.h for details on the triggers. PRBool oldIndexExists = PR_FALSE; nsresult rv = mDBConn->IndexExists( @@ -1813,7 +1654,60 @@ nsNavHistory::MigrateV10Up(mozIStorageConnection *aDBConn) return NS_OK; } - + + +nsresult +nsNavHistory::MigrateV11Up(mozIStorageConnection *aDBConn) +{ + // Temp tables are going away, so we need the visit_count triggers to return. + + // Regardless triggers existance, every time we pass through this migration + // step, we must ensure correctness of visit_count values. + nsresult rv = aDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING( + "UPDATE moz_places SET visit_count = " + "(SELECT count(*) FROM moz_historyvisits " + "WHERE place_id = moz_places.id " + "AND visit_type NOT IN ") + + nsPrintfCString("(0,%d,%d,%d) ", + nsINavHistoryService::TRANSITION_EMBED, + nsINavHistoryService::TRANSITION_FRAMED_LINK, + nsINavHistoryService::TRANSITION_DOWNLOAD) + + NS_LITERAL_CSTRING(")") + ); + NS_ENSURE_SUCCESS(rv, rv); + + // Now create triggers if needed. + nsCOMPtr triggerDetection; + rv = aDBConn->CreateStatement(NS_LITERAL_CSTRING( + "SELECT name " + "FROM sqlite_master " + "WHERE type = 'trigger' " + "AND name = :trigger_name"), + getter_AddRefs(triggerDetection)); + NS_ENSURE_SUCCESS(rv, rv); + + // Both visits triggers were removed in the past at the same time, so we can + // check just one of them. + PRBool triggerExists; + rv = triggerDetection->BindUTF8StringByName( + NS_LITERAL_CSTRING("trigger_name"), + NS_LITERAL_CSTRING("moz_historyvisits_afterinsert_v2_trigger") + ); + NS_ENSURE_SUCCESS(rv, rv); + rv = triggerDetection->ExecuteStep(&triggerExists); + NS_ENSURE_SUCCESS(rv, rv); + + if (!triggerExists) { + rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERINSERT_TRIGGER); + NS_ENSURE_SUCCESS(rv, rv); + rv = mDBConn->ExecuteSimpleSQL(CREATE_HISTORYVISITS_AFTERDELETE_TRIGGER); + NS_ENSURE_SUCCESS(rv, rv); + } + + return NS_OK; +} + + // nsNavHistory::GetUrlIdFor // // Called by the bookmarks and annotation services, this function returns the @@ -2134,12 +2028,11 @@ nsNavHistory::GetNewSessionID() // Extract the last session ID, so we know where to pick up. There is no // index over sessions so we use the visit_date index. - // This happens on the first visit, so we don't care about temp tables. nsCOMPtr selectSession; nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT session FROM moz_historyvisits " - "ORDER BY visit_date DESC LIMIT 1"), - getter_AddRefs(selectSession)); + "SELECT session FROM moz_historyvisits " + "ORDER BY visit_date DESC " + ), getter_AddRefs(selectSession)); NS_ENSURE_SUCCESS(rv, rv); PRBool hasSession; if (NS_SUCCEEDED(selectSession->ExecuteStep(&hasSession)) && hasSession) @@ -2182,8 +2075,6 @@ nsNavHistory::GetDaysOfHistory() { "strftime('%s','now','localtime','utc') - " "( " "SELECT visit_date FROM moz_historyvisits " - "UNION ALL " - "SELECT visit_date FROM moz_historyvisits_temp " "ORDER BY visit_date ASC LIMIT 1 " ")/1000000 " ")/86400) AS daysOfHistory "), @@ -2554,9 +2445,7 @@ nsNavHistory::GetHasHistoryEntries(PRBool* aHasEntries) nsCOMPtr dbSelectStatement; nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT 1 " - "WHERE EXISTS (SELECT id FROM moz_historyvisits_temp LIMIT 1) " - "OR EXISTS (SELECT id FROM moz_historyvisits LIMIT 1)"), + "SELECT 1 FROM moz_historyvisits "), getter_AddRefs(dbSelectStatement)); NS_ENSURE_SUCCESS(rv, rv); rv = dbSelectStatement->ExecuteStep(aHasEntries); @@ -2574,14 +2463,11 @@ nsNavHistory::FixInvalidFrecenciesForExcludedPlaces() // set frecency to 0 so that it is excluded from url bar autocomplete. nsCOMPtr dbUpdateStatement; nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "UPDATE moz_places_view " + "UPDATE moz_places " "SET frecency = 0 WHERE id IN (" "SELECT h.id FROM moz_places h " "WHERE h.url >= 'place:' AND h.url < 'place;' " "UNION " - "SELECT h.id FROM moz_places_temp h " - "WHERE h.url >= 'place:' AND h.url < 'place;' " - "UNION " // Unvisited child of a livemark "SELECT b.fk FROM moz_bookmarks b " "JOIN moz_bookmarks bp ON bp.id = b.parent " @@ -2590,8 +2476,6 @@ nsNavHistory::FixInvalidFrecenciesForExcludedPlaces() "WHERE n.name = :anno_name " "AND b.fk IN( " "SELECT id FROM moz_places WHERE visit_count = 0 AND frecency < 0 " - "UNION ALL " - "SELECT id FROM moz_places_temp WHERE visit_count = 0 AND frecency < 0 " ") " ")"), getter_AddRefs(dbUpdateStatement)); @@ -3269,47 +3153,13 @@ PlacesSQLQueryBuilder::SelectAsURI() "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " "h.last_visit_date, f.url, v.session, null, null, null, null, ") + tagsSqlFragment + NS_LITERAL_CSTRING( - "FROM moz_places_temp h " - "JOIN moz_historyvisits_temp v ON h.id = v.place_id " + "FROM moz_places h " + "JOIN moz_historyvisits v ON h.id = v.place_id " "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " // WHERE 1 is a no-op since additonal conditions will start with AND. "WHERE 1 " "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " "{ADDITIONAL_CONDITIONS} " - "GROUP BY h.id " - "UNION ALL " - "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " - "h.last_visit_date, f.url, v.session, null, null, null, null, ") + - tagsSqlFragment + NS_LITERAL_CSTRING( - "FROM moz_places_temp h " - "JOIN moz_historyvisits v ON h.id = v.place_id " - "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE h.id NOT IN (SELECT place_id FROM moz_historyvisits_temp) " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " - "GROUP BY h.id " - "UNION ALL " - "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " - "h.last_visit_date, f.url, v.session, null, null, null, null, ") + - tagsSqlFragment + NS_LITERAL_CSTRING( - "FROM moz_places h " - "JOIN moz_historyvisits_temp v ON h.id = v.place_id " - "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE h.id NOT IN (SELECT id FROM moz_places_temp) " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " - "GROUP BY h.id " - "UNION ALL " - "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " - "h.last_visit_date, f.url, v.session, null, null, null, null, ") + - tagsSqlFragment + NS_LITERAL_CSTRING( - "FROM moz_places h " - "JOIN moz_historyvisits v ON h.id = v.place_id " - "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE h.id NOT IN (SELECT id FROM moz_places_temp) " - "AND h.id NOT IN (SELECT place_id FROM moz_historyvisits_temp) " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " "GROUP BY h.id "); break; @@ -3327,23 +3177,6 @@ PlacesSQLQueryBuilder::SelectAsURI() tagsSqlFragment); mQueryString = NS_LITERAL_CSTRING( - "SELECT b2.fk, h.url, COALESCE(b2.title, h.title), h.rev_host, " - "h.visit_count, h.last_visit_date, f.url, null, b2.id, " - "b2.dateAdded, b2.lastModified, b2.parent, ") + - tagsSqlFragment + NS_LITERAL_CSTRING( - "FROM moz_bookmarks b2 " - "JOIN (SELECT b.fk " - "FROM moz_bookmarks b " - // ADDITIONAL_CONDITIONS will filter on parent. - "WHERE b.type = 1 {ADDITIONAL_CONDITIONS} " - ") AS seed ON b2.fk = seed.fk " - "JOIN moz_places_temp h ON h.id = b2.fk " - "LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE NOT EXISTS ( " - "SELECT id FROM moz_bookmarks WHERE id = b2.parent AND parent = ") + - nsPrintfCString("%lld", history->GetTagsFolder()) + - NS_LITERAL_CSTRING(") " - "UNION ALL " "SELECT b2.fk, h.url, COALESCE(b2.title, h.title), h.rev_host, " "h.visit_count, h.last_visit_date, f.url, null, b2.id, " "b2.dateAdded, b2.lastModified, b2.parent, ") + @@ -3360,7 +3193,6 @@ PlacesSQLQueryBuilder::SelectAsURI() "SELECT id FROM moz_bookmarks WHERE id = b2.parent AND parent = ") + nsPrintfCString("%lld", history->GetTagsFolder()) + NS_LITERAL_CSTRING(") " - "AND h.id NOT IN (SELECT id FROM moz_places_temp) " "ORDER BY b2.fk DESC, b2.lastModified DESC"); } else { @@ -3369,20 +3201,6 @@ PlacesSQLQueryBuilder::SelectAsURI() mHasSearchTerms, tagsSqlFragment); mQueryString = NS_LITERAL_CSTRING( - "SELECT b.fk, h.url, COALESCE(b.title, h.title), h.rev_host, " - "h.visit_count, h.last_visit_date, f.url, null, b.id, " - "b.dateAdded, b.lastModified, b.parent, ") + - tagsSqlFragment + NS_LITERAL_CSTRING( - "FROM moz_bookmarks b " - "JOIN moz_places_temp h ON b.fk = h.id AND b.type = 1 " - "LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE NOT EXISTS " - "(SELECT id FROM moz_bookmarks " - "WHERE id = b.parent AND parent = ") + - nsPrintfCString("%lld", history->GetTagsFolder()) + - NS_LITERAL_CSTRING(") " - "{ADDITIONAL_CONDITIONS}" - "UNION ALL " "SELECT b.fk, h.url, COALESCE(b.title, h.title), h.rev_host, " "h.visit_count, h.last_visit_date, f.url, null, b.id, " "b.dateAdded, b.lastModified, b.parent, ") + @@ -3390,8 +3208,7 @@ PlacesSQLQueryBuilder::SelectAsURI() "FROM moz_bookmarks b " "JOIN moz_places h ON b.fk = h.id AND b.type = 1 " "LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE h.id NOT IN (SELECT id FROM moz_places_temp) " - "AND NOT EXISTS " + "WHERE NOT EXISTS " "(SELECT id FROM moz_bookmarks " "WHERE id = b.parent AND parent = ") + nsPrintfCString("%lld", history->GetTagsFolder()) + @@ -3420,42 +3237,11 @@ PlacesSQLQueryBuilder::SelectAsVisit() "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " "v.visit_date, f.url, v.session, null, null, null, null, ") + tagsSqlFragment + NS_LITERAL_CSTRING( - "FROM moz_places_temp h " - "JOIN moz_historyvisits_temp v ON h.id = v.place_id " - "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " - // WHERE 1 is a no-op since additonal conditions will start with AND. - "WHERE 1 " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " - "UNION ALL " - "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " - "v.visit_date, f.url, v.session, null, null, null, null, ") + - tagsSqlFragment + NS_LITERAL_CSTRING( - "FROM moz_places_temp h " + "FROM moz_places h " "JOIN moz_historyvisits v ON h.id = v.place_id " "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " // WHERE 1 is a no-op since additonal conditions will start with AND. "WHERE 1 " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " - "UNION ALL " - "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " - "v.visit_date, f.url, v.session, null, null, null, null, ") + - tagsSqlFragment + NS_LITERAL_CSTRING( - "FROM moz_places h " - "JOIN moz_historyvisits_temp v ON h.id = v.place_id " - "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE h.id NOT IN (SELECT id FROM moz_places_temp) " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " - "UNION ALL " - "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " - "v.visit_date, f.url, v.session, null, null, null, null, ") + - tagsSqlFragment + NS_LITERAL_CSTRING( - "FROM moz_places h " - "JOIN moz_historyvisits v ON h.id = v.place_id " - "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE h.id NOT IN (SELECT id FROM moz_places_temp) " "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " "{ADDITIONAL_CONDITIONS} "); @@ -3630,12 +3416,6 @@ PlacesSQLQueryBuilder::SelectAsDay() "%s AS beginTime, " "%s AS endTime " "WHERE EXISTS ( " - "SELECT id FROM moz_historyvisits_temp " - "WHERE visit_date >= %s " - "AND visit_date < %s " - "AND visit_type NOT IN (0,%d,%d) " - "{QUERY_OPTIONS_VISITS} " - "UNION ALL " "SELECT id FROM moz_historyvisits " "WHERE visit_date >= %s " "AND visit_date < %s " @@ -3647,10 +3427,6 @@ PlacesSQLQueryBuilder::SelectAsDay() sqlFragmentContainerBeginTime.get(), sqlFragmentContainerEndTime.get(), sqlFragmentSearchBeginTime.get(), - sqlFragmentSearchEndTime.get(), - nsINavHistoryService::TRANSITION_EMBED, - nsINavHistoryService::TRANSITION_FRAMED_LINK, - sqlFragmentSearchBeginTime.get(), sqlFragmentSearchEndTime.get(), nsINavHistoryService::TRANSITION_EMBED, nsINavHistoryService::TRANSITION_FRAMED_LINK); @@ -3684,15 +3460,8 @@ PlacesSQLQueryBuilder::SelectAsSite() "'place:type=%ld&sort=%ld&domain=&domainIsHost=true', " ":localhost, :localhost, null, null, null, null, null, null, null " "WHERE EXISTS ( " - "SELECT id FROM moz_places_temp " - "WHERE hidden <> 1 " - "AND rev_host = '.' " - "AND visit_count > 0 " - "AND url BETWEEN 'file://' AND 'file:/~' " - "UNION ALL " "SELECT id FROM moz_places " - "WHERE id NOT IN (SELECT id FROM moz_places_temp) " - "AND hidden <> 1 " + "WHERE hidden <> 1 " "AND rev_host = '.' " "AND visit_count > 0 " "AND url BETWEEN 'file://' AND 'file:/~' " @@ -3704,14 +3473,8 @@ PlacesSQLQueryBuilder::SelectAsSite() "FROM ( " "SELECT get_unreversed_host(rev_host) host " "FROM ( " - "SELECT DISTINCT rev_host FROM moz_places_temp " - "WHERE hidden <> 1 " - "AND rev_host <> '.' " - "AND visit_count > 0 " - "UNION ALL " "SELECT DISTINCT rev_host FROM moz_places " - "WHERE id NOT IN (SELECT id FROM moz_places_temp) " - "AND hidden <> 1 " + "WHERE hidden <> 1 " "AND rev_host <> '.' " "AND visit_count > 0 " ") " @@ -3737,33 +3500,6 @@ PlacesSQLQueryBuilder::SelectAsSite() "AND h.url BETWEEN 'file://' AND 'file:/~' " "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " "{ADDITIONAL_CONDITIONS} " - "UNION " - "SELECT h.id " - "FROM moz_places_temp h " - "JOIN moz_historyvisits v ON v.place_id = h.id " - "WHERE h.hidden <> 1 AND h.rev_host = '.' " - "AND h.visit_count > 0 " - "AND h.url BETWEEN 'file://' AND 'file:/~' " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " - "UNION " - "SELECT h.id " - "FROM moz_places h " - "JOIN moz_historyvisits_temp v ON v.place_id = h.id " - "WHERE h.hidden <> 1 AND h.rev_host = '.' " - "AND h.visit_count > 0 " - "AND h.url BETWEEN 'file://' AND 'file:/~' " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " - "UNION " - "SELECT h.id " - "FROM moz_places_temp h " - "JOIN moz_historyvisits_temp v ON v.place_id = h.id " - "WHERE h.hidden <> 1 AND h.rev_host = '.' " - "AND h.visit_count > 0 " - "AND h.url BETWEEN 'file://' AND 'file:/~' " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " ") " "UNION ALL " "SELECT DISTINCT null, " @@ -3778,30 +3514,6 @@ PlacesSQLQueryBuilder::SelectAsSite() "AND h.visit_count > 0 " "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " "{ADDITIONAL_CONDITIONS} " - "UNION " - "SELECT DISTINCT get_unreversed_host(rev_host) AS host " - "FROM moz_places_temp h " - "JOIN moz_historyvisits v ON v.place_id = h.id " - "WHERE h.rev_host <> '.' " - "AND h.visit_count > 0 " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " - "UNION " - "SELECT DISTINCT get_unreversed_host(rev_host) AS host " - "FROM moz_places h " - "JOIN moz_historyvisits_temp v ON v.place_id = h.id " - "WHERE h.rev_host <> '.' " - "AND h.visit_count > 0 " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " - "UNION " - "SELECT DISTINCT get_unreversed_host(rev_host) AS host " - "FROM moz_places_temp h " - "JOIN moz_historyvisits_temp v ON v.place_id = h.id " - "WHERE h.rev_host <> '.' " - "AND h.visit_count > 0 " - "{QUERY_OPTIONS_VISITS} {QUERY_OPTIONS_PLACES} " - "{ADDITIONAL_CONDITIONS} " "ORDER BY 1 ASC " ") ", nsINavHistoryQueryOptions::RESULTS_AS_URI, @@ -3853,11 +3565,6 @@ PlacesSQLQueryBuilder::Where() else if (mRedirectsMode == nsINavHistoryQueryOptions::REDIRECTS_MODE_TARGET) { additionalVisitsConditions += NS_LITERAL_CSTRING( "AND NOT EXISTS ( " - "SELECT id FROM moz_historyvisits_temp WHERE from_visit = v.id " - "AND visit_type IN ") + - nsPrintfCString("(%d,%d) ", nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT, - nsINavHistoryService::TRANSITION_REDIRECT_TEMPORARY) + - NS_LITERAL_CSTRING(") AND NOT EXISTS ( " "SELECT id FROM moz_historyvisits WHERE from_visit = v.id " "AND visit_type IN ") + nsPrintfCString("(%d,%d) ", nsINavHistoryService::TRANSITION_REDIRECT_PERMANENT, @@ -3924,9 +3631,7 @@ PlacesSQLQueryBuilder::OrderBy() switch(mSortingMode) { case nsINavHistoryQueryOptions::SORT_BY_NONE: - // If this is a URI query the sorting could change based on the - // sync status of disk and temp tables, we must ensure sorting does not - // change between queries. + // Ensure sorting does not change based on tables status. if (mResultType == nsINavHistoryQueryOptions::RESULTS_AS_URI) { if (mQueryType == nsINavHistoryQueryOptions::QUERY_TYPE_BOOKMARKS) mQueryString += NS_LITERAL_CSTRING(" ORDER BY b.id ASC "); @@ -4066,40 +3771,13 @@ nsNavHistory::ConstructQueryString( // Generate an optimized query for the history menu and most visited // smart bookmark. queryString = NS_LITERAL_CSTRING( - "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, h.last_visit_date, " - "f.url, null, null, null, null, null, ") + - tagsSqlFragment + NS_LITERAL_CSTRING( - "FROM moz_places_temp h " - "LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE h.hidden <> 1 " - "AND EXISTS (SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id " - "AND visit_type NOT IN ") + - nsPrintfCString("(0,%d,%d) ", - nsINavHistoryService::TRANSITION_EMBED, - nsINavHistoryService::TRANSITION_FRAMED_LINK) + - NS_LITERAL_CSTRING("UNION ALL " - "SELECT id FROM moz_historyvisits WHERE place_id = h.id " - "AND visit_type NOT IN ") + - nsPrintfCString("(0,%d,%d) ", - nsINavHistoryService::TRANSITION_EMBED, - nsINavHistoryService::TRANSITION_FRAMED_LINK) + - NS_LITERAL_CSTRING("LIMIT 1) " - "{QUERY_OPTIONS} " - "UNION ALL " "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, h.last_visit_date, " "f.url, null, null, null, null, null, ") + tagsSqlFragment + NS_LITERAL_CSTRING( "FROM moz_places h " "LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id " "WHERE h.hidden <> 1 " - "AND h.id NOT IN (SELECT id FROM moz_places_temp) " - "AND EXISTS (SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id " - "AND visit_type NOT IN ") + - nsPrintfCString("(0,%d,%d) ", - nsINavHistoryService::TRANSITION_EMBED, - nsINavHistoryService::TRANSITION_FRAMED_LINK) + - NS_LITERAL_CSTRING("UNION ALL " - "SELECT id FROM moz_historyvisits WHERE place_id = h.id " + "AND EXISTS (SELECT id FROM moz_historyvisits WHERE place_id = h.id " "AND visit_type NOT IN ") + nsPrintfCString("(0,%d,%d) ", nsINavHistoryService::TRANSITION_EMBED, @@ -4121,48 +3799,24 @@ nsNavHistory::ConstructQueryString( if (aOptions->RedirectsMode() == nsINavHistoryQueryOptions::REDIRECTS_MODE_SOURCE) { additionalQueryOptions += nsPrintfCString(256, - "AND NOT EXISTS ( " - "SELECT id FROM moz_historyvisits_temp WHERE place_id = h.id " - "AND visit_type IN (%d,%d)" - ") " "AND NOT EXISTS ( " "SELECT id FROM moz_historyvisits WHERE place_id = h.id " "AND visit_type IN (%d,%d)" ") ", TRANSITION_REDIRECT_PERMANENT, - TRANSITION_REDIRECT_TEMPORARY, - TRANSITION_REDIRECT_PERMANENT, TRANSITION_REDIRECT_TEMPORARY); } else if (aOptions->RedirectsMode() == nsINavHistoryQueryOptions::REDIRECTS_MODE_TARGET) { additionalQueryOptions += nsPrintfCString(1024, "AND NOT EXISTS ( " - "SELECT id " - "FROM moz_historyvisits_temp v " - "WHERE place_id = h.id " - "AND EXISTS(SELECT id FROM moz_historyvisits_temp " - "WHERE from_visit = v.id AND visit_type IN (%d,%d) " - "UNION ALL " - "SELECT id FROM moz_historyvisits " - "WHERE from_visit = v.id AND visit_type IN (%d,%d)) " - "UNION ALL " "SELECT id " "FROM moz_historyvisits v " "WHERE place_id = h.id " - "AND EXISTS(SELECT id FROM moz_historyvisits_temp " - "WHERE from_visit = v.id AND visit_type IN (%d,%d) " - "UNION ALL " - "SELECT id FROM moz_historyvisits " + "AND EXISTS(SELECT id FROM moz_historyvisits " "WHERE from_visit = v.id AND visit_type IN (%d,%d)) " ") ", TRANSITION_REDIRECT_PERMANENT, - TRANSITION_REDIRECT_TEMPORARY, - TRANSITION_REDIRECT_PERMANENT, - TRANSITION_REDIRECT_TEMPORARY, - TRANSITION_REDIRECT_PERMANENT, - TRANSITION_REDIRECT_TEMPORARY, - TRANSITION_REDIRECT_PERMANENT, TRANSITION_REDIRECT_TEMPORARY); } queryString.ReplaceSubstring("{QUERY_OPTIONS}", @@ -4406,27 +4060,11 @@ nsNavHistory::GetLastPageVisited(nsACString & aLastPageVisited) NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread"); nsCOMPtr statement; - // We are not checking for duplicated ids into the unified table - // for perf reasons, LIMIT 1 will discard duplicates faster since we - // expect newest visits being in temp table. nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT url, visit_date FROM moz_historyvisits_temp v " - "JOIN moz_places_temp h ON v.place_id = h.id " - "WHERE h.hidden <> 1 " - "UNION ALL " - "SELECT url, visit_date FROM moz_historyvisits_temp v " - "JOIN moz_places h ON v.place_id = h.id " - "WHERE h.hidden <> 1 " - "UNION ALL " - "SELECT url, visit_date FROM moz_historyvisits v " - "JOIN moz_places_temp h ON v.place_id = h.id " - "WHERE h.hidden <> 1 " - "UNION ALL " "SELECT url, visit_date FROM moz_historyvisits v " "JOIN moz_places h ON v.place_id = h.id " "WHERE h.hidden <> 1 " - "ORDER BY visit_date DESC " - "LIMIT 1 "), + "ORDER BY visit_date DESC "), getter_AddRefs(statement)); NS_ENSURE_SUCCESS(rv, rv); @@ -4484,7 +4122,7 @@ nsNavHistory::RemovePagesInternal(const nsCString& aPlaceIdsQueryString) // Delete all visits for the specified place ids. rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING( - "DELETE FROM moz_historyvisits_view WHERE place_id IN (") + + "DELETE FROM moz_historyvisits WHERE place_id IN (") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(")")); NS_ENSURE_SUCCESS(rv, rv); @@ -4523,21 +4161,12 @@ nsNavHistory::PreparePlacesForVisitsDelete(const nsCString& aPlaceIdsQueryString // to figure out which places to recalculate frecency first. // Pay attention to not set frecency = 0 if visit_count = 0 nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING( - "UPDATE moz_places_view " + "UPDATE moz_places " "SET frecency = -MAX(visit_count, 1) " "WHERE id IN ( " - "SELECT h.id " - "FROM moz_places_temp h " - "WHERE h.id IN ( ") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(") " - "AND ( " - "EXISTS (SELECT b.id FROM moz_bookmarks b WHERE b.fk =h.id) " - "OR EXISTS (SELECT a.id FROM moz_annos a WHERE a.place_id = h.id) " - ") " - "UNION ALL " "SELECT h.id " "FROM moz_places h " "WHERE h.id IN ( ") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(") " - "AND h.id NOT IN (SELECT id FROM moz_places_temp) " "AND ( " "EXISTS (SELECT b.id FROM moz_bookmarks b WHERE b.fk =h.id) " "OR EXISTS (SELECT a.id FROM moz_annos a WHERE a.place_id = h.id) " @@ -4572,16 +4201,9 @@ nsNavHistory::CleanupPlacesOnVisitsDelete(const nsCString& aPlaceIdsQueryString) // Note that we do NOT delete favicons. Any unreferenced favicons will be // deleted next time the browser is shut down. nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING( - "DELETE FROM moz_places_view WHERE id IN (" - "SELECT h.id FROM moz_places_temp h " - "WHERE h.id IN ( ") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(") " - "AND SUBSTR(h.url, 1, 6) <> 'place:' " - "AND NOT EXISTS " - "(SELECT b.id FROM moz_bookmarks b WHERE b.fk = h.id LIMIT 1) " - "UNION ALL " + "DELETE FROM moz_places WHERE id IN ( " "SELECT h.id FROM moz_places h " - "WHERE h.id NOT IN (SELECT id FROM moz_places_temp) " - "AND h.id IN ( ") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(") " + "WHERE h.id IN ( ") + aPlaceIdsQueryString + NS_LITERAL_CSTRING(") " "AND SUBSTR(h.url, 1, 6) <> 'place:' " "AND NOT EXISTS " "(SELECT b.id FROM moz_bookmarks b WHERE b.fk = h.id LIMIT 1) " @@ -4720,12 +4342,8 @@ nsNavHistory::RemovePagesFromHost(const nsACString& aHost, PRBool aEntireDomain) // create statement depending on delete type rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT id FROM moz_places_temp " - "WHERE ") + conditionString + NS_LITERAL_CSTRING( - "UNION ALL " "SELECT id FROM moz_places " - "WHERE id NOT IN (SELECT id FROM moz_places_temp) " - "AND ") + conditionString, + "WHERE ") + conditionString, getter_AddRefs(statement)); NS_ENSURE_SUCCESS(rv, rv); rv = statement->BindStringByIndex(0, revHostDot); @@ -4777,20 +4395,9 @@ nsNavHistory::RemovePagesByTimeframe(PRTime aBeginTime, PRTime aEndTime) // this query is faster than actually selecting in moz_historyvisits nsCOMPtr selectByTime; rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT h.id FROM moz_places_temp h WHERE " - "EXISTS " - "(SELECT id FROM moz_historyvisits v WHERE v.place_id = h.id " - "AND v.visit_date >= :from_date AND v.visit_date <= :to_date LIMIT 1)" - "OR EXISTS " - "(SELECT id FROM moz_historyvisits_temp v WHERE v.place_id = h.id " - "AND v.visit_date >= :from_date AND v.visit_date <= :to_date LIMIT 1) " - "UNION " "SELECT h.id FROM moz_places h WHERE " "EXISTS " "(SELECT id FROM moz_historyvisits v WHERE v.place_id = h.id " - "AND v.visit_date >= :from_date AND v.visit_date <= :to_date LIMIT 1)" - "OR EXISTS " - "(SELECT id FROM moz_historyvisits_temp v WHERE v.place_id = h.id " "AND v.visit_date >= :from_date AND v.visit_date <= :to_date LIMIT 1)"), getter_AddRefs(selectByTime)); NS_ENSURE_SUCCESS(rv, rv); @@ -4850,19 +4457,11 @@ nsNavHistory::RemoveVisitsByTimeframe(PRTime aBeginTime, PRTime aEndTime) nsCOMPtr selectByTime; mozStorageStatementScoper scope(selectByTime); rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT place_id " - "FROM moz_historyvisits_temp " - "WHERE :from_date <= visit_date AND visit_date <= :to_date " - "UNION " "SELECT place_id " "FROM moz_historyvisits " "WHERE :from_date <= visit_date AND visit_date <= :to_date " "EXCEPT " "SELECT place_id " - "FROM moz_historyvisits_temp " - "WHERE visit_date < :from_date OR :to_date < visit_date " - "EXCEPT " - "SELECT place_id " "FROM moz_historyvisits " "WHERE visit_date < :from_date OR :to_date < visit_date"), getter_AddRefs(selectByTime)); @@ -4897,7 +4496,7 @@ nsNavHistory::RemoveVisitsByTimeframe(PRTime aBeginTime, PRTime aEndTime) // Delete all visits within the timeframe. nsCOMPtr deleteVisitsStmt; rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "DELETE FROM moz_historyvisits_view " + "DELETE FROM moz_historyvisits " "WHERE :from_date <= visit_date AND visit_date <= :to_date"), getter_AddRefs(deleteVisitsStmt)); NS_ENSURE_SUCCESS(rv, rv); @@ -4937,11 +4536,8 @@ nsNavHistory::RemoveAllPages() // idle query to figure out which places to recalcuate frecency first. // We must do this before deleting visits. nsresult rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING( - "UPDATE moz_places_view SET frecency = -MAX(visit_count, 1) " + "UPDATE moz_places SET frecency = -MAX(visit_count, 1) " "WHERE id IN(" - "SELECT h.id FROM moz_places_temp h " - "WHERE EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) " - "UNION ALL " "SELECT h.id FROM moz_places h " "WHERE EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) " ")")); @@ -4949,7 +4545,7 @@ nsNavHistory::RemoveAllPages() // Expire visits, then let the paranoid functions do the cleanup for us. rv = mDBConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING( - "DELETE FROM moz_historyvisits_view")); + "DELETE FROM moz_historyvisits")); NS_ENSURE_SUCCESS(rv, rv); // Some of the remaining places could be place: urls or @@ -5751,8 +5347,11 @@ nsNavHistory::Observe(nsISupports *aSubject, const char *aTopic, nsresult rv = FinalizeInternalStatements(); NS_ENSURE_SUCCESS(rv, rv); - // NOTE: We don't close the connection because the sync service could still - // need it for a final flush. + // Finally, close the connection. + nsRefPtr closeListener = + new PlacesEvent(TOPIC_PLACES_DATABASE_CLOSED); + (void)mDBConn->AsyncClose(closeListener); + mDBConn = nsnull; } #ifdef MOZ_XUL @@ -5946,9 +5545,8 @@ nsNavHistory::DecayFrecency() // Globally decay places frecency rankings to estimate reduced frecency // values of pages that haven't been visited for a while, i.e., they do - // not get an updated frecency. We directly modify moz_places to avoid - // bringing the whole database into places_temp through places_view. A - // scaling factor of .975 results in .5 the original value after 28 days. + // not get an updated frecency. A scaling factor of .975 results in .5 the + // original value after 28 days. nsCOMPtr decayFrecency; rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( "UPDATE moz_places SET frecency = ROUND(frecency * .975) " @@ -6159,9 +5757,6 @@ nsNavHistory::QueryToSelectClause(nsNavHistoryQuery* aQuery, // const nsPrintfCString param(":transition%d_", i); clause.Str("EXISTS (SELECT 1 FROM moz_historyvisits " "WHERE place_id = h.id AND visit_type = " - ).Param(param.get()).Str(" UNION ALL " - "SELECT 1 FROM moz_historyvisits_temp " - "WHERE place_id = h.id AND visit_type = " ).Param(param.get()).Str(" LIMIT 1)"); if (i < transitions.Length() - 1) clause.Str("AND"); @@ -7748,7 +7343,7 @@ nsNavHistory::FixInvalidFrecencies() nsCOMPtr invalidFrecencies; nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( "SELECT id, typed, hidden, frecency, url " - "FROM moz_places_view " + "FROM moz_places " "WHERE frecency < 0"), getter_AddRefs(invalidFrecencies)); NS_ENSURE_SUCCESS(rv, rv); @@ -7864,15 +7459,9 @@ nsNavHistory::GetDBFeedbackIncrease() "INSERT OR REPLACE INTO moz_inputhistory " // use_count will asymptotically approach the max of 10. "SELECT h.id, IFNULL(i.input, :input_text), IFNULL(i.use_count, 0) * .9 + 1 " - "FROM moz_places_temp h " - "LEFT JOIN moz_inputhistory i ON i.place_id = h.id AND i.input = :input_text " - "WHERE url = :page_url " - "UNION ALL " - "SELECT h.id, IFNULL(i.input, :input_text), IFNULL(i.use_count, 0) * .9 + 1 " "FROM moz_places h " "LEFT JOIN moz_inputhistory i ON i.place_id = h.id AND i.input = :input_text " - "WHERE url = :page_url " - "AND h.id NOT IN (SELECT id FROM moz_places_temp)"), + "WHERE url = :page_url "), getter_AddRefs(mDBFeedbackIncrease)); NS_ENSURE_SUCCESS(rv, nsnull); @@ -7940,27 +7529,14 @@ nsNavHistory::GetDBVisitToVisitResult() if (mDBVisitToVisitResult) return mDBVisitToVisitResult; - // mDBVisitToVisitResult, should match kGetInfoIndex_* (see GetQueryResults) - // We are not checking for duplicated ids into the unified table - // for perf reasons, LIMIT 1 will discard duplicates faster since we - // have unique visit ids. + // Should match kGetInfoIndex_* (see GetQueryResults) nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " - "v.visit_date, f.url, v.session, null, null, null, null " - "FROM moz_places_temp h " - "LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id " - "LEFT JOIN moz_historyvisits v ON h.id = v.place_id " - "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE v.id = :visit_id OR v_t.id = :visit_id " - "UNION ALL " "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " "v.visit_date, f.url, v.session, null, null, null, null " "FROM moz_places h " - "LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id " - "LEFT JOIN moz_historyvisits v ON h.id = v.place_id " + "JOIN moz_historyvisits v ON h.id = v.place_id " "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE v.id = :visit_id OR v_t.id = :visit_id " - "LIMIT 1"), + "WHERE v.id = :visit_id "), getter_AddRefs(mDBVisitToVisitResult)); NS_ENSURE_SUCCESS(rv, nsnull); @@ -7973,27 +7549,14 @@ nsNavHistory::GetDBVisitToURLResult() if (mDBVisitToURLResult) return mDBVisitToURLResult; - // mDBVisitToURLResult, should match kGetInfoIndex_* (see GetQueryResults) - // We are not checking for duplicated ids into the unified table - // for perf reasons, LIMIT 1 will discard duplicates faster since we - // have unique visit ids. + // Should match kGetInfoIndex_* (see GetQueryResults) nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " - "h.last_visit_date, f.url, null, null, null, null, null, null " - "FROM moz_places_temp h " - "LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id " - "LEFT JOIN moz_historyvisits v ON h.id = v.place_id " - "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE v.id = :visit_id OR v_t.id = :visit_id " - "UNION ALL " "SELECT h.id, h.url, h.title, h.rev_host, h.visit_count, " "h.last_visit_date, f.url, null, null, null, null, null, null " "FROM moz_places h " - "LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id " - "LEFT JOIN moz_historyvisits v ON h.id = v.place_id " + "JOIN moz_historyvisits v ON h.id = v.place_id " "LEFT JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE v.id = :visit_id OR v_t.id = :visit_id " - "LIMIT 1"), + "WHERE v.id = :visit_id "), getter_AddRefs(mDBVisitToURLResult)); NS_ENSURE_SUCCESS(rv, nsnull); @@ -8011,14 +7574,6 @@ nsNavHistory::GetDBBookmarkToUrlResult() // for perf reasons, LIMIT 1 will discard duplicates faster since we // have unique place ids. nsresult rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT b.fk, h.url, COALESCE(b.title, h.title), " - "h.rev_host, h.visit_count, h.last_visit_date, f.url, null, b.id, " - "b.dateAdded, b.lastModified, b.parent, null " - "FROM moz_bookmarks b " - "JOIN moz_places_temp h ON b.fk = h.id " - "LEFT OUTER JOIN moz_favicons f ON h.favicon_id = f.id " - "WHERE b.id = :item_id " - "UNION ALL " "SELECT b.fk, h.url, COALESCE(b.title, h.title), " "h.rev_host, h.visit_count, h.last_visit_date, f.url, null, b.id, " "b.dateAdded, b.lastModified, b.parent, null " diff --git a/toolkit/components/places/src/nsNavHistory.h b/toolkit/components/places/src/nsNavHistory.h index 3614c87e069..a9f5ee58c18 100644 --- a/toolkit/components/places/src/nsNavHistory.h +++ b/toolkit/components/places/src/nsNavHistory.h @@ -99,6 +99,8 @@ // If you need to listen for Places shutdown, you should really use // places-shutdown, because places-teardown is guaranteed to break your code. #define TOPIC_PLACES_TEARDOWN "places-teardown" +// Fired when the database connection has been closed. +#define TOPIC_PLACES_DATABASE_CLOSED "places-database-closed" // Fired when Places found a locked database while initing. #define TOPIC_DATABASE_LOCKED "places-database-locked" // Fired after Places inited. @@ -550,7 +552,6 @@ protected: */ nsresult InitAdditionalDBItems(); nsresult InitTempTables(); - nsresult InitViews(); nsresult InitFunctions(); nsresult InitStatements(); nsresult ForceMigrateBookmarksDB(mozIStorageConnection *aDBConn); @@ -560,6 +561,7 @@ protected: nsresult MigrateV8Up(mozIStorageConnection *aDBConn); nsresult MigrateV9Up(mozIStorageConnection *aDBConn); nsresult MigrateV10Up(mozIStorageConnection *aDBConn); + nsresult MigrateV11Up(mozIStorageConnection *aDBConn); nsresult RemovePagesInternal(const nsCString& aPlaceIdsQueryString); nsresult PreparePlacesForVisitsDelete(const nsCString& aPlaceIdsQueryString); diff --git a/toolkit/components/places/src/nsPlacesAutoComplete.js b/toolkit/components/places/src/nsPlacesAutoComplete.js index 3d73eadd541..582d7999dc2 100644 --- a/toolkit/components/places/src/nsPlacesAutoComplete.js +++ b/toolkit/components/places/src/nsPlacesAutoComplete.js @@ -108,33 +108,6 @@ const kTitleTagsSeparator = " \u2013 "; const kBrowserUrlbarBranch = "browser.urlbar."; -//////////////////////////////////////////////////////////////////////////////// -//// Global Functions - -/** - * Generates the SQL subquery to get the best favicon for a given revhost. This - * is the favicon for the most recent visit. - * - * @param aTableName - * The table to join to the moz_favicons table with. This must have a - * column called favicon_id. - * @return the SQL subquery (in string form) to get the best favicon. - */ -function best_favicon_for_revhost(aTableName) -{ - return "(" + - "SELECT f.url " + - "FROM " + aTableName + " " + - "JOIN moz_favicons f ON f.id = favicon_id " + - "WHERE rev_host = IFNULL( " + - "(SELECT rev_host FROM moz_places_temp WHERE id = b.fk), " + - "(SELECT rev_host FROM moz_places WHERE id = b.fk) " + - ") " + - "ORDER BY frecency DESC " + - "LIMIT 1 " + - ")"; -} - //////////////////////////////////////////////////////////////////////////////// //// AutoCompleteStatementCallbackWrapper class @@ -211,32 +184,24 @@ function nsPlacesAutoComplete() ////////////////////////////////////////////////////////////////////////////// //// Shared Constants for Smart Getters - // Define common pieces of various queries. // TODO bug 412736 in case of a frecency tie, break it with h.typed and // h.visit_count which is better than nothing. This is slow, so not doing it // yet... - // Note: h.frecency is only selected because we need it for ordering. - function sql_base_fragment(aTableName) { - return "SELECT h.url, h.title, f.url, " + kBookTagSQLFragment + ", " + - "h.visit_count, h.typed, h.id, :query_type, t.open_count, " + - "h.frecency " + - "FROM " + aTableName + " h " + - "LEFT OUTER JOIN moz_favicons f ON f.id = h.favicon_id " + - "LEFT OUTER JOIN moz_openpages_temp t ON t.place_id = h.id " + - "WHERE h.frecency <> 0 " + - "AND AUTOCOMPLETE_MATCH(:searchString, h.url, " + - "IFNULL(bookmark, h.title), tags, " + - "h.visit_count, h.typed, parent, " + - "t.open_count, " + - ":matchBehavior, :searchBehavior) " + - "{ADDITIONAL_CONDITIONS} "; - } - const SQL_BASE = sql_base_fragment("moz_places_temp") + - "UNION ALL " + - sql_base_fragment("moz_places") + - "AND +h.id NOT IN (SELECT id FROM moz_places_temp) " + - "ORDER BY h.frecency DESC, h.id DESC " + - "LIMIT :maxResults"; + const SQL_BASE = "SELECT h.url, h.title, f.url, " + kBookTagSQLFragment + ", " + + "h.visit_count, h.typed, h.id, :query_type, " + + "t.open_count " + + "FROM moz_places h " + + "LEFT JOIN moz_favicons f ON f.id = h.favicon_id " + + "LEFT JOIN moz_openpages_temp t ON t.place_id = h.id " + + "WHERE h.frecency <> 0 " + + "AND AUTOCOMPLETE_MATCH(:searchString, h.url, " + + "IFNULL(bookmark, h.title), tags, " + + "h.visit_count, h.typed, parent, " + + "t.open_count, " + + ":matchBehavior, :searchBehavior) " + + "{ADDITIONAL_CONDITIONS} " + + "ORDER BY h.frecency DESC, h.id DESC " + + "LIMIT :maxResults"; ////////////////////////////////////////////////////////////////////////////// //// Smart Getters @@ -269,42 +234,42 @@ function nsPlacesAutoComplete() XPCOMUtils.defineLazyGetter(this, "_defaultQuery", function() { let replacementText = ""; - return this._db.createStatement( + return this._db.createAsyncStatement( SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g") ); }); XPCOMUtils.defineLazyGetter(this, "_historyQuery", function() { let replacementText = "AND h.visit_count > 0"; - return this._db.createStatement( + return this._db.createAsyncStatement( SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g") ); }); XPCOMUtils.defineLazyGetter(this, "_bookmarkQuery", function() { let replacementText = "AND bookmark IS NOT NULL"; - return this._db.createStatement( + return this._db.createAsyncStatement( SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g") ); }); XPCOMUtils.defineLazyGetter(this, "_tagsQuery", function() { let replacementText = "AND tags IS NOT NULL"; - return this._db.createStatement( + return this._db.createAsyncStatement( SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g") ); }); XPCOMUtils.defineLazyGetter(this, "_openPagesQuery", function() { let replacementText = "AND t.open_count > 0"; - return this._db.createStatement( + return this._db.createAsyncStatement( SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g") ); }); XPCOMUtils.defineLazyGetter(this, "_typedQuery", function() { let replacementText = "AND h.typed = 1"; - return this._db.createStatement( + return this._db.createAsyncStatement( SQL_BASE.replace("{ADDITIONAL_CONDITIONS}", replacementText, "g") ); }); @@ -313,58 +278,55 @@ function nsPlacesAutoComplete() // In this query, we are taking kBookTagSQLFragment only for h.id because it // uses data from the moz_bookmarks table and we sync tables on bookmark // insert. So, most likely, h.id will always be populated when we have any - // bookmark. We still need to join on moz_places_temp for other data (eg. - // title). - return this._db.createStatement( - "/* do not warn (bug 487789) */ " + - "SELECT IFNULL(h_t.url, h.url) AS c_url, " + - "IFNULL(h_t.title, h.title) AS c_title, f.url, " + - kBookTagSQLFragment + ", " + - "IFNULL(h_t.visit_count, h.visit_count) AS c_visit_count, " + - "IFNULL(h_t.typed, h.typed) AS c_typed, " + - "IFNULL(h_t.id, h.id), :query_type, t.open_count, rank " + - "FROM ( " + - "SELECT ROUND(MAX(((i.input = :search_string) + " + - "(SUBSTR(i.input, 1, LENGTH(:search_string)) = :search_string)) * " + - "i.use_count), 1) AS rank, place_id " + - "FROM moz_inputhistory i " + - "GROUP BY i.place_id " + - "HAVING rank > 0 " + - ") AS i " + - "LEFT JOIN moz_places h ON h.id = i.place_id " + - "LEFT JOIN moz_places_temp h_t ON h_t.id = i.place_id " + - "LEFT JOIN moz_favicons f ON f.id = IFNULL(h_t.favicon_id, h.favicon_id) " + - "LEFT JOIN moz_openpages_temp t ON t.place_id = i.place_id " + - "WHERE c_url NOTNULL " + - "AND AUTOCOMPLETE_MATCH(:searchString, c_url, " + - "IFNULL(bookmark, c_title), tags, " + - "c_visit_count, c_typed, parent, " + - "t.open_count, " + - ":matchBehavior, :searchBehavior) " + - "ORDER BY rank DESC, IFNULL(h_t.frecency, h.frecency) DESC" + // bookmark. + return this._db.createAsyncStatement( + "/* do not warn (bug 487789) */ " + + "SELECT h.url, h.title, f.url, " + kBookTagSQLFragment + ", " + + "h.visit_count, h.typed, h.id, :query_type, t.open_count, rank " + + "FROM ( " + + "SELECT ROUND( " + + "MAX(((i.input = :search_string) + " + + "(SUBSTR(i.input, 1, LENGTH(:search_string)) = :search_string) " + + ") * i.use_count " + + ") , 1 " // Round at first decimal. + + ") AS rank, place_id " + + "FROM moz_inputhistory i " + + "GROUP BY i.place_id " + + "HAVING rank > 0 " + + ") AS i " + + "JOIN moz_places h ON h.id = i.place_id " + + "LEFT JOIN moz_favicons f ON f.id = h.favicon_id " + + "LEFT JOIN moz_openpages_temp t ON t.place_id = i.place_id " + + "WHERE AUTOCOMPLETE_MATCH(:searchString, h.url, " + + "IFNULL(bookmark, h.title), tags, " + + "h.visit_count, h.typed, parent, " + + "t.open_count, " + + ":matchBehavior, :searchBehavior) " + + "ORDER BY rank DESC, h.frecency DESC " ); }); XPCOMUtils.defineLazyGetter(this, "_keywordQuery", function() { - return this._db.createStatement( - "/* do not warn (bug 487787) */ " + - "SELECT IFNULL( " + - "(SELECT REPLACE(url, '%s', :query_string) FROM moz_places_temp WHERE id = b.fk), " + - "(SELECT REPLACE(url, '%s', :query_string) FROM moz_places WHERE id = b.fk) " + - ") AS search_url, IFNULL(h_t.title, h.title), " + - "COALESCE(f.url, " + best_favicon_for_revhost("moz_places_temp") + "," + - best_favicon_for_revhost("moz_places") + "), b.parent, " + - "b.title, NULL, IFNULL(h_t.visit_count, h.visit_count), " + - "IFNULL(h_t.typed, h.typed), COALESCE(h_t.id, h.id, b.fk), " + - ":query_type, t.open_count " + - "FROM moz_keywords k " + - "JOIN moz_bookmarks b ON b.keyword_id = k.id " + - "LEFT JOIN moz_places AS h ON h.url = search_url " + - "LEFT JOIN moz_places_temp AS h_t ON h_t.url = search_url " + - "LEFT JOIN moz_favicons f ON f.id = IFNULL(h_t.favicon_id, h.favicon_id) " + - "LEFT JOIN moz_openpages_temp t ON t.place_id = IFNULL(h_t.id, h.id) " + - "WHERE LOWER(k.keyword) = LOWER(:keyword) " + - "ORDER BY IFNULL(h_t.frecency, h.frecency) DESC" + return this._db.createAsyncStatement( + "/* do not warn (bug 487787) */ " + + "SELECT " + + "(SELECT REPLACE(url, '%s', :query_string) FROM moz_places WHERE id = b.fk) " + + "AS search_url, h.title, " + + "IFNULL(f.url, (SELECT f.url " + + "FROM moz_places " + + "JOIN moz_favicons f ON f.id = favicon_id " + + "WHERE rev_host = (SELECT rev_host FROM moz_places WHERE id = b.fk) " + + "ORDER BY frecency DESC " + + "LIMIT 1) " + + "), b.parent, b.title, NULL, h.visit_count, h.typed, IFNULL(h.id, b.fk), " + + ":query_type, t.open_count " + + "FROM moz_keywords k " + + "JOIN moz_bookmarks b ON b.keyword_id = k.id " + + "LEFT JOIN moz_places h ON h.url = search_url " + + "LEFT JOIN moz_favicons f ON f.id = h.favicon_id " + + "LEFT JOIN moz_openpages_temp t ON t.place_id = h.id " + + "WHERE LOWER(k.keyword) = LOWER(:keyword) " + + "ORDER BY h.frecency DESC " ); }); diff --git a/toolkit/components/places/src/nsPlacesDBFlush.js b/toolkit/components/places/src/nsPlacesDBFlush.js deleted file mode 100644 index e797b9b2721..00000000000 --- a/toolkit/components/places/src/nsPlacesDBFlush.js +++ /dev/null @@ -1,399 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Shawn Wilsher (Original Author) - * Marco Bonardo - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -//////////////////////////////////////////////////////////////////////////////// -//// Constants - -const Cc = Components.classes; -const Ci = Components.interfaces; -const Cr = Components.results; -const Cu = Components.utils; - -// Use places-teardown to ensure we run last in the shutdown process. -// Any other implementer should use places-shutdown instead, since teardown is -// where things really break. -const kTopicShutdown = "places-teardown"; -const kSyncFinished = "places-sync-finished"; -const kDebugStopSync = "places-debug-stop-sync"; -const kDebugStartSync = "places-debug-start-sync"; - -const kSyncPrefName = "places.syncDBTableIntervalInSecs"; -const kDefaultSyncInterval = 120; - -// Query Constants. These describe the queries we use. -const kQuerySyncPlacesId = 0; -const kQuerySyncHistoryVisitsId = 1; - -//////////////////////////////////////////////////////////////////////////////// -//// Modules - -Cu.import("resource://gre/modules/XPCOMUtils.jsm"); -Cu.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/PlacesUtils.jsm"); - -//////////////////////////////////////////////////////////////////////////////// -//// nsPlacesDBFlush class - -function nsPlacesDBFlush() -{ - // Get our sync interval - try { - // We want to silently fail since getIntPref throws if it does not exist, - // and use a default to fallback to. - this._syncInterval = Services.prefs.getIntPref(kSyncPrefName); - if (this._syncInterval <= 0) - this._syncInterval = kDefaultSyncInterval; - } - catch (e) { - // The preference did not exist, so use the default. - this._syncInterval = kDefaultSyncInterval; - } - - // Register observers - Services.obs.addObserver(this, kTopicShutdown, false); - Services.obs.addObserver(this, kDebugStopSync, false); - Services.obs.addObserver(this, kDebugStartSync, false); - - let (pb2 = Services.prefs.QueryInterface(Ci.nsIPrefBranch2)) - pb2.addObserver(kSyncPrefName, this, false); - - // Create our timer to update everything - this._timer = this._newTimer(); - - ////////////////////////////////////////////////////////////////////////////// - //// Smart Getters - - XPCOMUtils.defineLazyGetter(this, "_db", function() { - return PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase) - .DBConnection; - }); -} - -nsPlacesDBFlush.prototype = { - ////////////////////////////////////////////////////////////////////////////// - //// nsIObserver - - observe: function DBFlush_observe(aSubject, aTopic, aData) - { - if (aTopic == kTopicShutdown) { - Services.obs.removeObserver(this, kTopicShutdown); - Services.obs.removeObserver(this, kDebugStopSync); - Services.obs.removeObserver(this, kDebugStartSync); - - let (pb2 = Services.prefs.QueryInterface(Ci.nsIPrefBranch2)) - pb2.removeObserver(kSyncPrefName, this); - - if (this._timer) { - this._timer.cancel(); - this._timer = null; - } - - // Other components could still make changes to history at this point, - // for example to clear private data on shutdown, so here we dispatch - // an event to the main thread so that we will sync after - // Places shutdown ensuring all data have been saved. - Services.tm.mainThread.dispatch({ - _self: this, - run: function() { - // Flush any remaining change to disk tables. - this._self._flushWithQueries([kQuerySyncPlacesId, kQuerySyncHistoryVisitsId]); - - // Close the database connection, this was the last sync and we can't - // ensure database coherence from now on. - this._self._finalizeInternalStatements(); - this._self._db.asyncClose(); - } - }, Ci.nsIThread.DISPATCH_NORMAL); - } - else if (aTopic == "nsPref:changed" && aData == kSyncPrefName) { - // Get the new pref value, and then update our timer - this._syncInterval = Services.prefs.getIntPref(kSyncPrefName); - if (this._syncInterval <= 0) - this._syncInterval = kDefaultSyncInterval; - - // We may have canceled the timer already for batch updates, so we want to - // exit early. - if (!this._timer) - return; - - this._timer.cancel(); - this._timer = this._newTimer(); - } - else if (aTopic == kDebugStopSync) { - this._syncStopped = true; - } - else if (aTopic == kDebugStartSync) { - if (_syncStopped in this) - delete this._syncStopped; - } - }, - - ////////////////////////////////////////////////////////////////////////////// - //// nsINavBookmarkObserver - - onBeginUpdateBatch: function DBFlush_onBeginUpdateBatch() - { - this._inBatchMode = true; - - // We do not want to sync while we are doing batch work. - this._timer.cancel(); - this._timer = null; - }, - - onEndUpdateBatch: function DBFlush_onEndUpdateBatch() - { - this._inBatchMode = false; - - // Restore our timer - this._timer = this._newTimer(); - - // We need to sync now - this._flushWithQueries([kQuerySyncPlacesId, kQuerySyncHistoryVisitsId]); - }, - - onItemAdded: function(aItemId, aParentId, aIndex, aItemType) - { - // Sync only if we added a TYPE_BOOKMARK item. Note, we want to run the - // least amount of queries as possible here for performance reasons. - if (!this._inBatchMode && aItemType == PlacesUtils.bookmarks.TYPE_BOOKMARK) - this._flushWithQueries([kQuerySyncPlacesId]); - }, - - onItemChanged: function DBFlush_onItemChanged(aItemId, aProperty, - aIsAnnotationProperty, - aNewValue, aLastModified, - aItemType) - { - if (!this._inBatchMode && aProperty == "uri") - this._flushWithQueries([kQuerySyncPlacesId]); - }, - - onBeforeItemRemoved: function() { }, - onItemRemoved: function() { }, - onItemVisited: function() { }, - onItemMoved: function() { }, - - ////////////////////////////////////////////////////////////////////////////// - //// nsINavHistoryObserver - - // We currently only use the history observer to know when the history service - // is activated. At that point, we actually get initialized, and our timer - // to sync history is added. - - // These methods share the name of the ones on nsINavBookmarkObserver, so - // the implementations can be found above. - //onBeginUpdateBatch: function() { }, - //onEndUpdateBatch: function() { }, - onVisit: function() { }, - onTitleChanged: function() { }, - onBeforeDeleteURI: function() { }, - onDeleteURI: function() { }, - onClearHistory: function() { }, - onPageChanged: function() { }, - onDeleteVisits: function() { }, - - ////////////////////////////////////////////////////////////////////////////// - //// nsITimerCallback - - notify: function DBFlush_timerCallback() - { - let queries = [ - kQuerySyncPlacesId, - kQuerySyncHistoryVisitsId, - ]; - this._flushWithQueries(queries); - }, - - ////////////////////////////////////////////////////////////////////////////// - //// mozIStorageStatementCallback - - handleResult: function DBFlush_handleResult(aResultSet) - { - }, - - handleError: function DBFlush_handleError(aError) - { - Cu.reportError("Async statement execution returned with '" + - aError.result + "', '" + aError.message + "'"); - }, - - handleCompletion: function DBFlush_handleCompletion(aReason) - { - if (aReason == Ci.mozIStorageStatementCallback.REASON_FINISHED) { - // Dispatch a notification that sync has finished. - Services.obs.notifyObservers(null, kSyncFinished, null); - } - }, - - ////////////////////////////////////////////////////////////////////////////// - //// nsPlacesDBFlush - _syncInterval: kDefaultSyncInterval, - - /** - * Execute async statements to flush tables with the specified queries. - * - * @param aQueryNames - * The names of the queries to use with this flush. - */ - _flushWithQueries: function DBFlush_flushWithQueries(aQueryNames) - { - // No need to do extra work if we are in batch mode - if (this._inBatchMode || this._syncStopped) - return; - - let statements = []; - for (let i = 0; i < aQueryNames.length; i++) - statements.push(this._getQuery(aQueryNames[i])); - - // Execute sync statements async in a transaction - this._db.executeAsync(statements, statements.length, this); - }, - - /** - * Finalizes all of our mozIStorageStatements so we can properly close the - * database. - */ - _finalizeInternalStatements: function DBFlush_finalizeInternalStatements() - { - this._cachedStatements.forEach(function(stmt) { - if (stmt instanceof Ci.mozIStorageAsyncStatement) - stmt.finalize(); - }); - }, - - /** - * Generate the statement to synchronizes the moz_{aTableName} and - * moz_{aTableName}_temp by copying all the data from the temporary table - * into the permanent one. - * Most of the work is done through triggers defined in nsPlacesTriggers.h, - * they sync back to disk, then delete the data in the temporary table. - * - * @param aQueryType - * Type of the query to build statement for. - */ - _cachedStatements: [], - _getQuery: function DBFlush_getQuery(aQueryType) - { - // Statement creating can be expensive, so always cache if we can. - if (aQueryType in this._cachedStatements) { - let stmt = this._cachedStatements[aQueryType]; - - // Bind the appropriate parameters. - let params = stmt.params; - switch (aQueryType) { - case kQuerySyncHistoryVisitsId: - case kQuerySyncPlacesId: - params.transition_type = Ci.nsINavHistoryService.TRANSITION_EMBED; - break; - } - - return stmt; - } - - switch(aQueryType) { - case kQuerySyncHistoryVisitsId: - // For history table we want to leave embed visits in memory, since - // those are expired with current session, so we are filtering them out. - // Notice that instead we _want_ to sync framed_link visits, since those - // come from user's actions. - this._cachedStatements[aQueryType] = this._db.createAsyncStatement( - "DELETE FROM moz_historyvisits_temp " + - "WHERE visit_type <> :transition_type" - ); - break; - - case kQuerySyncPlacesId: - // For places table we want to leave places associated with embed visits - // in memory, they usually have hidden = 1 and at least an embed visit - // in historyvisits_temp table. - this._cachedStatements[aQueryType] = this._db.createAsyncStatement( - "DELETE FROM moz_places_temp " + - "WHERE id IN ( " + - "SELECT id FROM moz_places_temp h " + - "WHERE h.hidden <> 1 OR NOT EXISTS ( " + - "SELECT id FROM moz_historyvisits_temp " + - "WHERE place_id = h.id AND visit_type = :transition_type " + - "LIMIT 1 " + - ") " + - ")" - ); - break; - - default: - throw "Unexpected statement!"; - } - - // We only bind our own parameters when we have a cached statement, so we - // call ourself since we now have a cached statement. - return this._getQuery(aQueryType); - }, - - /** - * Creates a new timer based on this._syncInterval. - * - * @returns a REPEATING_SLACK nsITimer that runs every this._syncInterval. - */ - _newTimer: function DBFlush_newTimer() - { - let timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); - timer.initWithCallback(this, this._syncInterval * 1000, - Ci.nsITimer.TYPE_REPEATING_SLACK); - return timer; - }, - - ////////////////////////////////////////////////////////////////////////////// - //// nsISupports - - classID: Components.ID("c1751cfc-e8f1-4ade-b0bb-f74edfb8ef6a"), - - QueryInterface: XPCOMUtils.generateQI([ - Ci.nsIObserver, - Ci.nsINavBookmarkObserver, - Ci.nsINavHistoryObserver, - Ci.nsITimerCallback, - Ci.mozIStorageStatementCallback, - ]) -}; - -//////////////////////////////////////////////////////////////////////////////// -//// Module Registration - -let components = [nsPlacesDBFlush]; -var NSGetFactory = XPCOMUtils.generateNSGetFactory(components); diff --git a/toolkit/components/places/src/nsPlacesExpiration.js b/toolkit/components/places/src/nsPlacesExpiration.js index 64e211f5e8b..b2c543b3db8 100644 --- a/toolkit/components/places/src/nsPlacesExpiration.js +++ b/toolkit/components/places/src/nsPlacesExpiration.js @@ -210,23 +210,10 @@ const EXPIRATION_QUERIES = { QUERY_FIND_VISITS_TO_EXPIRE: { sql: "INSERT INTO expiration_notify " + "(v_id, url, visit_date, expected_results) " - + "SELECT v.id, IFNULL(h_t.url, h.url) AS url, " - + "v.visit_date AS visit_date, " - + ":limit_visits AS expected_results " - + "FROM moz_historyvisits_temp v " - + "LEFT JOIN moz_places_temp AS h_t ON h_t.id = v.place_id " - + "LEFT JOIN moz_places AS h ON h.id = v.place_id " - + "WHERE ((SELECT COUNT(*) FROM moz_places_temp) + " - + "(SELECT COUNT(*) FROM moz_places)) > :max_uris " - + "UNION ALL " - + "SELECT v.id, IFNULL(h_t.url, h.url) AS url, " - + "v.visit_date AS visit_date, " - + ":limit_visits AS expected_results " + + "SELECT v.id, h.url, v.visit_date, :limit_visits " + "FROM moz_historyvisits v " - + "LEFT JOIN moz_places_temp AS h_t ON h_t.id = v.place_id " - + "LEFT JOIN moz_places AS h ON h.id = v.place_id " - + "WHERE ((SELECT COUNT(*) FROM moz_places_temp) + " - + "(SELECT COUNT(*) FROM moz_places)) > :max_uris " + + "JOIN moz_places h ON h.id = v.place_id " + + "WHERE (SELECT COUNT(*) FROM moz_places) > :max_uris " + "ORDER BY v.visit_date ASC " + "LIMIT :limit_visits", actions: ACTION.TIMED_OVERLIMIT | ACTION.SHUTDOWN | ACTION.IDLE | @@ -235,7 +222,7 @@ const EXPIRATION_QUERIES = { // Removes the previously found visits. QUERY_EXPIRE_VISITS: { - sql: "DELETE FROM moz_historyvisits_view WHERE id IN ( " + sql: "DELETE FROM moz_historyvisits WHERE id IN ( " + "SELECT v_id FROM expiration_notify WHERE v_id NOTNULL " + ")", actions: ACTION.TIMED_OVERLIMIT | ACTION.SHUTDOWN | ACTION.IDLE | @@ -248,26 +235,13 @@ const EXPIRATION_QUERIES = { QUERY_FIND_URIS_TO_EXPIRE: { sql: "INSERT INTO expiration_notify " + "(p_id, url, visit_date, expected_results) " - + "SELECT h.id, h.url, h.last_visit_date AS visit_date, " - + ":limit_uris AS expected_results " - + "FROM moz_places_temp h " - + "LEFT JOIN moz_historyvisits v ON h.id = v.place_id " - + "LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id " - + "LEFT JOIN moz_bookmarks b ON h.id = b.fk " - + "WHERE v.id IS NULL " - + "AND v_t.id IS NULL " - + "AND b.id IS NULL " - + "AND h.ROWID <> IFNULL(:null_skips_last, (SELECT MAX(ROWID) FROM moz_places_temp)) " - + "UNION ALL " - + "SELECT h.id, h.url, h.last_visit_date AS visit_date, " - + ":limit_uris AS expected_results " + + "SELECT h.id, h.url, h.last_visit_date, :limit_uris " + "FROM moz_places h " + "LEFT JOIN moz_historyvisits v ON h.id = v.place_id " - + "LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id " + "LEFT JOIN moz_bookmarks b ON h.id = b.fk " + "WHERE v.id IS NULL " - + "AND v_t.id IS NULL " + "AND b.id IS NULL " + + "AND h.ROWID <> IFNULL(:null_skips_last, (SELECT MAX(ROWID) FROM moz_places)) " + "LIMIT :limit_uris", actions: ACTION.TIMED | ACTION.TIMED_OVERLIMIT | ACTION.SHUTDOWN | ACTION.IDLE | ACTION.DEBUG @@ -275,7 +249,7 @@ const EXPIRATION_QUERIES = { // Expire found URIs from the database. QUERY_EXPIRE_URIS: { - sql: "DELETE FROM moz_places_view WHERE id IN ( " + sql: "DELETE FROM moz_places WHERE id IN ( " + "SELECT p_id FROM expiration_notify WHERE p_id NOTNULL " + ")", actions: ACTION.TIMED | ACTION.TIMED_OVERLIMIT | ACTION.SHUTDOWN | @@ -284,26 +258,13 @@ const EXPIRATION_QUERIES = { // Expire orphan URIs from the database. QUERY_SILENT_EXPIRE_ORPHAN_URIS: { - sql: "DELETE FROM moz_places_view WHERE id IN ( " - + "SELECT h.id " - + "FROM moz_places_temp h " - + "LEFT JOIN moz_historyvisits v ON h.id = v.place_id " - + "LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id " - + "LEFT JOIN moz_bookmarks b ON h.id = b.fk " - + "WHERE v.id IS NULL " - + "AND v_t.id IS NULL " - + "AND b.id IS NULL " - + "AND SUBSTR(h.url, 1, 6) <> 'place:' " - + "UNION ALL " + sql: "DELETE FROM moz_places WHERE id IN ( " + "SELECT h.id " + "FROM moz_places h " + "LEFT JOIN moz_historyvisits v ON h.id = v.place_id " - + "LEFT JOIN moz_historyvisits_temp v_t ON h.id = v_t.place_id " + "LEFT JOIN moz_bookmarks b ON h.id = b.fk " + "WHERE v.id IS NULL " - + "AND v_t.id IS NULL " + "AND b.id IS NULL " - + "AND SUBSTR(h.url, 1, 6) <> 'place:' " + "LIMIT :limit_uris " + ")", actions: ACTION.CLEAR_HISTORY @@ -314,9 +275,7 @@ const EXPIRATION_QUERIES = { sql: "DELETE FROM moz_favicons WHERE id IN ( " + "SELECT f.id FROM moz_favicons f " + "LEFT JOIN moz_places h ON f.id = h.favicon_id " - + "LEFT JOIN moz_places_temp h_t ON f.id = h_t.favicon_id " + "WHERE h.favicon_id IS NULL " - + "AND h_t.favicon_id IS NULL " + "LIMIT :limit_favicons " + ")", actions: ACTION.TIMED | ACTION.TIMED_OVERLIMIT | ACTION.CLEAR_HISTORY | @@ -328,12 +287,9 @@ const EXPIRATION_QUERIES = { sql: "DELETE FROM moz_annos WHERE id in ( " + "SELECT a.id FROM moz_annos a " + "LEFT JOIN moz_places h ON a.place_id = h.id " - + "LEFT JOIN moz_places_temp h_t ON a.place_id = h_t.id " + "LEFT JOIN moz_historyvisits v ON a.place_id = v.place_id " - + "LEFT JOIN moz_historyvisits_temp v_t ON a.place_id = v_t.place_id " - + "WHERE (h.id IS NULL AND h_t.id IS NULL) " - + "OR (v.id IS NULL AND v_t.id IS NULL AND " - + "a.expiration <> :expire_never) " + + "WHERE h.id IS NULL " + + "OR (v.id IS NULL AND a.expiration <> :expire_never) " + "LIMIT :limit_annos " + ")", actions: ACTION.TIMED | ACTION.TIMED_OVERLIMIT | ACTION.CLEAR_HISTORY | @@ -370,8 +326,6 @@ const EXPIRATION_QUERIES = { QUERY_EXPIRE_ANNOS_WITH_HISTORY: { sql: "DELETE FROM moz_annos " + "WHERE expiration = :expire_with_history " - + "AND NOT EXISTS (SELECT id FROM moz_historyvisits_temp " - + "WHERE place_id = moz_annos.place_id LIMIT 1) " + "AND NOT EXISTS (SELECT id FROM moz_historyvisits " + "WHERE place_id = moz_annos.place_id LIMIT 1)", actions: ACTION.TIMED | ACTION.TIMED_OVERLIMIT | ACTION.CLEAR_HISTORY | @@ -407,9 +361,7 @@ const EXPIRATION_QUERIES = { sql: "DELETE FROM moz_inputhistory WHERE place_id IN ( " + "SELECT i.place_id FROM moz_inputhistory i " + "LEFT JOIN moz_places h ON h.id = i.place_id " - + "LEFT JOIN moz_places_temp h_t ON h_t.id = i.place_id " + "WHERE h.id IS NULL " - + "AND h_t.id IS NULL " + "LIMIT :limit_inputhistory " + ")", actions: ACTION.CLEAR_HISTORY | ACTION.SHUTDOWN | ACTION.IDLE | ACTION.DEBUG @@ -522,8 +474,8 @@ nsPlacesExpiration.prototype = { this._timer = null; } - // We must be sure to run after all other shutdown observers (but DBFlush) - // thus we enqueue the calls. + // We must be sure to run after all other shutdown observers thus we + // enqueue the calls. let self = this; Services.tm.mainThread.dispatch({ run: function() { @@ -617,8 +569,7 @@ nsPlacesExpiration.prototype = { // Check if we are over history capacity, if so visits must be expired. if (!this._cachedStatements["LIMIT_COUNT"]) { this._cachedStatements["LIMIT_COUNT"] = this._db.createAsyncStatement( - "SELECT (SELECT COUNT(*) FROM moz_places_temp) + " - + "(SELECT COUNT(*) FROM moz_places)" + "SELECT COUNT(*) FROM moz_places" ); } let self = this; diff --git a/toolkit/components/places/src/nsPlacesIndexes.h b/toolkit/components/places/src/nsPlacesIndexes.h index 7b9bb896906..131cc7bd4dc 100644 --- a/toolkit/components/places/src/nsPlacesIndexes.h +++ b/toolkit/components/places/src/nsPlacesIndexes.h @@ -49,55 +49,31 @@ /** * moz_places */ -#define CREATE_IDX_MOZ_PLACES_TEMP_URL \ - CREATE_PLACES_IDX( \ - "url_uniqueindex", "moz_places_temp", "url", "UNIQUE" \ - ) #define CREATE_IDX_MOZ_PLACES_URL \ CREATE_PLACES_IDX( \ "url_uniqueindex", "moz_places", "url", "UNIQUE" \ ) -#define CREATE_IDX_MOZ_PLACES_TEMP_FAVICON \ - CREATE_PLACES_IDX( \ - "faviconindex", "moz_places_temp", "favicon_id", "" \ - ) #define CREATE_IDX_MOZ_PLACES_FAVICON \ CREATE_PLACES_IDX( \ "faviconindex", "moz_places", "favicon_id", "" \ ) -#define CREATE_IDX_MOZ_PLACES_TEMP_REVHOST \ - CREATE_PLACES_IDX( \ - "hostindex", "moz_places_temp", "rev_host", "" \ - ) #define CREATE_IDX_MOZ_PLACES_REVHOST \ CREATE_PLACES_IDX( \ "hostindex", "moz_places", "rev_host", "" \ ) -#define CREATE_IDX_MOZ_PLACES_TEMP_VISITCOUNT \ - CREATE_PLACES_IDX( \ - "visitcount", "moz_places_temp", "visit_count", "" \ - ) #define CREATE_IDX_MOZ_PLACES_VISITCOUNT \ CREATE_PLACES_IDX( \ "visitcount", "moz_places", "visit_count", "" \ ) -#define CREATE_IDX_MOZ_PLACES_TEMP_FRECENCY \ - CREATE_PLACES_IDX( \ - "frecencyindex", "moz_places_temp", "frecency", "" \ - ) #define CREATE_IDX_MOZ_PLACES_FRECENCY \ CREATE_PLACES_IDX( \ "frecencyindex", "moz_places", "frecency", "" \ ) -#define CREATE_IDX_MOZ_PLACES_TEMP_LASTVISITDATE \ - CREATE_PLACES_IDX( \ - "lastvisitdateindex", "moz_places_temp", "last_visit_date", "" \ - ) #define CREATE_IDX_MOZ_PLACES_LASTVISITDATE \ CREATE_PLACES_IDX( \ "lastvisitdateindex", "moz_places", "last_visit_date", "" \ @@ -107,28 +83,16 @@ * moz_historyvisits */ -#define CREATE_IDX_MOZ_HISTORYVISITS_TEMP_PLACEDATE \ - CREATE_PLACES_IDX( \ - "placedateindex", "moz_historyvisits_temp", "place_id, visit_date", "" \ - ) #define CREATE_IDX_MOZ_HISTORYVISITS_PLACEDATE \ CREATE_PLACES_IDX( \ "placedateindex", "moz_historyvisits", "place_id, visit_date", "" \ ) -#define CREATE_IDX_MOZ_HISTORYVISITS_TEMP_FROMVISIT \ - CREATE_PLACES_IDX( \ - "fromindex", "moz_historyvisits_temp", "from_visit", "" \ - ) #define CREATE_IDX_MOZ_HISTORYVISITS_FROMVISIT \ CREATE_PLACES_IDX( \ "fromindex", "moz_historyvisits", "from_visit", "" \ ) -#define CREATE_IDX_MOZ_HISTORYVISITS_TEMP_VISITDATE \ - CREATE_PLACES_IDX( \ - "dateindex", "moz_historyvisits_temp", "visit_date", "" \ - ) #define CREATE_IDX_MOZ_HISTORYVISITS_VISITDATE \ CREATE_PLACES_IDX( \ "dateindex", "moz_historyvisits", "visit_date", "" \ diff --git a/toolkit/components/places/src/nsPlacesTables.h b/toolkit/components/places/src/nsPlacesTables.h index a77fb7e3919..4528b744dfe 100644 --- a/toolkit/components/places/src/nsPlacesTables.h +++ b/toolkit/components/places/src/nsPlacesTables.h @@ -40,8 +40,9 @@ #ifndef __nsPlacesTables_h__ #define __nsPlacesTables_h__ -#define CREATE_MOZ_PLACES_BASE(__name, __temporary) NS_LITERAL_CSTRING( \ - "CREATE " __temporary " TABLE " __name " ( " \ + +#define CREATE_MOZ_PLACES NS_LITERAL_CSTRING( \ + "CREATE TABLE moz_places ( " \ " id INTEGER PRIMARY KEY" \ ", url LONGVARCHAR" \ ", title LONGVARCHAR" \ @@ -54,22 +55,12 @@ ", last_visit_date INTEGER " \ ")" \ ) -#define CREATE_MOZ_PLACES CREATE_MOZ_PLACES_BASE("moz_places", "") -#define CREATE_MOZ_PLACES_TEMP CREATE_MOZ_PLACES_BASE("moz_places_temp", "TEMP") #define MOZ_PLACES_COLUMNS \ "id, url, title, rev_host, visit_count, hidden, typed, favicon_id, " \ "frecency, last_visit_date" -#define CREATE_MOZ_PLACES_VIEW NS_LITERAL_CSTRING( \ - "CREATE TEMPORARY VIEW moz_places_view AS " \ - "SELECT " MOZ_PLACES_COLUMNS " FROM moz_places_temp " \ - "UNION ALL " \ - "SELECT " MOZ_PLACES_COLUMNS " FROM moz_places " \ - "WHERE id NOT IN (SELECT id FROM moz_places_temp) " \ -) - -#define CREATE_MOZ_HISTORYVISITS_BASE(__name, __temporary) NS_LITERAL_CSTRING( \ - "CREATE " __temporary " TABLE " __name " (" \ +#define CREATE_MOZ_HISTORYVISITS NS_LITERAL_CSTRING( \ + "CREATE TABLE moz_historyvisits (" \ " id INTEGER PRIMARY KEY" \ ", from_visit INTEGER" \ ", place_id INTEGER" \ @@ -78,19 +69,9 @@ ", session INTEGER" \ ")" \ ) -#define CREATE_MOZ_HISTORYVISITS \ - CREATE_MOZ_HISTORYVISITS_BASE("moz_historyvisits", "") -#define CREATE_MOZ_HISTORYVISITS_TEMP \ - CREATE_MOZ_HISTORYVISITS_BASE("moz_historyvisits_temp", "TEMP") #define MOZ_HISTORYVISITS_COLUMNS \ "id, from_visit, place_id, visit_date, visit_type, session" -#define CREATE_MOZ_HISTORYVISITS_VIEW NS_LITERAL_CSTRING( \ - "CREATE TEMPORARY VIEW moz_historyvisits_view AS " \ - "SELECT " MOZ_HISTORYVISITS_COLUMNS " FROM moz_historyvisits_temp " \ - "UNION ALL " \ - "SELECT " MOZ_HISTORYVISITS_COLUMNS " FROM moz_historyvisits " \ - "WHERE id NOT IN (SELECT id FROM moz_historyvisits_temp) " \ -) + #define CREATE_MOZ_INPUTHISTORY NS_LITERAL_CSTRING( \ "CREATE TABLE moz_inputhistory (" \ diff --git a/toolkit/components/places/src/nsPlacesTriggers.h b/toolkit/components/places/src/nsPlacesTriggers.h index 2737bc8d43e..653a00b205e 100644 --- a/toolkit/components/places/src/nsPlacesTriggers.h +++ b/toolkit/components/places/src/nsPlacesTriggers.h @@ -72,194 +72,35 @@ "END" \ ) -/** - * This trigger allows for an insertion into moz_places_view. It enters the new - * data into the temporary table, ensuring that the new id is one greater than - * the largest id value found. - */ -#define CREATE_PLACES_VIEW_INSERT_TRIGGER NS_LITERAL_CSTRING( \ - "CREATE TEMPORARY TRIGGER moz_places_view_insert_trigger " \ - "INSTEAD OF INSERT " \ - "ON moz_places_view " \ - "BEGIN " \ - "INSERT INTO moz_places_temp (" MOZ_PLACES_COLUMNS ") " \ - "VALUES (MAX(IFNULL((SELECT MAX(id) FROM moz_places_temp), 0), " \ - "IFNULL((SELECT MAX(id) FROM moz_places), 0)) + 1," \ - "NEW.url, NEW.title, NEW.rev_host, " \ - "IFNULL(NEW.visit_count, 0), " /* enforce having a value */ \ - "NEW.hidden, NEW.typed, NEW.favicon_id, NEW.frecency, " \ - "NEW.last_visit_date);" \ - "END" \ -) /** - * This trigger allows for the deletion of a record in moz_places_view. It - * removes any entry in the temporary table, the permanent table, and any - * associated entry in moz_openpages_temp. + * This triggers update visit_count and last_visit_date based on historyvisits + * table changes. */ -#define CREATE_PLACES_VIEW_DELETE_TRIGGER NS_LITERAL_CSTRING( \ - "CREATE TEMPORARY TRIGGER moz_places_view_delete_trigger " \ - "INSTEAD OF DELETE " \ - "ON moz_places_view " \ +#define CREATE_HISTORYVISITS_AFTERINSERT_TRIGGER NS_LITERAL_CSTRING( \ + "CREATE TRIGGER moz_historyvisits_afterinsert_v2_trigger " \ + "AFTER INSERT ON moz_historyvisits FOR EACH ROW " \ "BEGIN " \ - "DELETE FROM moz_places_temp " \ - "WHERE id = OLD.id; " \ - "DELETE FROM moz_places " \ - "WHERE id = OLD.id; " \ - "DELETE FROM moz_openpages_temp " \ - "WHERE place_id = OLD.id; " \ - "END" \ -) - -/** - * This trigger allows for updates to a record in moz_places_view. It first - * copies the row from the permanent table over to the temp table if it does not - * exist in the temporary table. Then, it will update the temporary table with - * the new data. - * We use INSERT OR IGNORE to avoid looking if the place already exists in the - * temp table. - */ -#define CREATE_PLACES_VIEW_UPDATE_TRIGGER NS_LITERAL_CSTRING( \ - "CREATE TEMPORARY TRIGGER moz_places_view_update_trigger " \ - "INSTEAD OF UPDATE " \ - "ON moz_places_view " \ - "BEGIN " \ - "INSERT OR IGNORE INTO moz_places_temp (" MOZ_PLACES_COLUMNS ") " \ - "SELECT " MOZ_PLACES_COLUMNS " FROM moz_places " \ - "WHERE id = OLD.id; " \ - "UPDATE moz_places_temp " \ - "SET url = IFNULL(NEW.url, OLD.url), " \ - "title = IFNULL(NEW.title, OLD.title), " \ - "rev_host = IFNULL(NEW.rev_host, OLD.rev_host), " \ - "visit_count = IFNULL(NEW.visit_count, OLD.visit_count), " \ - "hidden = IFNULL(NEW.hidden, OLD.hidden), " \ - "typed = IFNULL(NEW.typed, OLD.typed), " \ - "favicon_id = IFNULL(NEW.favicon_id, OLD.favicon_id), " \ - "frecency = IFNULL(NEW.frecency, OLD.frecency), " \ - "last_visit_date = IFNULL(NEW.last_visit_date, OLD.last_visit_date) " \ - "WHERE id = OLD.id; " \ - "END" \ -) - -/** - * This trigger allows for an insertion into moz_historyvisits_view. It enters - * the new data into the temporary table, ensuring that the new id is one - * greater than the largest id value found. It then updates moz_places_view - * with the new visit count. - * We use INSERT OR IGNORE to avoid looking if the place already exists in the - * temp table. - * In this case when updating last_visit_date we can simply check the maximum - * between new visit date and the actual cached value (or 0 if it is NULL). - */ -#define CREATE_HISTORYVISITS_VIEW_INSERT_TRIGGER NS_LITERAL_CSTRING( \ - "CREATE TEMPORARY TRIGGER moz_historyvisits_view_insert_trigger " \ - "INSTEAD OF INSERT " \ - "ON moz_historyvisits_view " \ - "BEGIN " \ - "INSERT INTO moz_historyvisits_temp (" MOZ_HISTORYVISITS_COLUMNS ") " \ - "VALUES (MAX(IFNULL((SELECT MAX(id) FROM moz_historyvisits_temp), 0), " \ - "IFNULL((SELECT MAX(id) FROM moz_historyvisits), 0)) + 1, " \ - "NEW.from_visit, NEW.place_id, NEW.visit_date, NEW.visit_type, " \ - "NEW.session); " \ - "INSERT OR IGNORE INTO moz_places_temp (" MOZ_PLACES_COLUMNS ") " \ - "SELECT " MOZ_PLACES_COLUMNS " FROM moz_places " \ - "WHERE id = NEW.place_id " \ - "AND NEW.visit_type NOT IN (" EXCLUDED_VISIT_TYPES "); " \ - "UPDATE moz_places_temp " \ - "SET visit_count = visit_count + 1 " \ - "WHERE id = NEW.place_id " \ - "AND NEW.visit_type NOT IN (" EXCLUDED_VISIT_TYPES "); " \ - "UPDATE moz_places_temp " \ - "SET last_visit_date = MAX(IFNULL(last_visit_date, 0), NEW.visit_date)" \ + "UPDATE moz_places SET " \ + "visit_count = visit_count + (SELECT NEW.visit_type NOT IN (" EXCLUDED_VISIT_TYPES ")), "\ + "last_visit_date = MAX(IFNULL(last_visit_date, 0), NEW.visit_date) " \ "WHERE id = NEW.place_id;" \ "END" \ ) -/** - * This trigger allows for the deletion of a record in moz_historyvisits_view. - * It removes any entry in the temporary table, and removes any entry in the - * permanent table as well. It then updates moz_places_view with the new visit - * count. - * We use INSERT OR IGNORE to avoid looking if the place already exists in the - * temp table. - */ -#define CREATE_HISTORYVISITS_VIEW_DELETE_TRIGGER NS_LITERAL_CSTRING( \ - "CREATE TEMPORARY TRIGGER moz_historyvisits_view_delete_trigger " \ - "INSTEAD OF DELETE " \ - "ON moz_historyvisits_view " \ +#define CREATE_HISTORYVISITS_AFTERDELETE_TRIGGER NS_LITERAL_CSTRING( \ + "CREATE TRIGGER moz_historyvisits_afterdelete_v2_trigger " \ + "AFTER DELETE ON moz_historyvisits FOR EACH ROW " \ "BEGIN " \ - "DELETE FROM moz_historyvisits_temp " \ - "WHERE id = OLD.id; " \ - "DELETE FROM moz_historyvisits " \ - "WHERE id = OLD.id; " \ - "INSERT OR IGNORE INTO moz_places_temp (" MOZ_PLACES_COLUMNS ") " \ - "SELECT " MOZ_PLACES_COLUMNS " FROM moz_places " \ - "WHERE id = OLD.place_id " \ - "AND OLD.visit_type NOT IN (" EXCLUDED_VISIT_TYPES "); " \ - "UPDATE moz_places_temp " \ - "SET visit_count = visit_count - 1 " \ - "WHERE id = OLD.place_id " \ - "AND OLD.visit_type NOT IN (" EXCLUDED_VISIT_TYPES "); " \ - "UPDATE moz_places_temp " \ - "SET last_visit_date = " \ - "(SELECT visit_date FROM moz_historyvisits_temp " \ - "WHERE place_id = OLD.place_id " \ - "UNION ALL " \ - "SELECT visit_date FROM moz_historyvisits " \ - "WHERE place_id = OLD.place_id " \ - "ORDER BY visit_date DESC LIMIT 1) " \ - "WHERE id = OLD.place_id; " \ + "UPDATE moz_places SET " \ + "visit_count = visit_count - (SELECT OLD.visit_type NOT IN (" EXCLUDED_VISIT_TYPES ")), "\ + "last_visit_date = (SELECT visit_date FROM moz_historyvisits " \ + "WHERE place_id = OLD.place_id " \ + "ORDER BY visit_date DESC LIMIT 1) " \ + "WHERE id = OLD.place_id;" \ "END" \ ) -/** - * This trigger allows for updates to a record in moz_historyvisits_view. It - * first copies the row from the permanent table over to the temp table if it - * does not exist in the temporary table. Then it will update the temporary - * table with the new data. - * We use INSERT OR IGNORE to avoid looking if the visit already exists in the - * temp table. - */ -#define CREATE_HISTORYVISITS_VIEW_UPDATE_TRIGGER NS_LITERAL_CSTRING( \ - "CREATE TEMPORARY TRIGGER moz_historyvisits_view_update_trigger " \ - "INSTEAD OF UPDATE " \ - "ON moz_historyvisits_view " \ - "BEGIN " \ - "INSERT OR IGNORE INTO moz_historyvisits_temp (" MOZ_HISTORYVISITS_COLUMNS ") " \ - "SELECT " MOZ_HISTORYVISITS_COLUMNS " FROM moz_historyvisits " \ - "WHERE id = OLD.id; " \ - "UPDATE moz_historyvisits_temp " \ - "SET from_visit = IFNULL(NEW.from_visit, OLD.from_visit), " \ - "place_id = IFNULL(NEW.place_id, OLD.place_id), " \ - "visit_date = IFNULL(NEW.visit_date, OLD.visit_date), " \ - "visit_type = IFNULL(NEW.visit_type, OLD.visit_type), " \ - "session = IFNULL(NEW.session, OLD.session) " \ - "WHERE id = OLD.id; " \ - "END" \ -) - -/** - * This trigger moves the data out of a temporary table into the permanent one - * before deleting from the temporary table. - * - * Note - it's OK to use an INSERT OR REPLACE here because the only conflict - * that will happen is the primary key. As a result, the row will be deleted, - * and the replacement will be inserted with the same id. - */ -#define CREATE_TEMP_SYNC_TRIGGER_BASE(__table, __columns) NS_LITERAL_CSTRING( \ - "CREATE TEMPORARY TRIGGER " __table "_beforedelete_trigger " \ - "BEFORE DELETE ON " __table "_temp FOR EACH ROW " \ - "BEGIN " \ - "INSERT OR REPLACE INTO " __table " (" __columns ") " \ - "SELECT " __columns " FROM " __table "_temp " \ - "WHERE id = OLD.id;" \ - "END" \ -) -#define CREATE_MOZ_PLACES_SYNC_TRIGGER \ - CREATE_TEMP_SYNC_TRIGGER_BASE("moz_places", MOZ_PLACES_COLUMNS) -#define CREATE_MOZ_HISTORYVISITS_SYNC_TRIGGER \ - CREATE_TEMP_SYNC_TRIGGER_BASE("moz_historyvisits", MOZ_HISTORYVISITS_COLUMNS) - /** * This trigger removes a row from moz_openpages_temp when open_count reaches 0. diff --git a/toolkit/components/places/src/toolkitplaces.manifest b/toolkit/components/places/src/toolkitplaces.manifest index 499b30fcab3..6b2439ef0e6 100644 --- a/toolkit/components/places/src/toolkitplaces.manifest +++ b/toolkit/components/places/src/toolkitplaces.manifest @@ -8,12 +8,6 @@ contract @mozilla.org/browser/tagging-service;1 {bbc23860-2553-479d-8b78-94d9038 component {1dcc23b0-d4cb-11dc-9ad6-479d56d89593} nsTaggingService.js contract @mozilla.org/autocomplete/search;1?name=places-tag-autocomplete {1dcc23b0-d4cb-11dc-9ad6-479d56d89593} -# nsPlacesDBFlush.js -component {c1751cfc-e8f1-4ade-b0bb-f74edfb8ef6a} nsPlacesDBFlush.js -contract @mozilla.org/places/sync;1 {c1751cfc-e8f1-4ade-b0bb-f74edfb8ef6a} -category bookmark-observers nsPlacesDBFlush @mozilla.org/places/sync;1 -category history-observers nsPlacesDBFlush @mozilla.org/places/sync;1 - # nsPlacesExpiration.js component {705a423f-2f69-42f3-b9fe-1517e0dee56f} nsPlacesExpiration.js contract @mozilla.org/places/expiration;1 {705a423f-2f69-42f3-b9fe-1517e0dee56f} diff --git a/toolkit/components/places/tests/Makefile.in b/toolkit/components/places/tests/Makefile.in index c6b6c13492b..f9d47b7a5ee 100644 --- a/toolkit/components/places/tests/Makefile.in +++ b/toolkit/components/places/tests/Makefile.in @@ -49,7 +49,6 @@ MODULE = test_places XPCSHELL_TESTS = \ autocomplete \ expiration \ - sync \ bookmarks \ queries \ unit \ diff --git a/toolkit/components/places/tests/autocomplete/test_autocomplete_on_value_removed_479089.js b/toolkit/components/places/tests/autocomplete/test_autocomplete_on_value_removed_479089.js index ad63cecabb2..7c6ade89f64 100644 --- a/toolkit/components/places/tests/autocomplete/test_autocomplete_on_value_removed_479089.js +++ b/toolkit/components/places/tests/autocomplete/test_autocomplete_on_value_removed_479089.js @@ -72,7 +72,7 @@ function run_test() // open the result container queryRes.root.containerOpen = true; // debug queries - // dump_table("moz_places_view"); + // dump_table("moz_places"); do_check_eq(queryRes.root.childCount, 1); // call the untested code path listener.onValueRemoved(null, uri.spec, true); diff --git a/toolkit/components/places/tests/browser/browser_settitle.js b/toolkit/components/places/tests/browser/browser_settitle.js index bf7da355ccc..99b1ebf0fdd 100644 --- a/toolkit/components/places/tests/browser/browser_settitle.js +++ b/toolkit/components/places/tests/browser/browser_settitle.js @@ -36,8 +36,6 @@ var conn = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase).DBConnectio function getColumn(table, column, fromColumnName, fromColumnValue) { var stmt = conn.createStatement( - "SELECT " + column + " FROM " + table + "_temp WHERE " + fromColumnName + "=:val " + - "UNION ALL " + "SELECT " + column + " FROM " + table + " WHERE " + fromColumnName + "=:val " + "LIMIT 1"); try { diff --git a/toolkit/components/places/tests/browser/browser_visituri.js b/toolkit/components/places/tests/browser/browser_visituri.js index e21bb59aa0f..db6189535bd 100644 --- a/toolkit/components/places/tests/browser/browser_visituri.js +++ b/toolkit/components/places/tests/browser/browser_visituri.js @@ -51,8 +51,6 @@ var conn = PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase).DBConnectio function getColumn(table, column, fromColumnName, fromColumnValue) { var stmt = conn.createStatement( - "SELECT " + column + " FROM " + table + "_temp WHERE " + fromColumnName + "=:val " + - "UNION ALL " + "SELECT " + column + " FROM " + table + " WHERE " + fromColumnName + "=:val " + "LIMIT 1"); try { diff --git a/toolkit/components/places/tests/cpp/places_test_harness.h b/toolkit/components/places/tests/cpp/places_test_harness.h index 389cda76105..2d2114cefcc 100644 --- a/toolkit/components/places/tests/cpp/places_test_harness.h +++ b/toolkit/components/places/tests/cpp/places_test_harness.h @@ -182,16 +182,12 @@ do_get_place(nsIURI* aURI, PlaceRecord& result) do_check_success(rv); rv = dbConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT id, hidden, typed, visit_count FROM moz_places_temp " - "WHERE url=?1 " - "UNION ALL " "SELECT id, hidden, typed, visit_count FROM moz_places " "WHERE url=?1 " - "LIMIT 1" ), getter_AddRefs(stmt)); do_check_success(rv); - rv = stmt->BindUTF8StringParameter(0, spec); + rv = stmt->BindUTF8StringByIndex(0, spec); do_check_success(rv); PRBool hasResults; @@ -222,16 +218,13 @@ do_get_lastVisit(PRInt64 placeId, VisitRecord& result) nsCOMPtr stmt; nsresult rv = dbConn->CreateStatement(NS_LITERAL_CSTRING( - "SELECT id, from_visit, visit_type FROM moz_historyvisits_temp " - "WHERE place_id=?1 " - "UNION ALL " "SELECT id, from_visit, visit_type FROM moz_historyvisits " "WHERE place_id=?1 " "LIMIT 1" ), getter_AddRefs(stmt)); do_check_success(rv); - rv = stmt->BindInt64Parameter(0, placeId); + rv = stmt->BindInt64ByIndex(0, placeId); do_check_success(rv); PRBool hasResults; diff --git a/toolkit/components/places/tests/expiration/test_annos_expire_policy.js b/toolkit/components/places/tests/expiration/test_annos_expire_policy.js index 695a9382286..76385d43dec 100644 --- a/toolkit/components/places/tests/expiration/test_annos_expire_policy.js +++ b/toolkit/components/places/tests/expiration/test_annos_expire_policy.js @@ -90,7 +90,7 @@ function add_old_anno(aIdentifier, aName, aValue, aExpirePolicy, // Update dateAdded for the last added annotation. sql = "UPDATE moz_annos SET dateAdded = :expire_date, lastModified = :last_modified " + "WHERE id = (SELECT a.id FROM moz_annos a " + - "LEFT JOIN moz_places_view h on h.id = a.place_id " + + "LEFT JOIN moz_places h on h.id = a.place_id " + "WHERE h.url = :id " + "ORDER BY a.dateAdded DESC LIMIT 1)"; } diff --git a/toolkit/components/places/tests/expiration/test_removeAllPages.js b/toolkit/components/places/tests/expiration/test_removeAllPages.js index c2b84395d4a..8cd94f78629 100644 --- a/toolkit/components/places/tests/expiration/test_removeAllPages.js +++ b/toolkit/components/places/tests/expiration/test_removeAllPages.js @@ -88,7 +88,7 @@ function add_old_anno(aIdentifier, aName, aValue, aExpirePolicy, "WHERE id = ( " + "SELECT a.id FROM moz_annos a " + "JOIN moz_anno_attributes n ON n.id = a.anno_attribute_id " + - "JOIN moz_places_view h on h.id = a.place_id " + + "JOIN moz_places h on h.id = a.place_id " + "WHERE h.url = :id " + "AND n.name = :anno_name " + "ORDER BY a.dateAdded DESC LIMIT 1 " + diff --git a/toolkit/components/places/tests/head_common.js b/toolkit/components/places/tests/head_common.js index 3204d74ffd6..6b6f5152ef1 100644 --- a/toolkit/components/places/tests/head_common.js +++ b/toolkit/components/places/tests/head_common.js @@ -457,34 +457,3 @@ function is_time_ordered(before, after) { let skew = isWindows ? 20000000 : 0; return after - before > -skew; } - - -// These tests are known to randomly fail due to bug 507790 when database -// flushes are active, so we turn off syncing for them. -let (randomFailingSyncTests = [ - "test_multi_word_tags.js", - "test_removeVisitsByTimeframe.js", - "test_utils_getURLsForContainerNode.js", - "test_exclude_livemarks.js", - "test_402799.js", - "test_results-as-visit.js", - "test_sorting.js", - "test_redirectsMode.js", - "test_384228.js", - "test_395593.js", - "test_containersQueries_sorting.js", - "test_browserGlue_smartBookmarks.js", - "test_browserGlue_distribution.js", - "test_331487.js", - "test_tags.js", - "test_385829.js", - "test_405938_restore_queries.js", -]) { - let currentTestFilename = do_get_file(_TEST_FILE[0], true).leafName; - if (randomFailingSyncTests.indexOf(currentTestFilename) != -1) { - print("Test " + currentTestFilename + - " is known random due to bug 507790, disabling PlacesDBFlush."); - let sync = Cc["@mozilla.org/places/sync;1"].getService(Ci.nsIObserver); - sync.observe(null, "places-debug-stop-sync", null); - } -} diff --git a/toolkit/components/places/tests/mochitest/bug_411966/redirect.js b/toolkit/components/places/tests/mochitest/bug_411966/redirect.js index f141db08f3f..4a05d1c528a 100644 --- a/toolkit/components/places/tests/mochitest/bug_411966/redirect.js +++ b/toolkit/components/places/tests/mochitest/bug_411966/redirect.js @@ -158,11 +158,11 @@ function checkDB(data){ ghist.addURI(this.mChannel.URI, true, true, referrer); // Get all pages visited from the original typed one - var sql = "SELECT url FROM moz_historyvisits_view " + - "JOIN moz_places_view h ON h.id = place_id " + + var sql = "SELECT url FROM moz_historyvisits " + + "JOIN moz_places h ON h.id = place_id " + "WHERE from_visit IN " + - "(SELECT v.id FROM moz_historyvisits_view v " + - "JOIN moz_places_view p ON p.id = v.place_id " + + "(SELECT v.id FROM moz_historyvisits v " + + "JOIN moz_places p ON p.id = v.place_id " + "WHERE p.url = ?1)"; var stmt = mDBConn.createStatement(sql); stmt.bindUTF8StringParameter(0, typedURI.spec); diff --git a/toolkit/components/places/tests/network/test_history_redirects.js b/toolkit/components/places/tests/network/test_history_redirects.js index 016b4023dd6..0bdbc87b909 100644 --- a/toolkit/components/places/tests/network/test_history_redirects.js +++ b/toolkit/components/places/tests/network/test_history_redirects.js @@ -109,8 +109,8 @@ function run_test() { function continue_test() { let stmt = DBConn().createStatement( "SELECT v.id, h.url, v.from_visit, v.visit_date, v.visit_type, v.session " + - "FROM moz_historyvisits_view v " + - "JOIN moz_places_view h on h.id = v.place_id " + + "FROM moz_historyvisits v " + + "JOIN moz_places h on h.id = v.place_id " + "ORDER BY v.id ASC"); const EXPECTED = [ { id: 1, diff --git a/toolkit/components/places/tests/queries/head_queries.js b/toolkit/components/places/tests/queries/head_queries.js index eef43fa89cf..18bc7dbc979 100644 --- a/toolkit/components/places/tests/queries/head_queries.js +++ b/toolkit/components/places/tests/queries/head_queries.js @@ -85,7 +85,7 @@ function populateDB(aArray) { if (qdata.title && !qdata.isDetails) { // Set the page title synchronously, otherwise setPageTitle is LAZY. let stmt = DBConn().createStatement( - "UPDATE moz_places_view SET title = :title WHERE url = :url" + "UPDATE moz_places SET title = :title WHERE url = :url" ); stmt.params.title = qdata.title; stmt.params.url = qdata.uri; @@ -102,7 +102,7 @@ function populateDB(aArray) { // Set a fake visit_count, this is not a real count but can be used // to test sorting by visit_count. let stmt = DBConn().createStatement( - "UPDATE moz_places_view SET visit_count = :vc WHERE url = :url"); + "UPDATE moz_places SET visit_count = :vc WHERE url = :url"); stmt.params.vc = qdata.visitCount; stmt.params.url = qdata.uri; try { diff --git a/toolkit/components/places/tests/queries/test_transitions.js b/toolkit/components/places/tests/queries/test_transitions.js index f541693432c..e9f788928ce 100644 --- a/toolkit/components/places/tests/queries/test_transitions.js +++ b/toolkit/components/places/tests/queries/test_transitions.js @@ -100,10 +100,8 @@ function run_test() { testData[i].title = null; } - dump_table("moz_places"); - dump_table("moz_places_temp"); - dump_table("moz_historyvisits"); - dump_table("moz_historyvisits_temp"); + //dump_table("moz_places"); + //dump_table("moz_historyvisits"); var numSortFunc = function (a,b) { return (a - b); }; var arrs = testDataTyped.concat(testDataDownload).concat(testDataBookmark) diff --git a/toolkit/components/places/tests/sync/head_sync.js b/toolkit/components/places/tests/sync/head_sync.js deleted file mode 100644 index ceeb6211163..00000000000 --- a/toolkit/components/places/tests/sync/head_sync.js +++ /dev/null @@ -1,136 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Places. - * - * The Initial Developer of the Original Code is - * Google Inc. - * Portions created by the Initial Developer are Copyright (C) 2005 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Brian Ryner - * Dietrich Ayala - * Shawn Wilsher - * Marco Bonardo - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -const Ci = Components.interfaces; -const Cc = Components.classes; -const Cr = Components.results; -const Cu = Components.utils; - -Cu.import("resource://gre/modules/Services.jsm"); - -// Import common head. -let (commonFile = do_get_file("../head_common.js", false)) { - let uri = Services.io.newFileURI(commonFile); - Services.scriptloader.loadSubScript(uri.spec, this); -} - -// Put any other stuff relative to this test folder below. - - -/** - * Function tests to see if the place associated with the bookmark with id - * aBookmarkId has the uri aExpectedURI. The event will call do_test_finished() - * if aFinish is true. - * - * @param aBookmarkId - * The bookmark to check against. - * @param aExpectedURI - * The URI we expect to be in moz_places. - * @param aExpected - * Indicates if we expect to get a result or not. - * @param [optional] aFinish - * Indicates if the test should be completed or not. - */ -function new_test_bookmark_uri_event(aBookmarkId, aExpectedURI, aExpected, aFinish) -{ - let stmt = DBConn().createStatement( - "SELECT moz_places.url " + - "FROM moz_bookmarks INNER JOIN moz_places " + - "ON moz_bookmarks.fk = moz_places.id " + - "WHERE moz_bookmarks.id = ?1" - ); - stmt.bindInt64Parameter(0, aBookmarkId); - - if (aExpected) { - do_check_true(stmt.executeStep()); - do_check_eq(stmt.getUTF8String(0), aExpectedURI); - } - else { - do_check_false(stmt.executeStep()); - } - stmt.reset(); - stmt.finalize(); - stmt = null; - - if (aFinish) - do_test_finished(); -} - - -/** - * Function tests to see if the place associated with the visit with id aVisitId - * has the uri aExpectedURI. The event will call do_test_finished() if aFinish is - * true. - * - * @param aVisitId - * The visit to check against. - * @param aExpectedURI - * The URI we expect to be in moz_places. - * @param aExpected - * Indicates if we expect to get a result or not. - * @param [optional] aFinish - * Indicates if the test should be completed or not. - */ -function new_test_visit_uri_event(aVisitId, aExpectedURI, aExpected, aFinish) -{ - let stmt = DBConn().createStatement( - "SELECT moz_places.url " + - "FROM moz_historyvisits INNER JOIN moz_places " + - "ON moz_historyvisits.place_id = moz_places.id " + - "WHERE moz_historyvisits.id = ?1" - ); - stmt.bindInt64Parameter(0, aVisitId); - - if (aExpected) { - do_check_true(stmt.executeStep()); - do_check_eq(stmt.getUTF8String(0), aExpectedURI); - } - else { - do_check_false(stmt.executeStep()); - } - stmt.reset(); - stmt.finalize(); - stmt = null; - - if (aFinish) - do_test_finished(); -} - diff --git a/toolkit/components/places/tests/sync/test_bookmarks_sorted_by_none.js b/toolkit/components/places/tests/sync/test_bookmarks_sorted_by_none.js deleted file mode 100644 index 9e1e030e356..00000000000 --- a/toolkit/components/places/tests/sync/test_bookmarks_sorted_by_none.js +++ /dev/null @@ -1,126 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2009 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Marco Bonardo (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * Bug 493933 - When sorting bookmarks BY NONE we should take in count partitioning. - * - * When we have a bookmarks results sorted BY NONE, could be the order depends - * on current status of disk and temp tables due to how the query executes the - * UNION. We must ensure their order is correct. - */ - -var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); -var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const SYNC_INTERVAL = 600; -const kSyncFinished = "places-sync-finished"; - -var observer = { - _runCount: 0, - one: null, - two: null, - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished) { - // Skip the first sync. - if (++this._runCount < 2) - return; - - os.removeObserver(this, kSyncFinished); - - // Sanity check positions. - do_check_true(this.one < this.two); - do_check_eq(bs.getItemIndex(this.one), 0); - do_check_eq(bs.getItemIndex(this.two), 1); - - check_results(); - - // Now add a visit to the second bookmark, so that it is in temp table. - hs.addVisit(uri("http://2.mozilla.org/"), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); - - // Nothing should change in results. - check_results(); - - // Cleanup. - bs.removeFolderChildren(bs.toolbarFolder); - do_test_finished(); - } - } -} -os.addObserver(observer, kSyncFinished, false); - -function check_results() { - // Create a bookmarks query. - var options = hs.getNewQueryOptions(); - options.queryType = Ci.nsINavHistoryQueryOptions.QUERY_TYPE_BOOKMARKS; - var query = hs.getNewQuery(); - query.setFolders([bs.toolbarFolder], 1); - query.searchTerms = "mozilla"; - var result = hs.executeQuery(query, options); - var root = result.root; - root.containerOpen = true; - do_check_eq(root.childCount, 2); - do_check_eq(root.getChild(0).title, "mozilla 1"); - do_check_eq(root.getChild(1).title, "mozilla 2"); - root.containerOpen = false; -} - -function run_test() -{ - // First set the preference for the timer to a large value so we don't sync - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Add two bookmarks and check their index - observer.one = bs.insertBookmark(bs.toolbarFolder, - uri("http://1.mozilla.org/"), - bs.DEFAULT_INDEX, "mozilla 1"); - observer.two = bs.insertBookmark(bs.toolbarFolder, - uri("http://2.mozilla.org/"), - bs.DEFAULT_INDEX, "mozilla 2"); - - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_database_sync_after_addBookmark.js b/toolkit/components/places/tests/sync/test_database_sync_after_addBookmark.js deleted file mode 100644 index 85033c5f683..00000000000 --- a/toolkit/components/places/tests/sync/test_database_sync_after_addBookmark.js +++ /dev/null @@ -1,89 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Shawn Wilsher (Original Author) - * Marco Bonardo - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); - -const TEST_URI = "http://test.com/"; - -const SYNC_INTERVAL = 600; // ten minutes -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const kSyncFinished = "places-sync-finished"; - -// Used to update observer itemId -var bookmarksObserver = { - onItemAdded: function(aItemId, aNewParent, aNewIndex) { - observer.itemId = aItemId; - } -} -bs.addObserver(bookmarksObserver, false); - -var observer = { - itemId: -1, - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished) { - do_check_neq(this.itemId, -1); - // remove the observer, we don't need to observe sync on quit - os.removeObserver(this, kSyncFinished); - bs.removeObserver(bookmarksObserver); - // Check that moz_places table has been correctly synced - new_test_bookmark_uri_event(this.itemId, TEST_URI, true, true); - } - } -} -os.addObserver(observer, kSyncFinished, false); - -function run_test() -{ - // First set the preference for the timer to a really large value so it won't - // run before the test finishes. - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Insert a new bookmark - bs.insertBookmark(bs.unfiledBookmarksFolder, uri(TEST_URI), - bs.DEFAULT_INDEX, "test"); - - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_database_sync_after_addBookmark_batched.js b/toolkit/components/places/tests/sync/test_database_sync_after_addBookmark_batched.js deleted file mode 100644 index f95227bd01b..00000000000 --- a/toolkit/components/places/tests/sync/test_database_sync_after_addBookmark_batched.js +++ /dev/null @@ -1,110 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Shawn Wilsher (Original Author) - * Marco Bonardo - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); - -const TEST_URI = "http://test.com/"; - -const SYNC_INTERVAL = 600; // ten minutes -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const kSyncFinished = "places-sync-finished"; - -// Used to check if we are batching and to update observer itemId -var bookmarksObserver = { - _batching: false, - onBeginUpdateBatch: function() { - this._batching = true; - }, - onEndUpdateBatch: function() { - this._batching = false; - }, - onItemAdded: function(aItemId, aNewParent, aNewIndex) { - observer.itemId = aItemId; - } -} -bs.addObserver(bookmarksObserver, false); - -var observer = { - itemId: -1, - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished) { - dump(this.itemId); - // item id must be valid - do_check_neq(this.itemId, -1); - // Check that we are not in a batch - do_check_false(bookmarksObserver._batching); - // remove the observer, we don't need to observe sync on quit - os.removeObserver(this, kSyncFinished); - bs.removeObserver(bookmarksObserver); - // Check that tables have been correctly synced - new_test_bookmark_uri_event(this.itemId, TEST_URI, true, true); - } - } -} -os.addObserver(observer, kSyncFinished, false); - -function run_test() -{ - // Set the preference for the timer to a really large value, so it won't - // run before the test finishes. - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Add a bookmark in batch mode - let id = -1; - bs.runInBatchMode({ - runBatched: function(aUserData) - { - id = bs.insertBookmark(bs.unfiledBookmarksFolder, uri(TEST_URI), - bs.DEFAULT_INDEX, "test"); - // We should not sync during a batch - new_test_bookmark_uri_event(id, TEST_URI, false); - } - }, null); - // Ensure the bookmark has been added - do_check_neq(id, -1); - - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_database_sync_after_addVisit.js b/toolkit/components/places/tests/sync/test_database_sync_after_addVisit.js deleted file mode 100644 index a100df86ef0..00000000000 --- a/toolkit/components/places/tests/sync/test_database_sync_after_addVisit.js +++ /dev/null @@ -1,96 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Shawn Wilsher (Original Author) - * Marco Bonardo - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); -var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - -const TEST_URI = "http://test.com/"; - -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const SYNC_INTERVAL = 1; -const kSyncFinished = "places-sync-finished"; - -var observer = { - visitId: -1, - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished && this.visitId != -1) { - // sanity check: visitId set by history observer should be the same we - // have added - do_check_eq(this.visitId, visitId); - // remove the observer, we don't need to observe sync on quit - os.removeObserver(this, kSyncFinished); - // Check the visit - new_test_visit_uri_event(this.visitId, TEST_URI, true, true); - } - } -} -os.addObserver(observer, kSyncFinished, false); - -// Used to update observer visitId -var historyObserver = { - onVisit: function(aURI, aVisitId, aTime, aSessionId, aReferringId, - aTransitionType, aAdded) { - observer.visitId = aVisitId; - hs.removeObserver(this, false); - } -} -hs.addObserver(historyObserver, false); - -// used for sanity check -var visitId = -1; - -function run_test() -{ - // First set the preference for the timer to a small value - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Now add the visit - visitId = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); - - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_database_sync_after_addVisit_batched.js b/toolkit/components/places/tests/sync/test_database_sync_after_addVisit_batched.js deleted file mode 100644 index 6c905559469..00000000000 --- a/toolkit/components/places/tests/sync/test_database_sync_after_addVisit_batched.js +++ /dev/null @@ -1,109 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Shawn Wilsher (Original Author) - * Marco Bonardo - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); - var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - -const TEST_URI = "http://test.com/"; - -const kSyncFinished = "places-sync-finished"; - -// Used to check if we are batching -var bookmarksObserver = { - _batching: false, - onBeginUpdateBatch: function() { - this._batching = true; - }, - onEndUpdateBatch: function() { - this._batching = false; - } -} -bs.addObserver(bookmarksObserver, false); - -// Used to update observer visitId -var historyObserver = { - onVisit: function(aURI, aVisitId, aTime, aSessionId, aReferringId, - aTransitionType, aAdded) { - observer.visitId = aVisitId; - } -} -hs.addObserver(historyObserver, false); - -var observer = { - visitId: -1, - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished) { - // visit id must be valid - do_check_neq(this.visitId, -1); - // Check that we are not in a batch - do_check_false(bookmarksObserver._batching); - // remove the observer, we don't need to observe sync on quit - os.removeObserver(this, kSyncFinished); - bs.removeObserver(bookmarksObserver); - hs.removeObserver(historyObserver); - // Check that tables have been correctly synced - new_test_visit_uri_event(this.visitId, TEST_URI, true, true); - } - } -} -os.addObserver(observer, kSyncFinished, false); - -function run_test() -{ - // Add a visit in batch mode - let id = -1; - bs.runInBatchMode({ - runBatched: function(aUserData) - { - id = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); - // We should not sync during a batch - new_test_visit_uri_event(id, TEST_URI, false); - } - }, null); - // Ensure the visit has been added - do_check_neq(id, -1); - - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_database_sync_after_modifyBookmark.js b/toolkit/components/places/tests/sync/test_database_sync_after_modifyBookmark.js deleted file mode 100644 index 0b5f456a683..00000000000 --- a/toolkit/components/places/tests/sync/test_database_sync_after_modifyBookmark.js +++ /dev/null @@ -1,109 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Shawn Wilsher (Original Author) - * Marco Bonardo - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); - -const TEST_URI = "http://test.com/"; -const MODIFIED_URI = "http://test.com/index.html"; - -const SYNC_INTERVAL = 600; // ten minutes -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const kSyncFinished = "places-sync-finished"; - -// Used to update observer itemId -var bookmarksObserver = { - onItemAdded: function(aItemId, aNewParent, aNewIndex, aItemType) { - observer.itemId = aItemId; - }, - onItemChanged: function(aItemId, aProperty, aNewValue, aLastModified, - aItemType) { - if (aProperty == "uri") - do_check_eq(observer.itemId, aItemId); - } -} -bs.addObserver(bookmarksObserver, false); - -var observer = { - itemId: -1, - _runCount: 0, - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished) { - // item id must be valid - do_check_neq(this.itemId, -1); - if (++this._runCount == 1) { - // First sync is fired by adding the bookmark - // Check that tables have been synced after insertBookmark - new_test_bookmark_uri_event(this.itemId, TEST_URI, true); - // Now modify the bookmark - bs.changeBookmarkURI(this.itemId, uri(MODIFIED_URI)); - } - else if (this._runCount == 2) { - // Second sync is fired by changing the bookmark's uri - // remove the observer, we don't need to observe sync on quit - os.removeObserver(this, kSyncFinished); - bs.removeObserver(bookmarksObserver); - // Check that tables have been synced after changeBookmarkURI - new_test_bookmark_uri_event(this.itemId, MODIFIED_URI, true, true); - } - else - do_throw("Too many places sync calls"); - } - } -} -os.addObserver(observer, kSyncFinished, false); - -function run_test() -{ - // Set the preference for the timer to a really large value, so it won't - // run before the test finishes. - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Insert a new bookmark - bs.insertBookmark(bs.unfiledBookmarksFolder, uri(TEST_URI), - bs.DEFAULT_INDEX, "test"); - - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_database_sync_after_shutdown.js b/toolkit/components/places/tests/sync/test_database_sync_after_shutdown.js deleted file mode 100644 index 6327ca31b26..00000000000 --- a/toolkit/components/places/tests/sync/test_database_sync_after_shutdown.js +++ /dev/null @@ -1,95 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Shawn Wilsher (Original Author) - * Marco Bonardo - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); -var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); - -const TEST_URI = "http://test.com/"; - -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const SYNC_INTERVAL = 600; // ten minutes -const kSyncFinished = "places-sync-finished"; - -var historyObserver = { - onVisit: function(aURI, aVisitId, aTime, aSessionId, aReferringId, - aTransitionType, aAdded) { - observer.visitId = aVisitId; - hs.removeObserver(this); - } -} -hs.addObserver(historyObserver, false); - -var observer = { - visitId: -1, - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished) { - // remove the observer, we don't need to observe sync on quit - os.removeObserver(this, kSyncFinished); - - // visit id must be valid - do_check_neq(this.visitId, -1); - // Check that tables have been correctly synced - new_test_visit_uri_event(this.visitId, TEST_URI, true, true); - } - } -} -os.addObserver(observer, kSyncFinished, false); - -function run_test() -{ - // Set the preference for the timer to a really large value, so it won't - // run before the test finishes. - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Now add a visit - hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); - - // Notify that we are quitting the app - we should sync! - shutdownPlaces(); - - // Test will continue on sync notification. - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_database_sync_after_shutdown_with_removeAllPages.js b/toolkit/components/places/tests/sync/test_database_sync_after_shutdown_with_removeAllPages.js deleted file mode 100644 index e805817fdb4..00000000000 --- a/toolkit/components/places/tests/sync/test_database_sync_after_shutdown_with_removeAllPages.js +++ /dev/null @@ -1,164 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Marco Bonardo (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); -var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); -var bh = hs.QueryInterface(Ci.nsIBrowserHistory); -var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); - -const TEST_URI = "http://test.com/"; - -const PREF_SYNC_INTERVAL = "syncDBTableIntervalInSecs"; -const SYNC_INTERVAL = 600; // ten minutes -const TOPIC_SYNC_FINISHED = "places-sync-finished"; - -// Polling constants to check the connection closed status. -const POLLING_TIMEOUT_MS = 100; -const POLLING_MAX_PASSES = 20; - -var historyObserver = { - visitId: -1, - cleared: false, - onVisit: function(aURI, aVisitId, aTime, aSessionId, aReferringId, - aTransitionType, aAdded) { - this.visitId = aVisitId; - }, - onClearHistory: function() { - // check browserHistory returns no entries - do_check_eq(0, bh.count); - this.cleared = true; - hs.removeObserver(this); - } -} -hs.addObserver(historyObserver, false); - -var observer = { - _runCount: 0, - observe: function(aSubject, aTopic, aData) { - if (aTopic == TOPIC_SYNC_FINISHED) { - if (++this._runCount == 1) { - // The first sync is due to the insert bookmark. - // Simulate a clear private data just before shutdown. - bh.removeAllPages(); - // Immediately notify shutdown. - shutdownPlaces(); - return; - } - - // Remove the observer, we don't need it anymore. - os.removeObserver(this, TOPIC_SYNC_FINISHED); - - // Visit id must be valid. - do_check_neq(historyObserver.visitId, -1); - // History must have been cleared. - do_check_true(historyObserver.cleared); - - // The database connection will be closed after this sync, but we can't - // know how much time it will take, so we use a polling strategy. - do_timeout(POLLING_TIMEOUT_MS, check_results); - } - } -} -os.addObserver(observer, TOPIC_SYNC_FINISHED, false); - -var gPasses = 0; -function check_results() { - if (++gPasses >= POLLING_MAX_PASSES) { - do_throw("Maximum time elapsdes waiting for Places database connection to close"); - do_test_finished(); - } - - if (PlacesUtils.history.QueryInterface(Ci.nsPIPlacesDatabase) - .DBConnection.connectionReady) { - do_timeout(POLLING_TIMEOUT_MS, check_results); - return; - } - - let dbConn = DBConn(); - do_check_true(dbConn.connectionReady); - - // Check that frecency for not cleared items (bookmarks) has been - // converted to -MAX(visit_count, 1), so we will be able to - // recalculate frecency starting from most frecent bookmarks. - let stmt = dbConn.createStatement( - "SELECT id FROM moz_places WHERE frecency > 0 LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - stmt = dbConn.createStatement( - "SELECT h.id FROM moz_places h WHERE h.frecency = -2 " + - "AND EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) LIMIT 1"); - do_check_true(stmt.executeStep()); - stmt.finalize(); - - // Check that all visit_counts have been brought to 0 - stmt = dbConn.createStatement( - "SELECT id FROM moz_places WHERE visit_count <> 0 LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - dbConn.asyncClose(function() { - do_check_false(dbConn.connectionReady); - - do_test_finished(); - }); -} - -function run_test() -{ - do_test_pending(); - - // Set the preference for the timer to a really large value, so it won't - // run before the test finishes. - prefs.setIntPref(PREF_SYNC_INTERVAL, SYNC_INTERVAL); - - // Now add a visit before creating bookmark, and one later - hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); - bs.insertBookmark(bs.unfiledBookmarksFolder, uri(TEST_URI), - bs.DEFAULT_INDEX, "bookmark"); - hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); -} diff --git a/toolkit/components/places/tests/sync/test_database_sync_embed_visits.js b/toolkit/components/places/tests/sync/test_database_sync_embed_visits.js deleted file mode 100644 index 21720a9b321..00000000000 --- a/toolkit/components/places/tests/sync/test_database_sync_embed_visits.js +++ /dev/null @@ -1,173 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Marco Bonardo (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - /* - * This test checks that embed visits are not synced down to disk, we hold - * them in memory since they're going to be purged at session close - * - * We instead sync to disk FRAMED_LINK visits. - */ - -var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); -var dbConn = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection; -var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - -const TEST_URI = "http://test.com/"; -const EMBED_URI = "http://embed.test.com/"; -const PLACE_URI = "place:test.com/"; - -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const SYNC_INTERVAL = 1; -const kSyncFinished = "places-sync-finished"; - -var transitions = [ hs.TRANSITION_LINK, - hs.TRANSITION_TYPED, - hs.TRANSITION_BOOKMARK, - hs.TRANSITION_EMBED, - hs.TRANSITION_FRAMED_LINK, - hs.TRANSITION_REDIRECT_PERMANENT, - hs.TRANSITION_REDIRECT_TEMPORARY, - hs.TRANSITION_DOWNLOAD ]; - -var observer = { - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished && this.visitId != -1) { - // remove the observer, we don't need to observe sync on quit - os.removeObserver(this, kSyncFinished); - - // Check that moz_places table has been correctly synced - var stmt = dbConn.createStatement( - "SELECT id FROM moz_places WHERE url = :url"); - stmt.params["url"] = TEST_URI; - do_check_true(stmt.executeStep()); - stmt.finalize(); - stmt = dbConn.createStatement( - "SELECT id FROM moz_places_temp WHERE url = :url"); - stmt.params["url"] = TEST_URI; - do_check_false(stmt.executeStep()); - stmt.finalize(); - - stmt = dbConn.createStatement( - "SELECT id FROM moz_places WHERE url = :url"); - stmt.params["url"] = EMBED_URI; - do_check_false(stmt.executeStep()); - stmt.finalize(); - stmt = dbConn.createStatement( - "SELECT id FROM moz_places_temp WHERE url = :url"); - stmt.params["url"] = EMBED_URI; - do_check_true(stmt.executeStep()); - stmt.finalize(); - - stmt = dbConn.createStatement( - "SELECT id FROM moz_places WHERE url = :url"); - stmt.params["url"] = PLACE_URI; - do_check_true(stmt.executeStep()); - stmt.finalize(); - stmt = dbConn.createStatement( - "SELECT id FROM moz_places_temp WHERE url = :url"); - stmt.params["url"] = PLACE_URI; - do_check_false(stmt.executeStep()); - stmt.finalize(); - - // Check that all visits but embed ones are in disk table - stmt = dbConn.createStatement( - "SELECT count(*) FROM moz_historyvisits h WHERE visit_type <> :t_embed"); - stmt.params["t_embed"] = hs.TRANSITION_EMBED; - do_check_true(stmt.executeStep()); - do_check_eq(stmt.getInt32(0), (transitions.length - 1) * 2); - stmt.finalize(); - stmt = dbConn.createStatement( - "SELECT id FROM moz_historyvisits h WHERE visit_type = :t_embed"); - stmt.params["t_embed"] = hs.TRANSITION_EMBED; - do_check_false(stmt.executeStep()); - stmt.finalize(); - stmt = dbConn.createStatement( - "SELECT id FROM moz_historyvisits_temp h WHERE visit_type = :t_embed"); - stmt.params["t_embed"] = hs.TRANSITION_EMBED; - do_check_true(stmt.executeStep()); - stmt.finalize(); - stmt = dbConn.createStatement( - "SELECT id FROM moz_historyvisits_temp h WHERE visit_type <> :t_embed"); - stmt.params["t_embed"] = hs.TRANSITION_EMBED; - do_check_false(stmt.executeStep()); - stmt.finalize(); - - do_test_finished(); - } - } -} - -function run_test() -{ - // First set the preference for the timer to a small value - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Add a visit for every transition type on TEST_URI - // Embed visit should stay in temp table, while other should be synced - // Place entry for this uri should be synced to disk table - transitions.forEach(function addVisit(aTransition) { - hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - aTransition, false, 0); - }); - - // Add an embed visit for EMBED_URI - // Embed visit should stay in temp table - // Place entry for this uri should stay in temp table - hs.addVisit(uri(EMBED_URI), Date.now() * 1000, null, - hs.TRANSITION_EMBED, false, 0); - - // Add a visit for every transition type on PLACE_URI - // Embed visit should stay in temp table - // Place entry for this uri should be synced to disk table - transitions.forEach(function addVisit(aTransition) { - hs.addVisit(uri(PLACE_URI), Date.now() * 1000, null, - aTransition, false, 0); - }); - - os.addObserver(observer, kSyncFinished, false); - - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_database_sync_expireAllFavicons.js b/toolkit/components/places/tests/sync/test_database_sync_expireAllFavicons.js deleted file mode 100644 index e6218b448a5..00000000000 --- a/toolkit/components/places/tests/sync/test_database_sync_expireAllFavicons.js +++ /dev/null @@ -1,134 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2009 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Marco Bonardo (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/* - * This test ensures favicons are correctly expired by expireAllFavicons API, - * both synced and unsynced favicons should be expired. - */ -var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); -var dbConn = hs.QueryInterface(Ci.nsPIPlacesDatabase).DBConnection; -var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); -var icons = Cc["@mozilla.org/browser/favicon-service;1"]. - getService(Ci.nsIFaviconService); - -const TEST_URI = "http://test.com/"; -const TEST_ICON_URI = "http://test.com/favicon.ico"; -const TEST_NOSYNC_URI = "http://nosync.test.com/"; -const TEST_NOSYNC_ICON_URI = "http://nosync.test.com/favicon.ico"; - -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const SYNC_INTERVAL = 600; -const kSyncFinished = "places-sync-finished"; - -const kExpirationFinished = "places-favicons-expired"; - -var observer = { - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished) { - os.removeObserver(this, kSyncFinished); - - // Add a not synced page with a visit. - hs.addVisit(uri(TEST_NOSYNC_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); - // Set a favicon for the page. - icons.setFaviconUrlForPage(uri(TEST_NOSYNC_URI), uri(TEST_NOSYNC_ICON_URI)); - - // Check both a synced and a not-synced favicons exist. - let stmt = dbConn.createStatement( - "SELECT id FROM moz_places WHERE url = :url AND favicon_id NOT NULL"); - stmt.params["url"] = TEST_URI; - do_check_true(stmt.executeStep()); - - stmt.finalize(); - - stmt = dbConn.createStatement( - "SELECT id FROM moz_places_temp WHERE url = :url AND favicon_id NOT NULL"); - stmt.params["url"] = TEST_NOSYNC_URI; - do_check_true(stmt.executeStep()); - - stmt.finalize(); - - // Expire all favicons. - icons.expireAllFavicons(); - } - else if (aTopic == kExpirationFinished) { - os.removeObserver(this, kExpirationFinished); - // Check all favicons have been removed. - let stmt = dbConn.createStatement( - "SELECT id FROM moz_favicons"); - do_check_false(stmt.executeStep()); - - stmt.finalize(); - - stmt = dbConn.createStatement( - "SELECT id FROM moz_places_view WHERE favicon_id NOT NULL"); - do_check_false(stmt.executeStep()); - - stmt.finalize(); - - do_test_finished(); - } - } -} -os.addObserver(observer, kSyncFinished, false); -os.addObserver(observer, kExpirationFinished, false); - -function run_test() -{ - // First set the preference for the timer to a large value so we don't sync. - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Add a page with a visit. - let visitId = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); - // Set a favicon for the page. - icons.setFaviconUrlForPage(uri(TEST_URI), uri(TEST_ICON_URI)); - - // Now add a bookmark to force a sync. - bs.insertBookmark(bs.toolbarFolder, uri(TEST_URI), bs.DEFAULT_INDEX, "visited"); - - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_database_sync_onitemadded.js b/toolkit/components/places/tests/sync/test_database_sync_onitemadded.js deleted file mode 100644 index f0e3b9ffa0c..00000000000 --- a/toolkit/components/places/tests/sync/test_database_sync_onitemadded.js +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Marco Bonardo (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - - /* - * This test checks that when we add an item we sync only if its type is - * TYPE_BOOKMARKS - */ - -var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - -const TEST_URI = "http://test.com/"; - -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const SYNC_INTERVAL = 600; -const kSyncFinished = "places-sync-finished"; - -var syncObserver = { - _numSyncs: 0, - finalSync: false, - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished) { - if (++this._numSyncs > 1 || !this.finalSync) - do_throw("We synced too many times: " + this._numSyncs); - - // remove the observers - os.removeObserver(this, kSyncFinished); - bs.removeObserver(bookmarksObserver, false); - - do_test_finished(); - } - } -} -os.addObserver(syncObserver, kSyncFinished, false); - -var bookmarksObserver = { - onItemAdded: function(aItemId, aNewParent, aNewIndex) { - if (bs.getItemType(aItemId) == bs.TYPE_BOOKMARK) - syncObserver.finalSync = true; - } -} -bs.addObserver(bookmarksObserver, false); - -function run_test() -{ - // dynamic container sample - do_load_manifest("../unit/nsDynamicContainerServiceSample.manifest"); - - // First set the preference for the timer to a large value, so it won't sync - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Add a folder - bs.createFolder(bs.toolbarFolder, "folder", bs.DEFAULT_INDEX); - - // Add a dynamic container - bs.createDynamicContainer(bs.toolbarFolder, "dynamic", - "@mozilla.org/browser/remote-container-sample;1", - bs.DEFAULT_INDEX); - - // Add a separator - bs.insertSeparator(bs.toolbarFolder, bs.DEFAULT_INDEX); - - // Add a bookmark, this will trigger final sync - bs.insertBookmark(bs.toolbarFolder, uri(TEST_URI), bs.DEFAULT_INDEX, "bookmark"); - - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_database_sync_with_specialHistoryQueries.js b/toolkit/components/places/tests/sync/test_database_sync_with_specialHistoryQueries.js deleted file mode 100644 index 5b9efaa2fb6..00000000000 --- a/toolkit/components/places/tests/sync/test_database_sync_with_specialHistoryQueries.js +++ /dev/null @@ -1,116 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Marco Bonardo (Original Author) - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); -var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - -const TEST_URI = "http://test.com/"; - -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const SYNC_INTERVAL = 600; -const kSyncFinished = "places-sync-finished"; - -var observer = { - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished) { - // Set the preference for the timer to a large value so we don't sync. - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Now add another visit, be sure to use a different session, so we - // will also test grouping by uri. - hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 1); - - // Create the history menu query. - var options = hs.getNewQueryOptions(); - options.maxResults = 10; - options.resultType = options.RESULTS_AS_URI; - options.sortingMode = options.SORT_BY_DATE_DESCENDING; - var query = hs.getNewQuery(); - var result = hs.executeQuery(query, options); - var root = result.root; - root.containerOpen = true; - do_check_eq(root.childCount, 1); - root.containerOpen = false; - - // Create the most visited query. - options = hs.getNewQueryOptions(); - options.maxResults = 10; - options.resultType = options.RESULTS_AS_URI; - options.sortingMode = options.SORT_BY_VISITCOUNT_DESCENDING; - query = hs.getNewQuery(); - result = hs.executeQuery(query, options); - root = result.root; - root.containerOpen = true; - do_check_eq(root.childCount, 1); - root.containerOpen = false; - - // Create basic uri query. - options = hs.getNewQueryOptions(); - query = hs.getNewQuery(); - result = hs.executeQuery(query, options); - root = result.root; - root.containerOpen = true; - do_check_eq(root.childCount, 1); - root.containerOpen = false; - - os.removeObserver(this, kSyncFinished); - do_test_finished(); - } - } -} -os.addObserver(observer, kSyncFinished, false); - -function run_test() -{ - // First set the preference for the timer to a small value so we sync - prefs.setIntPref(kSyncPrefName, 1); - - // Now add the visit - let visitId = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_multiple_bookmarks_around_sync.js b/toolkit/components/places/tests/sync/test_multiple_bookmarks_around_sync.js deleted file mode 100644 index 5e518b497bb..00000000000 --- a/toolkit/components/places/tests/sync/test_multiple_bookmarks_around_sync.js +++ /dev/null @@ -1,150 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Shawn Wilsher (Original Author) - * Marco Bonardo - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * This test ensures that adding a bookmark (which has an implicit sync), then - * adding another one that has the same place, we end up with only one entry in - * moz_places. - */ - -var bs = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. - getService(Ci.nsINavBookmarksService); -var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); -var db = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsPIPlacesDatabase). - DBConnection; -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); - -const TEST_URI = "http://test.com/"; - -const SYNC_INTERVAL = 600; // ten minutes -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const kSyncFinished = "places-sync-finished"; - -// Used to update observer itemId -var bookmarksObserver = { - onItemAdded: function(aItemId, aNewParent, aNewIndex) { - observer.itemIds.push(aItemId); - } -} -bs.addObserver(bookmarksObserver, false); - -var observer = { - itemIds: [], - _placeId: -1, - _runCount: 0, - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished) { - if (++this._runCount == 1) { - let itemId = this.itemIds[this._runCount - 1]; - // item id must be valid - do_check_neq(itemId, null); - // Ensure tables have been synced - new_test_bookmark_uri_event(itemId, TEST_URI, true); - - // Get the place_id - let stmt = db.createStatement( - "SELECT fk " + - "FROM moz_bookmarks " + - "WHERE id = ?" - ); - stmt.bindInt64Parameter(0, itemId); - do_check_true(stmt.executeStep()); - this._placeId = stmt.getInt64(0); - stmt.finalize(); - stmt = null; - // place id must be valid - do_check_true(this._placeId > 0); - } - else if (this._runCount == 2) { - let itemId = this.itemIds[this._runCount - 1]; - // item id must be valid - do_check_neq(itemId, null); - // Ensure it was added - new_test_bookmark_uri_event(itemId, TEST_URI, true); - - // Check to make sure we have the same place_id - stmt = db.createStatement( - "SELECT * " + - "FROM moz_bookmarks " + - "WHERE id = ?1 " + - "AND fk = ?2" - ); - stmt.bindInt64Parameter(0, itemId); - stmt.bindInt64Parameter(1, this._placeId); - do_check_true(stmt.executeStep()); - stmt.finalize(); - stmt = null; - - // remove the observer, we don't need to observe sync on quit - os.removeObserver(this, kSyncFinished); - bs.removeObserver(bookmarksObserver); - // test ends here - do_test_finished(); - } - else - do_throw("Too many places sync calls"); - } - } -} -os.addObserver(observer, kSyncFinished, false); - -function run_test() -{ - // Set the preference for the timer to a really large value, so it won't - // run before the test finishes. - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Add the first bookmark - let id1 = bs.insertBookmark(bs.unfiledBookmarksFolder, uri(TEST_URI), - bs.DEFAULT_INDEX, "test"); - - // Now we add another bookmark to a different folder - let id2 = bs.insertBookmark(bs.toolbarFolder, uri(TEST_URI), - bs.DEFAULT_INDEX, "test"); - do_check_neq(id1, id2); - - do_test_pending(); -} diff --git a/toolkit/components/places/tests/sync/test_multiple_visits_around_sync.js b/toolkit/components/places/tests/sync/test_multiple_visits_around_sync.js deleted file mode 100644 index 1b99b09a923..00000000000 --- a/toolkit/components/places/tests/sync/test_multiple_visits_around_sync.js +++ /dev/null @@ -1,152 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- - * vim: sw=2 ts=2 sts=2 expandtab - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is - * Mozilla Corporation. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Shawn Wilsher (Original Author) - * Marco Bonardo - * - * Alternatively, the contents of this file may be used under the terms of - * either the GNU General Public License Version 2 or later (the "GPL"), or - * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -/** - * This test ensures that when adding a visit, then syncing, and adding another - * visit to the same url creates two visits and that we only end up with one - * entry in moz_places. - */ - -var hs = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsINavHistoryService); -var db = Cc["@mozilla.org/browser/nav-history-service;1"]. - getService(Ci.nsPIPlacesDatabase). - DBConnection; -var prefs = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefService). - getBranch("places."); -var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - -const TEST_URI = "http://test.com/"; - -const kSyncPrefName = "syncDBTableIntervalInSecs"; -const SYNC_INTERVAL = 1; -const kSyncFinished = "places-sync-finished"; - -var observer = { - visitId: -1, - _runCount: 0, - _placeId: -1, - _lastVisitId: -1, - observe: function(aSubject, aTopic, aData) { - if (aTopic == kSyncFinished && this.visitId != -1) { - // Check the visit - new_test_visit_uri_event(this.visitId, TEST_URI, true); - - // sanity check: visitId set by history observer should be the same we - // have added - do_check_eq(this.visitId, visitIds[this._runCount]); - - if (++this._runCount == 1) { - // Get the place_id and pass it on - let stmt = db.createStatement( - "SELECT place_id " + - "FROM moz_historyvisits " + - "WHERE id = ?1" - ); - stmt.bindInt64Parameter(0, this.visitId); - do_check_true(stmt.executeStep()); - this._placeId = stmt.getInt64(0); - this._lastVisitId = this.visitId; - stmt.finalize(); - stmt = null; - - // clear cached value before continue test - this.visitId = -1; - continue_test(); - } - else if (this._runCount == 2) { - do_check_neq(this.visitId, this._lastVisitId); - // Get the place_id and check for equality - let stmt = db.createStatement( - "SELECT place_id " + - "FROM moz_historyvisits " + - "WHERE id = ?1" - ); - stmt.bindInt64Parameter(0, this.visitId); - do_check_true(stmt.executeStep()); - do_check_eq(this._placeId, stmt.getInt64(0)); - stmt.finalize(); - stmt = null; - - // remove the observers - os.removeObserver(this, kSyncFinished); - hs.removeObserver(historyObserver, false); - do_test_finished(); - } - else - do_throw("bad runCount!"); - } - } -} -os.addObserver(observer, kSyncFinished, false); - -// Used to update observer visitId -var historyObserver = { - onVisit: function(aURI, aVisitId, aTime, aSessionId, aReferringId, - aTransitionType, aAdded) { - do_check_true(aVisitId > 0); - observer.visitId = aVisitId; - } -} -hs.addObserver(historyObserver, false); - -// used for sanity checks -var visitIds = []; - -function run_test() -{ - // First set the preference for the timer to a small value - prefs.setIntPref(kSyncPrefName, SYNC_INTERVAL); - - // Now add the first visit - visitIds[0] = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); - - do_test_pending(); -} - -function continue_test() -{ - // Now we add another visit - visitIds[1] = hs.addVisit(uri(TEST_URI), Date.now() * 1000, null, - hs.TRANSITION_TYPED, false, 0); -} diff --git a/toolkit/components/places/tests/unit/test_248970.js b/toolkit/components/places/tests/unit/test_248970.js index ad51d92746b..ce4f2307b35 100644 --- a/toolkit/components/places/tests/unit/test_248970.js +++ b/toolkit/components/places/tests/unit/test_248970.js @@ -45,8 +45,6 @@ var histsvc = Cc["@mozilla.org/browser/nav-history-service;1"]. var bhist = histsvc.QueryInterface(Ci.nsIBrowserHistory); var bmsvc = Cc["@mozilla.org/browser/nav-bookmarks-service;1"]. getService(Ci.nsINavBookmarksService); -var ios = Cc["@mozilla.org/network/io-service;1"]. - getService(Components.interfaces.nsIIOService); /** * Function prohibits an attempt to pop up a confirmation @@ -249,22 +247,13 @@ function run_test() { var pb = get_PBSvc(); if (pb) { // Private Browsing might not be available - // need to catch places sync notifications - var os = Cc["@mozilla.org/observer-service;1"]. - getService(Ci.nsIObserverService); - const kSyncFinished = "places-sync-finished"; do_test_pending(); - var prefBranch = Cc["@mozilla.org/preferences-service;1"]. - getService(Ci.nsIPrefBranch); - prefBranch.setBoolPref("browser.privatebrowsing.keep_current_session", true); - - var bookmark_A_URI = ios.newURI("http://google.com/", null, null); - var bookmark_B_URI = ios.newURI("http://bugzilla.mozilla.org/", null, null); - var onBookmarkAAdded = { - observe: function (aSubject, aTopic, aData) { - os.removeObserver(this, kSyncFinished); + Services.prefs.setBoolPref("browser.privatebrowsing.keep_current_session", true); + var bookmark_A_URI = NetUtil.newURI("http://google.com/"); + var bookmark_B_URI = NetUtil.newURI("http://bugzilla.mozilla.org/"); + var onBookmarkAAdded = function() { check_placesItem_Count(); // Bookmark-A should be bookmarked, data should be retrievable @@ -298,16 +287,11 @@ function run_test() { do_check_true(bmsvc.isBookmarked(bookmark_A_URI)); do_check_eq("google",bmsvc.getKeywordForURI(bookmark_A_URI)); - os.addObserver(onBookmarkBAdded, kSyncFinished, false); - // Create Bookmark-B myBookmarks[1] = create_bookmark(bookmark_B_URI,"title 2", "bugzilla"); - } + onBookmarkBAdded(); }; - var onBookmarkBAdded = { - observe: function (aSubject, aTopic, aData) { - os.removeObserver(this, kSyncFinished); - + var onBookmarkBAdded = function() { // A check on the history count should be same as before, 7 history entries with // now 2 bookmark items (A) and bookmark (B), so we set num_places_entries to 9 num_places_entries = 10; // Bookmark-B successfully added but not the history entries. @@ -330,9 +314,8 @@ function run_test() { do_check_true(bhist.isVisited(uri(visited_uri))); } - prefBranch.clearUserPref("browser.privatebrowsing.keep_current_session"); + Services.prefs.clearUserPref("browser.privatebrowsing.keep_current_session"); do_test_finished(); - } }; // History database should be empty @@ -344,8 +327,6 @@ function run_test() { // History database should have entries do_check_true(histsvc.hasHistoryEntries); - os.addObserver(onBookmarkAAdded, kSyncFinished, false); - // Create Bookmark-A myBookmarks[0] = create_bookmark(bookmark_A_URI,"title 1", "google"); @@ -354,5 +335,7 @@ function run_test() { do_check_true(bhist.isVisited(uri(visited_uri))); do_check_true(uri_in_db(uri(visited_uri))); } + + onBookmarkAAdded(); } } diff --git a/toolkit/components/places/tests/unit/test_412132.js b/toolkit/components/places/tests/unit/test_412132.js index 8a73511e5be..bb9155e5b9c 100644 --- a/toolkit/components/places/tests/unit/test_412132.js +++ b/toolkit/components/places/tests/unit/test_412132.js @@ -292,7 +292,7 @@ function getFrecency(url) var stmt; var frecency; - sql = "SELECT frecency FROM moz_places_view WHERE url = ?1"; + sql = "SELECT frecency FROM moz_places WHERE url = ?1"; stmt = dbConn.createStatement(sql); stmt.bindUTF8StringParameter(0, url); do_check_true(stmt.executeStep()); @@ -307,7 +307,7 @@ function prepTest(testName, callback) { print("Test: " + testName); waitForClearHistory(function() { - dbConn.executeSimpleSQL("DELETE FROM moz_places_view"); + dbConn.executeSimpleSQL("DELETE FROM moz_places"); dbConn.executeSimpleSQL("DELETE FROM moz_bookmarks WHERE id > " + defaultBookmarksMaxId); callback(); diff --git a/toolkit/components/places/tests/unit/test_454977.js b/toolkit/components/places/tests/unit/test_454977.js index fa8f61a638a..7919502b03d 100644 --- a/toolkit/components/places/tests/unit/test_454977.js +++ b/toolkit/components/places/tests/unit/test_454977.js @@ -57,7 +57,7 @@ function add_visit(aURI, aVisitDate, aVisitType) { aVisitType != hs.TRANSITION_DOWNLOAD) visit_count ++; // Get the place id - var sql = "SELECT place_id FROM moz_historyvisits_view WHERE id = ?1"; + var sql = "SELECT place_id FROM moz_historyvisits WHERE id = ?1"; var stmt = mDBConn.createStatement(sql); stmt.bindInt64Parameter(0, visitId); do_check_true(stmt.executeStep()); diff --git a/toolkit/components/places/tests/unit/test_doSetAndLoadFaviconForPage_failures.js b/toolkit/components/places/tests/unit/test_doSetAndLoadFaviconForPage_failures.js index d1ea2d67f86..e8c5ea0b072 100644 --- a/toolkit/components/places/tests/unit/test_doSetAndLoadFaviconForPage_failures.js +++ b/toolkit/components/places/tests/unit/test_doSetAndLoadFaviconForPage_failures.js @@ -138,8 +138,8 @@ let historyObserver = { return; // dump tables, useful if the test fails. - dump_table("moz_places_temp"); - dump_table("moz_favicons"); + //dump_table("moz_places"); + //dump_table("moz_favicons"); // Ensure we have been called by the last test. do_check_true(pageURI.equals(uri("http://test4.bar/"))); diff --git a/toolkit/components/places/tests/unit/test_history_removeAllPages.js b/toolkit/components/places/tests/unit/test_history_removeAllPages.js index 48aa75a8138..3d0ea40840e 100644 --- a/toolkit/components/places/tests/unit/test_history_removeAllPages.js +++ b/toolkit/components/places/tests/unit/test_history_removeAllPages.js @@ -51,12 +51,8 @@ let os = Cc["@mozilla.org/observer-service;1"]. let lms = Cc["@mozilla.org/browser/livemark-service;2"]. getService(Ci.nsILivemarkService); -const kSyncFinished = "places-sync-finished"; const kExpirationFinished = "places-expiration-finished"; -// Number of expected sync notifications, we expect one per bookmark. -const EXPECTED_SYNCS = 4; - function add_fake_livemark() { let lmId = lms.createLivemarkFolderOnly(bs.toolbarFolder, "Livemark", @@ -91,42 +87,84 @@ let observer = { // check browserHistory returns no entries do_check_eq(0, bh.count); + // Check that frecency for not cleared items (bookmarks) has been converted + // to -MAX(visit_count, 1), so we will be able to recalculate frecency + // starting from most frecent bookmarks. + stmt = mDBConn.createStatement( + "SELECT h.id FROM moz_places h WHERE h.frecency > 0 " + + "AND EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) LIMIT 1"); + do_check_false(stmt.executeStep()); + stmt.finalize(); + + stmt = mDBConn.createStatement( + "SELECT h.id FROM moz_places h WHERE h.frecency = -2 " + + "AND EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) LIMIT 1"); + do_check_true(stmt.executeStep()); + stmt.finalize(); + let expirationObserver = { observe: function (aSubject, aTopic, aData) { os.removeObserver(this, kExpirationFinished, false); - - // Check that frecency for not cleared items (bookmarks) has been converted - // to -MAX(visit_count, 1), so we will be able to recalculate frecency - // starting from most frecent bookmarks. - // Memory table has been updated, disk table has not - stmt = mDBConn.createStatement( - "SELECT id FROM moz_places_temp WHERE frecency > 0 LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - stmt = mDBConn.createStatement( - "SELECT h.id FROM moz_places_temp h WHERE h.frecency = -2 " + - "AND EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) LIMIT 1"); - do_check_true(stmt.executeStep()); - stmt.finalize(); // Check that all visit_counts have been brought to 0 stmt = mDBConn.createStatement( - "SELECT id FROM moz_places_temp WHERE visit_count <> 0 LIMIT 1"); + "SELECT id FROM moz_places WHERE visit_count <> 0 LIMIT 1"); do_check_false(stmt.executeStep()); stmt.finalize(); // Check that history tables are empty stmt = mDBConn.createStatement( - "SELECT * FROM (SELECT id FROM moz_historyvisits_temp LIMIT 1) " + - "UNION ALL " + "SELECT * FROM (SELECT id FROM moz_historyvisits LIMIT 1)"); do_check_false(stmt.executeStep()); stmt.finalize(); - // force a sync and check again disk tables, insertBookmark will do that - bs.insertBookmark(bs.unfiledBookmarksFolder, uri("place:folder=4"), - bs.DEFAULT_INDEX, "shortcut"); + // Check that all moz_places entries except bookmarks and place: have been removed + stmt = mDBConn.createStatement( + "SELECT h.id FROM moz_places h WHERE SUBSTR(h.url, 1, 6) <> 'place:' "+ + "AND NOT EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) LIMIT 1"); + do_check_false(stmt.executeStep()); + stmt.finalize(); + + // Check that we only have favicons for retained places + stmt = mDBConn.createStatement( + "SELECT f.id FROM moz_favicons f WHERE NOT EXISTS " + + "(SELECT id FROM moz_places WHERE favicon_id = f.id) LIMIT 1"); + do_check_false(stmt.executeStep()); + stmt.finalize(); + + // Check that we only have annotations for retained places + stmt = mDBConn.createStatement( + "SELECT a.id FROM moz_annos a WHERE NOT EXISTS " + + "(SELECT id FROM moz_places WHERE id = a.place_id) LIMIT 1"); + do_check_false(stmt.executeStep()); + stmt.finalize(); + + // Check that we only have inputhistory for retained places + stmt = mDBConn.createStatement( + "SELECT i.place_id FROM moz_inputhistory i WHERE NOT EXISTS " + + "(SELECT id FROM moz_places WHERE id = i.place_id) LIMIT 1"); + do_check_false(stmt.executeStep()); + stmt.finalize(); + + // Check that place:uris have frecency 0 + stmt = mDBConn.createStatement( + "SELECT h.id FROM moz_places h " + + "WHERE SUBSTR(h.url, 1, 6) = 'place:' AND h.frecency <> 0 LIMIT 1"); + do_check_false(stmt.executeStep()); + stmt.finalize(); + + // Check that livemarks children don't have frecency <> 0 + stmt = mDBConn.createStatement( + "SELECT h.id FROM moz_places h " + + "JOIN moz_bookmarks b ON h.id = b.fk " + + "JOIN moz_bookmarks bp ON bp.id = b.parent " + + "JOIN moz_items_annos t ON t.item_id = bp.id " + + "JOIN moz_anno_attributes n ON t.anno_attribute_id = n.id " + + "WHERE n.name = 'livemark/feedURI' AND h.frecency <> 0 LIMIT 1"); + do_check_false(stmt.executeStep()); + stmt.finalize(); + + do_test_finished(); } } os.addObserver(expirationObserver, kExpirationFinished, false); @@ -137,105 +175,12 @@ let observer = { onDeleteVisits: function() { }, - QueryInterface: function(iid) { - if (iid.equals(Ci.nsINavHistoryObserver) || - iid.equals(Ci.nsISupports)) { - return this; - } - throw Cr.NS_ERROR_NO_INTERFACE; - } + QueryInterface: XPCOMUtils.generateQI([ + Ci.nsINavHistoryObserver + ]); } hs.addObserver(observer, false); -let syncObserver = { - _runCount: 0, - observe: function (aSubject, aTopic, aData) { - if (++this._runCount < EXPECTED_SYNCS) - return; - if (this._runCount == EXPECTED_SYNCS) { - bh.removeAllPages(); - return; - } - os.removeObserver(this, kSyncFinished, false); - - // Sanity: check that places temp table is empty - stmt = mDBConn.createStatement( - "SELECT id FROM moz_places_temp LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - // Check that frecency for not cleared items (bookmarks) has been converted - // to -MAX(visit_count, 1), so we will be able to recalculate frecency - // starting from most frecent bookmarks. - stmt = mDBConn.createStatement( - "SELECT id FROM moz_places WHERE frecency > 0 LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - stmt = mDBConn.createStatement( - "SELECT h.id FROM moz_places h WHERE h.frecency = -2 " + - "AND EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) LIMIT 1"); - do_check_true(stmt.executeStep()); - stmt.finalize(); - - // Check that all visit_counts have been brought to 0 - stmt = mDBConn.createStatement( - "SELECT id FROM moz_places WHERE visit_count <> 0 LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - // Check that all moz_places entries except bookmarks and place: have been removed - stmt = mDBConn.createStatement( - "SELECT h.id FROM moz_places h WHERE SUBSTR(h.url, 1, 6) <> 'place:' "+ - "AND NOT EXISTS (SELECT id FROM moz_bookmarks WHERE fk = h.id) LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - // Check that we only have favicons for retained places - stmt = mDBConn.createStatement( - "SELECT f.id FROM moz_favicons f WHERE NOT EXISTS " + - "(SELECT id FROM moz_places WHERE favicon_id = f.id) LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - // Check that we only have annotations for retained places - stmt = mDBConn.createStatement( - "SELECT a.id FROM moz_annos a WHERE NOT EXISTS " + - "(SELECT id FROM moz_places WHERE id = a.place_id) LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - // Check that we only have inputhistory for retained places - stmt = mDBConn.createStatement( - "SELECT i.place_id FROM moz_inputhistory i WHERE NOT EXISTS " + - "(SELECT id FROM moz_places WHERE id = i.place_id) LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - // Check that place:uris have frecency 0 - stmt = mDBConn.createStatement( - "SELECT h.id FROM moz_places h " + - "WHERE SUBSTR(h.url, 1, 6) = 'place:' AND h.frecency <> 0 LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - // Check that livemarks children don't have frecency <> 0 - stmt = mDBConn.createStatement( - "SELECT h.id FROM moz_places h " + - "JOIN moz_bookmarks b ON h.id = b.fk " + - "JOIN moz_bookmarks bp ON bp.id = b.parent " + - "JOIN moz_items_annos t ON t.item_id = bp.id " + - "JOIN moz_anno_attributes n ON t.anno_attribute_id = n.id " + - "WHERE n.name = 'livemark/feedURI' AND h.frecency <> 0 LIMIT 1"); - do_check_false(stmt.executeStep()); - stmt.finalize(); - - do_test_finished(); - } -} -os.addObserver(syncObserver, kSyncFinished, false); - -// main function run_test() { // Add a livemark with a visited and an unvisited child add_fake_livemark(); @@ -269,13 +214,23 @@ function run_test() { // Add a bookmark // Bookmarked page should have history cleared and frecency = -old_visit_count - // This will also finally sync temp tables to disk bs.insertBookmark(bs.unfiledBookmarksFolder, uri("http://typed.mozilla.org"), bs.DEFAULT_INDEX, "bookmark"); - // this visit is not synced to disk hs.addVisit(uri("http://typed.mozilla.org"), Date.now(), null, hs.TRANSITION_BOOKMARK, false, 0); + // Since we are checking frecency, we have to disable some stuff that could + // change values during test run. On idle-daily frecencies are updated. + Services.obs.removeObserver(hs, "idle-daily"); + + // executeSoon allows us to fire the places-init-complete notification before + // the removeAllPages call. Since we are creating a new database, on that + // notification we will act on initial frecency, and that could disturb + // this test's frecency checks. + do_execute_soon(function () { + bh.removeAllPages(); + }); + do_test_pending(); } diff --git a/toolkit/components/places/tests/unit/test_migrateFrecency.js b/toolkit/components/places/tests/unit/test_migrateFrecency.js index 9750cfea2d8..91cc5272efb 100644 --- a/toolkit/components/places/tests/unit/test_migrateFrecency.js +++ b/toolkit/components/places/tests/unit/test_migrateFrecency.js @@ -72,7 +72,7 @@ function run_test() { _("Now that places has migrated, check that it calculated frecencies"); var stmt = places.DBConnection.createStatement( - "SELECT COUNT(*) FROM moz_places_view WHERE frecency < 0"); + "SELECT COUNT(*) FROM moz_places WHERE frecency < 0"); stmt.executeAsync({ handleResult: function(results) { _("Should always get a result from COUNT(*)"); diff --git a/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js b/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js index bc01033f389..57f1d8fb956 100644 --- a/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js +++ b/toolkit/components/places/tests/unit/test_removeVisitsByTimeframe.js @@ -390,7 +390,7 @@ function deleteAllHistoryAndBookmarks() { * @return the frecency of aURI */ function getFrecencyForURI(aURI) { - let sql = "SELECT frecency FROM moz_places_view WHERE url = :url"; + let sql = "SELECT frecency FROM moz_places WHERE url = :url"; let stmt = dbConn.createStatement(sql); stmt.params.url = aURI.spec; do_check_true(stmt.executeStep()); @@ -407,7 +407,7 @@ function getFrecencyForURI(aURI) { * the URI of a place */ function uriExistsInMozPlaces(aURI) { - let sql = "SELECT id FROM moz_places_view WHERE url = :url"; + let sql = "SELECT id FROM moz_places WHERE url = :url"; let stmt = dbConn.createStatement(sql); stmt.params.url = aURI.spec; var exists = stmt.executeStep(); diff --git a/toolkit/components/places/tests/unit/test_update_frecency_after_delete.js b/toolkit/components/places/tests/unit/test_update_frecency_after_delete.js index a6b7658ebd8..c035632cf81 100644 --- a/toolkit/components/places/tests/unit/test_update_frecency_after_delete.js +++ b/toolkit/components/places/tests/unit/test_update_frecency_after_delete.js @@ -345,7 +345,7 @@ function createLivemark(aLmChildItemURI) { * @return the frecency of aURL */ function getFrecency(aURL) { - let sql = "SELECT frecency FROM moz_places_view WHERE url = :url"; + let sql = "SELECT frecency FROM moz_places WHERE url = :url"; let stmt = dbConn.createStatement(sql); stmt.params.url = aURL; do_check_true(stmt.executeStep());