From 4bdc1d76c68f116894570c559cd2190ce8d58bde Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Fri, 10 Feb 2023 19:11:39 +0100 Subject: [PATCH 1/3] Testing of /catalog/v2/entries for count={0,-1} --- test/library_server.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/library_server.cpp b/test/library_server.cpp index 5c0d65b1f..5cba0eeb3 100644 --- a/test/library_server.cpp +++ b/test/library_server.cpp @@ -656,6 +656,42 @@ TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_range) ); } + { + // count=-1 disables the limit on the number of results + const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?count=-1"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(maskVariableOPDSFeedData(r->body), + CATALOG_V2_ENTRIES_PREAMBLE("?count=-1") + " Filtered Entries (count=-1)\n" + " YYYY-MM-DDThh:mm:ssZ\n" + " 3\n" + " 0\n" + " 3\n" + CHARLES_RAY_CATALOG_ENTRY + RAY_CHARLES_CATALOG_ENTRY + UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY + "\n" + ); + } + + { + // count=0 disables the limit on the number of results + const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?count=0"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(maskVariableOPDSFeedData(r->body), + CATALOG_V2_ENTRIES_PREAMBLE("?count=0") + " Filtered Entries (count=0)\n" + " YYYY-MM-DDThh:mm:ssZ\n" + " 3\n" + " 0\n" + " 3\n" + CHARLES_RAY_CATALOG_ENTRY + RAY_CHARLES_CATALOG_ENTRY + UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY + "\n" + ); + } + { const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?count=2"); EXPECT_EQ(r->status, 200); From 340fadd9be9e8b00627412a9da41992cd60210fa Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Fri, 10 Feb 2023 19:13:33 +0100 Subject: [PATCH 2/3] Testing of /catalog/search?count=-1 --- test/library_server.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/library_server.cpp b/test/library_server.cpp index 5cba0eeb3..405df90ac 100644 --- a/test/library_server.cpp +++ b/test/library_server.cpp @@ -358,6 +358,26 @@ TEST_F(LibraryServerTest, catalog_search_by_language) TEST_F(LibraryServerTest, catalog_search_results_pagination) { { + // count=-1 disables the limit on the number of results + const auto r = zfs1_->GET("/ROOT%23%3F/catalog/search?count=-1"); + EXPECT_EQ(r->status, 200); + EXPECT_EQ(maskVariableOPDSFeedData(r->body), + OPDS_FEED_TAG + " 12345678-90ab-cdef-1234-567890abcdef\n" + " Filtered zims (count=-1)\n" + " YYYY-MM-DDThh:mm:ssZ\n" + " 3\n" + " 0\n" + " 3\n" + CATALOG_LINK_TAGS + CHARLES_RAY_CATALOG_ENTRY + RAY_CHARLES_CATALOG_ENTRY + UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY + "\n" + ); + } + { + // count=0 disables the limit on the number of results const auto r = zfs1_->GET("/ROOT%23%3F/catalog/search?count=0"); EXPECT_EQ(r->status, 200); EXPECT_EQ(maskVariableOPDSFeedData(r->body), From 2e0124710aa491c31294bfef05e3a2ae56c84205 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Fri, 10 Feb 2023 19:15:29 +0100 Subject: [PATCH 3/3] `?count=0` OPDS catalog queries return 0 results ... which is a useful way of finding out the total number of results with the least consumption of resources. --- src/server/internalServer.cpp | 4 ++-- test/library_server.cpp | 14 ++++---------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index b50c6e650..89b2efb13 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -1021,9 +1021,9 @@ InternalServer::search_catalog(const RequestContext& request, const auto filter = get_search_filter(request); std::vector bookIdsToDump = mp_library->filter(filter); const auto totalResults = bookIdsToDump.size(); - const size_t count = request.get_optional_param("count", 10UL); + const long count = request.get_optional_param("count", 10L); const size_t startIndex = request.get_optional_param("start", 0UL); - const size_t intendedCount = count > 0 ? count : bookIdsToDump.size(); + const size_t intendedCount = count >= 0 ? count : bookIdsToDump.size(); bookIdsToDump = subrange(bookIdsToDump, startIndex, intendedCount); opdsDumper.setOpenSearchInfo(totalResults, startIndex, bookIdsToDump.size()); return bookIdsToDump; diff --git a/test/library_server.cpp b/test/library_server.cpp index 405df90ac..723d0c60c 100644 --- a/test/library_server.cpp +++ b/test/library_server.cpp @@ -377,7 +377,7 @@ TEST_F(LibraryServerTest, catalog_search_results_pagination) ); } { - // count=0 disables the limit on the number of results + // count=0 returns 0 results const auto r = zfs1_->GET("/ROOT%23%3F/catalog/search?count=0"); EXPECT_EQ(r->status, 200); EXPECT_EQ(maskVariableOPDSFeedData(r->body), @@ -387,11 +387,8 @@ TEST_F(LibraryServerTest, catalog_search_results_pagination) " YYYY-MM-DDThh:mm:ssZ\n" " 3\n" " 0\n" - " 3\n" + " 0\n" CATALOG_LINK_TAGS - CHARLES_RAY_CATALOG_ENTRY - RAY_CHARLES_CATALOG_ENTRY - UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY "\n" ); } @@ -695,7 +692,7 @@ TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_range) } { - // count=0 disables the limit on the number of results + // count=0 returns 0 results const auto r = zfs1_->GET("/ROOT%23%3F/catalog/v2/entries?count=0"); EXPECT_EQ(r->status, 200); EXPECT_EQ(maskVariableOPDSFeedData(r->body), @@ -704,10 +701,7 @@ TEST_F(LibraryServerTest, catalog_v2_entries_filtered_by_range) " YYYY-MM-DDThh:mm:ssZ\n" " 3\n" " 0\n" - " 3\n" - CHARLES_RAY_CATALOG_ENTRY - RAY_CHARLES_CATALOG_ENTRY - UNCATEGORIZED_RAY_CHARLES_CATALOG_ENTRY + " 0\n" "\n" ); }