Bug 724739 - Part 0: Correct schema comment; project in getGuidsIDsForFolders; short-circuit updatePositions. r=nalexander
authorRichard Newman <rnewman@mozilla.com>
Tue, 10 Apr 2012 23:21:51 -0700
changeset 94717 5633c5648fed42deb0ede34b7e6dd271a32518e7
parent 94716 ced9405748208b7dc216f7b8a6b33799cf634849
child 94718 6124a190cc2b17f531c2e3dfcf0e1eb65a22504f
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnalexander
bugs724739
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 724739 - Part 0: Correct schema comment; project in getGuidsIDsForFolders; short-circuit updatePositions. r=nalexander
mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java
mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java
--- a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java
+++ b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksDataAccessor.java
@@ -74,33 +74,41 @@ public class AndroidBrowserBookmarksData
 
   @Override
   public void wipe() {
     Uri uri = getUri();
     Logger.info(LOG_TAG, "wiping (except for special guids): " + uri);
     context.getContentResolver().delete(uri, EXCLUDE_SPECIAL_GUIDS_WHERE_CLAUSE, null);
   }
 
+  private String[] GUID_AND_ID = new String[] { BrowserContract.Bookmarks.GUID,
+                                                BrowserContract.Bookmarks._ID };
+
   protected Cursor getGuidsIDsForFolders() throws NullCursorException {
     // Exclude "places" and "tags", in case they've ended up in the DB.
     String where = BOOKMARK_IS_FOLDER + " AND " + GUID_NOT_TAGS_OR_PLACES;
-    return queryHelper.safeQuery(".getGuidsIDsForFolders", null, where, null, null);
+    return queryHelper.safeQuery(".getGuidsIDsForFolders", GUID_AND_ID, where, null, null);
   }
 
   /**
    * Issue a request to the Content Provider to update the positions of the
    * records named by the provided GUIDs to the index of their GUID in the
    * provided array.
    *
    * @param childArray
    *        A sequence of GUID strings.
    */
   public int updatePositions(ArrayList<String> childArray) {
-    Logger.debug(LOG_TAG, "Updating positions for " + childArray.size() + " items.");
-    String[] args = childArray.toArray(new String[childArray.size()]);
+    final int size = childArray.size();
+    if (size == 0) {
+      return 0;
+    }
+
+    Logger.debug(LOG_TAG, "Updating positions for " + size + " items.");
+    String[] args = childArray.toArray(new String[size]);
     return context.getContentResolver().update(getPositionsUri(), new ContentValues(), null, args);
   }
 
   /**
    * Bump the modified time of a record by ID.
    */
   public int bumpModified(long id, long modified) {
     Logger.debug(LOG_TAG, "Bumping modified for " + id + " to " + modified);
--- a/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java
+++ b/mobile/android/base/sync/repositories/android/AndroidBrowserBookmarksRepositorySession.java
@@ -125,16 +125,20 @@ public class AndroidBrowserBookmarksRepo
    * representation which we are able to stably map upstream.
    *
    * That is:
    *
    * * We should not upload a `places` record or a `tags` record.
    * * We can stably _store_ menu/toolbar/unfiled/mobile as special GUIDs, and set
      * their parent ID as appropriate on upload.
    *
+   * Fortunately, Fennec stores our representation of the data, not Places: that is,
+   * there's a "places" root, containing "mobile", "menu", "toolbar", etc.
+   *
+   * These are guaranteed to exist when the database is created.
    *
    * = Places folders =
    *
    * guid        root_name   folder_id   parent
    * ----------  ----------  ----------  ----------
    * ?           places      1           0
    * ?           menu        2           1
    * ?           toolbar     3           1
@@ -143,17 +147,20 @@ public class AndroidBrowserBookmarksRepo
    *
    * ?           mobile*     474         1
    *
    *
    * = Fennec folders =
    *
    * guid        folder_id   parent
    * ----------  ----------  ----------
-   * mobile      ?           0
+   * places      0           0
+   * mobile      1           0
+   * menu        2           0
+   * etc.
    *
   */
   public static final Map<String, String> SPECIAL_GUID_PARENTS;
 
   static {
     HashMap<String, String> m = new HashMap<String, String>();
     m.put("places",  null);
     m.put("menu",    "places");