From 3e9d50fecb7cf7c2f0ee996723d39964a21db256 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 7 Feb 2024 16:26:35 +0100 Subject: [PATCH] Make `getBestTargetBookId` public. --- include/library.h | 19 ++++++++++++++----- src/library.cpp | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/library.h b/include/library.h index 895c20166..354876456 100644 --- a/include/library.h +++ b/include/library.h @@ -280,7 +280,7 @@ class Library: public std::enable_shared_from_this * * All invalid bookmarks (ie pointing to unknown books, no check is made on bookmark pointing to * invalid articles of valid book) will be migrated (if possible) to a better book. - * "Better book", will be determined using heuristics based on book name, flavour and date. + * "Better book", will be determined using method `getBestTargetBookId`. * * @return A tuple: , . */ @@ -290,9 +290,7 @@ class Library: public std::enable_shared_from_this * Migrate all bookmarks associated to a specific book. * * All bookmarks associated to `sourceBookId` book will be migrated to a better book. - * "Better book", will be determined using heuristics based on book name, flavour and date. - * Be carrefull, when using with `migrationModde == ALLOW_DOWGRADE`, the bookmark will be migrated to a different book - * even if the bookmark points to an existing book and the other book is older than the current one. + * "Better book", will be determined using method `getBestTargetBookId`. * * @param sourceBookId the source bookId of the bookmarks to migrate. * @param migrationMode how we will find the best book. @@ -311,6 +309,18 @@ class Library: public std::enable_shared_from_this */ int migrateBookmarks(const std::string& sourceBookId, const std::string& targetBookId); + /** + * Get the best available bookId for a bookmark. + * + * Given a bookmark, return the best available bookId. + * "best available bookId" is determined using heuristitcs based on book name, flavour and date. + * + * @param bookmark The bookmark to search the bookId for. + * @param migrationMode The migration mode to use. + * @return A bookId. Potentially empty string if no suitable book found. + */ + std::string getBestTargetBookId(const Bookmark& bookmark, MigrationMode migrationMode) const; + // XXX: This is a non-thread-safe operation const Book& getBookById(const std::string& id) const; // XXX: This is a non-thread-safe operation @@ -457,7 +467,6 @@ private: // functions std::vector getBookPropValueSet(BookStrPropMemFn p) const; BookIdCollection filterViaBookDB(const Filter& filter) const; void cleanupBookCollection(BookIdCollection& books, const std::string& sourceBookId, MigrationMode migrationMode) const; - std::string getBestTargetBookId(const Bookmark& bookmark, MigrationMode migrationMode) const; unsigned int getBookCount_not_protected(const bool localBooks, const bool remoteBooks) const; void updateBookDB(const Book& book); void dropCache(const std::string& bookId); diff --git a/src/library.cpp b/src/library.cpp index e5cc989cc..0e88867d3 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -192,6 +192,7 @@ void Library::cleanupBookCollection(BookIdCollection& books, const std::string& } std::string Library::getBestTargetBookId(const Bookmark& bookmark, MigrationMode migrationMode) const { + std::lock_guard lock(m_mutex); // Search for a existing book with the same name auto book_filter = Filter(); if (!bookmark.getBookName().empty()) {