Library::removeBookById() updates the revision

This commit is contained in:
Veloman Yunkan 2022-10-09 22:58:19 +04:00
parent 9fd1423100
commit ce8b2bf9d9
3 changed files with 13 additions and 3 deletions

View File

@ -332,8 +332,8 @@ class Library
/** /**
* Return the current revision of the library. * Return the current revision of the library.
* *
* The revision of the library is updated (incremented by one) only by * The revision of the library is updated (incremented by one) by
* the addBook() operation. * the addBook() and removeBookById() operations.
* *
* @return Current revision of the library. * @return Current revision of the library.
*/ */

View File

@ -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) // 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 // (And setMaxSize doesn't actually reduce the cache size, extra cached items
// will be removed in put or getOrPut). // 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 Library::Revision Library::getRevision() const

View File

@ -801,8 +801,14 @@ TEST_F(LibraryTest, removeBooksNotUpdatedSince)
lib.addBook(lib.getBookByIdThreadSafe(id)); lib.addBook(lib.getBookByIdThreadSafe(id));
} }
EXPECT_GT(lib.getRevision(), rev);
const uint64_t rev2 = lib.getRevision();
EXPECT_EQ(9u, lib.removeBooksNotUpdatedSince(rev)); EXPECT_EQ(9u, lib.removeBooksNotUpdatedSince(rev));
EXPECT_GT(lib.getRevision(), rev2);
EXPECT_FILTER_RESULTS(kiwix::Filter(), EXPECT_FILTER_RESULTS(kiwix::Filter(),
"Islam Stack Exchange", "Islam Stack Exchange",
"Movies & TV Stack Exchange", "Movies & TV Stack Exchange",