Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit e02f3fcb authored by Stefan Brüns's avatar Stefan Brüns

[Bookmarks Runner] Remove duplicate results for bookmarks

Summary:
An entry from the moz_places db may have several referring entries
in the moz_bookmarks db, i.e. where moz_places.id = moz_bookmarks.fk.
One of these entries is the "main" entry, while the other ones are used
for tags. Only the main entry has a title, while the others have not.
The tag entries have the same type as the main entry, even the parents
have the same type (folder).

Another source for duplicate URLs are manually created bookmarks, e.g.
in different folders. These may have the same or different titles.

To remove these duplicates, merge all entries with the same URL. If a
URL has multiple entries, keep all with distinct titles, otherwise keep
at least one - a bookmark may have an empty title.

See also T9626

Test Plan:
- Create a bookmark
- Add one or more tags
- Open FFs bookmarks sidebar
- Copy and paste the new entry
- Copy and paste the new entry again, change its title

Search for the new bookmark. It should appear exactly twice, once
with the original title, once with the modified one.
Without patch, it appears 3 times, plus once more for each tag.

Caveat: The bookmarks db has to be checkpointed to make the new
entries visible in the main DB file.  To force checkpointing, execute:
$> sqlite3 -column -header  ~/.mozilla/firefox/*.default/places.sqlite "PRAGMA wal_checkpoint"

Reviewers: #plasma, broulik

Reviewed By: #plasma, broulik

Subscribers: broulik, davidedmundson, zzag, ngraham, plasma-devel

Tags: #plasma

Maniphest Tasks: T9626

Differential Revision: https://phabricator.kde.org/D15357
parent 17380886
......@@ -99,6 +99,7 @@ QList< BookmarkMatch > Firefox::match(const QString& term, bool addEverything)
+ escapedTerm + "%')");
}
QList<QVariantMap> results = m_fetchsqlite->query(query, QMap<QString, QVariant>());
QMultiMap<QString, QString> uniqueResults;
foreach(QVariantMap result, results) {
const QString title = result.value(QStringLiteral("title")).toString();
const QUrl url = result.value(QStringLiteral("url")).toUrl();
......@@ -109,7 +110,34 @@ QList< BookmarkMatch > Firefox::match(const QString& term, bool addEverything)
continue;
}
BookmarkMatch bookmarkMatch( m_favicon, term, title, url.toString());
auto urlString = url.toString();
// After joining we may have multiple results for each URL:
// 1) one for each bookmark folder (same or different titles)
// 2) one for each tag (no title for all but the first entry)
auto keyRange = uniqueResults.equal_range(urlString);
auto it = keyRange.first;
if (!title.isEmpty()) {
while (it != keyRange.second) {
if (*it == title) {
// same URL and title in multiple bookmark folders
break;
}
if (it->isEmpty()) {
// add a title if there was none for the URL
*it = title;
break;
}
++it;
}
}
if (it == keyRange.second) {
// first or unique entry
uniqueResults.insert(urlString, title);
}
}
for (auto result = uniqueResults.constKeyValueBegin(); result != uniqueResults.constKeyValueEnd(); ++result) {
BookmarkMatch bookmarkMatch(m_favicon, term, (*result).second, (*result).first);
bookmarkMatch.addTo(matches, addEverything);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment