Bug 1389716 - `Bookmarks.reorder` shouldn't call `withConnectionWrapper` from within a transaction. r?adw draft
authorKit Cambridge <kit@yakshaving.ninja>
Fri, 11 Aug 2017 19:02:48 -0700
changeset 645240 02248c2d80890a76dde5f72d72694e102a3007c7
parent 645074 80ff3f300e05f38f96c385b03d1973a966a2bd35
child 725866 ba3a9a805214f234408656c1dfe254e965f774e0
push id73714
push userbmo:kit@mozilla.com
push dateSat, 12 Aug 2017 02:03:17 +0000
reviewersadw
bugs1389716
milestone57.0a1
Bug 1389716 - `Bookmarks.reorder` shouldn't call `withConnectionWrapper` from within a transaction. r?adw MozReview-Commit-ID: A6aMesfFcpF
toolkit/components/places/Bookmarks.jsm
--- a/toolkit/components/places/Bookmarks.jsm
+++ b/toolkit/components/places/Bookmarks.jsm
@@ -1705,35 +1705,31 @@ function fetchRecentBookmarks(numberOfIt
           numberOfItems,
         });
 
       return rows.length ? rowsToItemsArray(rows) : [];
     }
   );
 }
 
-function fetchBookmarksByParent(info) {
-  return PlacesUtils.withConnectionWrapper("Bookmarks.jsm: fetchBookmarksByParent",
-    async function(db) {
+async function fetchBookmarksByParent(db, info) {
+  let rows = await db.executeCached(
+    `SELECT b.guid, IFNULL(p.guid, "") AS parentGuid, b.position AS 'index',
+            b.dateAdded, b.lastModified, b.type, IFNULL(b.title, "") AS title,
+            h.url AS url, b.id AS _id, b.parent AS _parentId,
+            (SELECT count(*) FROM moz_bookmarks WHERE parent = b.id) AS _childCount,
+            p.parent AS _grandParentId, b.syncStatus AS _syncStatus
+     FROM moz_bookmarks b
+     LEFT JOIN moz_bookmarks p ON p.id = b.parent
+     LEFT JOIN moz_places h ON h.id = b.fk
+     WHERE p.guid = :parentGuid
+     ORDER BY b.position ASC
+    `, { parentGuid: info.parentGuid });
 
-    let rows = await db.executeCached(
-      `SELECT b.guid, IFNULL(p.guid, "") AS parentGuid, b.position AS 'index',
-              b.dateAdded, b.lastModified, b.type, IFNULL(b.title, "") AS title,
-              h.url AS url, b.id AS _id, b.parent AS _parentId,
-              (SELECT count(*) FROM moz_bookmarks WHERE parent = b.id) AS _childCount,
-              p.parent AS _grandParentId, b.syncStatus AS _syncStatus
-       FROM moz_bookmarks b
-       LEFT JOIN moz_bookmarks p ON p.id = b.parent
-       LEFT JOIN moz_places h ON h.id = b.fk
-       WHERE p.guid = :parentGuid
-       ORDER BY b.position ASC
-      `, { parentGuid: info.parentGuid });
-
-    return rowsToItemsArray(rows);
-  });
+  return rowsToItemsArray(rows);
 }
 
 // Remove implementation.
 
 function removeBookmark(item, options) {
   return PlacesUtils.withConnectionWrapper("Bookmarks.jsm: removeBookmark",
     async function(db) {
     let urls;
@@ -1798,20 +1794,20 @@ function removeBookmark(item, options) {
 
     return item;
   });
 }
 
 // Reorder implementation.
 
 function reorderChildren(parent, orderedChildrenGuids, options) {
-  return PlacesUtils.withConnectionWrapper("Bookmarks.jsm: updateBookmark",
+  return PlacesUtils.withConnectionWrapper("Bookmarks.jsm: reorderChildren",
     db => db.executeTransaction(async function() {
       // Select all of the direct children for the given parent.
-      let children = await fetchBookmarksByParent({ parentGuid: parent.guid });
+      let children = await fetchBookmarksByParent(db, { parentGuid: parent.guid });
       if (!children.length) {
         return [];
       }
 
       // Maps of GUIDs to indices for fast lookups in the comparator function.
       let guidIndices = new Map();
       let currentIndices = new Map();
       for (let i = 0; i < orderedChildrenGuids.length; ++i) {