diff --git a/src/lib/bookmarks/bookmarksimport/firefoximporter.h b/src/lib/bookmarks/bookmarksimport/firefoximporter.h --- a/src/lib/bookmarks/bookmarksimport/firefoximporter.h +++ b/src/lib/bookmarks/bookmarksimport/firefoximporter.h @@ -39,7 +39,7 @@ private: enum Type { - Url, + Url = 1, Folder, Separator, Invalid diff --git a/src/lib/bookmarks/bookmarksimport/firefoximporter.cpp b/src/lib/bookmarks/bookmarksimport/firefoximporter.cpp --- a/src/lib/bookmarks/bookmarksimport/firefoximporter.cpp +++ b/src/lib/bookmarks/bookmarksimport/firefoximporter.cpp @@ -89,33 +89,31 @@ root->setTitle(QStringLiteral("Firefox Import")); QSqlQuery query(QSqlDatabase::database(CONNECTION)); - query.prepare(QStringLiteral("SELECT id, parent, type, title, fk FROM moz_bookmarks WHERE fk NOT NULL OR type = 3")); + query.prepare(QStringLiteral(R"( + -- Calculate depth of items in tree. + WITH RECURSIVE depth_cte AS ( + SELECT id, 0 AS depth FROM moz_bookmarks WHERE parent = 0 + UNION ALL + SELECT moz_bookmarks.id AS id, depth+1 FROM moz_bookmarks + INNER JOIN depth_cte ON depth_cte.id = moz_bookmarks.parent + ) + SELECT moz_bookmarks.id, parent, type, moz_bookmarks.title, url FROM moz_bookmarks + LEFT OUTER JOIN moz_places ON moz_places.id = fk + INNER JOIN depth_cte ON depth_cte.id = moz_bookmarks.id + -- Exclude invalid items, the root folder and special 'place' scheme urls. + WHERE (type = 2 AND moz_bookmarks.guid <> 'root________') OR (type = 1 AND NOT (fk IS NULL OR url LIKE 'place:%')) + -- Order by depth so that parents are created before their children. + ORDER BY depth, position + )")); query.exec(); while (query.next()) { Item item; item.id = query.value(0).toInt(); item.parent = query.value(1).toInt(); item.type = typeFromValue(query.value(2).toInt()); item.title = query.value(3).toString(); - int fk = query.value(4).toInt(); - - if (item.type == BookmarkItem::Invalid) { - continue; - } - - QSqlQuery query(QSqlDatabase::database(CONNECTION)); - query.prepare(QStringLiteral("SELECT url FROM moz_places WHERE id=?")); - query.addBindValue(fk); - query.exec(); - - if (query.next()) { - item.url = query.value(0).toUrl(); - } - - if (item.url.scheme() == QLatin1String("place")) { - continue; - } + item.url = query.value(4).toUrl(); items.append(item); }