Make `getBestTargetBookId` public.

This commit is contained in:
Matthieu Gautier 2024-02-07 16:26:35 +01:00
parent f3a604380c
commit 3e9d50fecb
2 changed files with 15 additions and 5 deletions

View File

@ -280,7 +280,7 @@ class Library: public std::enable_shared_from_this<Library>
* *
* All invalid bookmarks (ie pointing to unknown books, no check is made on bookmark pointing to * 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. * 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<int, int>: <The number of bookmarks updated>, <Number of invalid bookmarks before migration was performed>. * @return A tuple<int, int>: <The number of bookmarks updated>, <Number of invalid bookmarks before migration was performed>.
*/ */
@ -290,9 +290,7 @@ class Library: public std::enable_shared_from_this<Library>
* Migrate all bookmarks associated to a specific book. * Migrate all bookmarks associated to a specific book.
* *
* All bookmarks associated to `sourceBookId` book will be migrated to a better 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. * "Better book", will be determined using method `getBestTargetBookId`.
* 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.
* *
* @param sourceBookId the source bookId of the bookmarks to migrate. * @param sourceBookId the source bookId of the bookmarks to migrate.
* @param migrationMode how we will find the best book. * @param migrationMode how we will find the best book.
@ -311,6 +309,18 @@ class Library: public std::enable_shared_from_this<Library>
*/ */
int migrateBookmarks(const std::string& sourceBookId, const std::string& targetBookId); 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 // XXX: This is a non-thread-safe operation
const Book& getBookById(const std::string& id) const; const Book& getBookById(const std::string& id) const;
// XXX: This is a non-thread-safe operation // XXX: This is a non-thread-safe operation
@ -457,7 +467,6 @@ private: // functions
std::vector<std::string> getBookPropValueSet(BookStrPropMemFn p) const; std::vector<std::string> getBookPropValueSet(BookStrPropMemFn p) const;
BookIdCollection filterViaBookDB(const Filter& filter) const; BookIdCollection filterViaBookDB(const Filter& filter) const;
void cleanupBookCollection(BookIdCollection& books, const std::string& sourceBookId, MigrationMode migrationMode) 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; unsigned int getBookCount_not_protected(const bool localBooks, const bool remoteBooks) const;
void updateBookDB(const Book& book); void updateBookDB(const Book& book);
void dropCache(const std::string& bookId); void dropCache(const std::string& bookId);

View File

@ -192,6 +192,7 @@ void Library::cleanupBookCollection(BookIdCollection& books, const std::string&
} }
std::string Library::getBestTargetBookId(const Bookmark& bookmark, MigrationMode migrationMode) const { std::string Library::getBestTargetBookId(const Bookmark& bookmark, MigrationMode migrationMode) const {
std::lock_guard<std::recursive_mutex> lock(m_mutex);
// Search for a existing book with the same name // Search for a existing book with the same name
auto book_filter = Filter(); auto book_filter = Filter();
if (!bookmark.getBookName().empty()) { if (!bookmark.getBookName().empty()) {