From ad2eb5255343fde825b396406a3f5a14a9b769c2 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Sun, 28 Nov 2021 19:53:48 +0400 Subject: [PATCH] Thread safe dumping of the OPDS feed --- src/opds_dumper.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/opds_dumper.cpp b/src/opds_dumper.cpp index 7d463f714..3570633c2 100644 --- a/src/opds_dumper.cpp +++ b/src/opds_dumper.cpp @@ -108,10 +108,15 @@ BooksData getBooksData(const Library* library, const std::vector& b { BooksData booksData; for ( const auto& bookId : bookIds ) { - const Book& book = library->getBookById(bookId); - booksData.push_back(kainjow::mustache::object{ - {"entry", getSingleBookEntryXML(book, false, endpointRoot, partial)} - }); + try { + const Book book = library->getBookByIdThreadSafe(bookId); + booksData.push_back(kainjow::mustache::object{ + {"entry", getSingleBookEntryXML(book, false, endpointRoot, partial)} + }); + } catch ( const std::out_of_range& ) { + // the book was removed from the library since its id was obtained + // ignore it + } } return booksData;