diff --git a/include/library.h b/include/library.h index 87b0315ea..856a3a9ef 100644 --- a/include/library.h +++ b/include/library.h @@ -332,8 +332,8 @@ class Library /** * Return the current revision of the library. * - * The revision of the library is updated (incremented by one) only by - * the addBook() operation. + * The revision of the library is updated (incremented by one) by + * the addBook() and removeBookById() operations. * * @return Current revision of the library. */ diff --git a/src/library.cpp b/src/library.cpp index 07eb428cb..508d7c8e1 100644 --- a/src/library.cpp +++ b/src/library.cpp @@ -221,7 +221,11 @@ bool Library::removeBookById(const std::string& id) // Having a too big cache is not a problem here (or it would have been before) // (And setMaxSize doesn't actually reduce the cache size, extra cached items // will be removed in put or getOrPut). - return mp_impl->m_books.erase(id) == 1; + const bool bookWasRemoved = mp_impl->m_books.erase(id) == 1; + if ( bookWasRemoved ) { + ++mp_impl->m_revision; + } + return bookWasRemoved; } Library::Revision Library::getRevision() const diff --git a/test/library.cpp b/test/library.cpp index ef41c4d7c..60762cb51 100644 --- a/test/library.cpp +++ b/test/library.cpp @@ -801,8 +801,14 @@ TEST_F(LibraryTest, removeBooksNotUpdatedSince) lib.addBook(lib.getBookByIdThreadSafe(id)); } + EXPECT_GT(lib.getRevision(), rev); + + const uint64_t rev2 = lib.getRevision(); + EXPECT_EQ(9u, lib.removeBooksNotUpdatedSince(rev)); + EXPECT_GT(lib.getRevision(), rev2); + EXPECT_FILTER_RESULTS(kiwix::Filter(), "Islam Stack Exchange", "Movies & TV Stack Exchange",