diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index c6469a888b..58c4bd7eb4 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -1391,6 +1391,14 @@ kml::GroupIdCollection BookmarkManager::GetCompilationOfType(kml::MarkGroupId pa return result; } +std::vector BookmarkManager::GetAllPaidCategoriesIds() const +{ + return GetCategoriesFromCatalog([](kml::AccessRules accessRules) + { + return accessRules == kml::AccessRules::Paid; + }); +} + void BookmarkManager::PrepareBookmarksAddresses(std::vector & bookmarksForSort, AddressesCollection & newAddresses) { @@ -3327,13 +3335,6 @@ void BookmarkManager::SetAllCategoriesVisibility(CategoryFilterType const filter } } -std::vector BookmarkManager::GetAllPaidCategoriesIds() const -{ - return GetCategoriesFromCatalog([](kml::AccessRules accessRules) { - return accessRules == kml::AccessRules::Paid; - }); -} - bool BookmarkManager::CanConvert() const { // The conversion available only after successful migration. diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index 2709a89332..28ec35bc77 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -508,6 +508,8 @@ public: kml::GroupIdCollection GetChildrenCategories(kml::MarkGroupId parentCategoryId) const; kml::GroupIdCollection GetChildrenCollections(kml::MarkGroupId parentCategoryId) const; + std::vector GetAllPaidCategoriesIds() const; + private: class MarksChangesTracker : public df::UserMarksProvider { @@ -783,8 +785,6 @@ private: SortedBlocksCollection & sortedBlocks) const; void SortTracksByTime(std::vector & tracks) const; - std::vector GetAllPaidCategoriesIds() const; - kml::MarkId GetTrackSelectionMarkId(kml::TrackId trackId) const; int GetTrackSelectionMarkMinZoom(kml::TrackId trackId) const; void SetTrackSelectionMark(kml::TrackId trackId, m2::PointD const & pt, double distance); diff --git a/map/catalog_headers_provider.cpp b/map/catalog_headers_provider.cpp index c8c6d1ac26..4d16b2c79e 100644 --- a/map/catalog_headers_provider.cpp +++ b/map/catalog_headers_provider.cpp @@ -1,7 +1,8 @@ #include "map/catalog_headers_provider.hpp" -#include "map/bookmark_catalog.hpp" +#include "map/bookmark_manager.hpp" +#include #include CatalogHeadersProvider::CatalogHeadersProvider(PositionProvider const & positionProvider, @@ -11,11 +12,11 @@ CatalogHeadersProvider::CatalogHeadersProvider(PositionProvider const & position { } -void CatalogHeadersProvider::SetBookmarkCatalog(BookmarkCatalog const * bookmarkCatalog) +void CatalogHeadersProvider::SetBookmarkManager(BookmarkManager const * bookmarkManager) { - ASSERT(bookmarkCatalog != nullptr, ()); + ASSERT(bookmarkManager != nullptr, ()); - m_bookmarkCatalog = bookmarkCatalog; + m_bookmarkManager = bookmarkManager; } platform::HttpClient::Headers CatalogHeadersProvider::GetHeaders() @@ -39,10 +40,17 @@ platform::HttpClient::Headers CatalogHeadersProvider::GetHeaders() } params.m_countryGeoIds.assign(countries.cbegin(), countries.cend()); - if (m_bookmarkCatalog != nullptr && !m_bookmarkCatalog->GetDownloadedIds().empty()) + auto ids = m_bookmarkManager->GetAllPaidCategoriesIds(); + if (m_bookmarkManager != nullptr && !ids.empty()) { - auto const & ids = m_bookmarkCatalog->GetDownloadedIds(); - params.m_downloadedGuidesIds.assign(ids.cbegin(), ids.cend()); + size_t constexpr kMaxCountOfGuides = 30; + if (ids.size() > kMaxCountOfGuides) + { + static std::mt19937 generator(std::random_device{}()); + std::shuffle(ids.begin(), ids.end(), generator); + ids.resize(kMaxCountOfGuides); + } + params.m_downloadedGuidesIds = std::move(ids); } return web_api::GetCatalogHeaders(params); diff --git a/map/catalog_headers_provider.hpp b/map/catalog_headers_provider.hpp index 5095dc5dbc..141881acd2 100644 --- a/map/catalog_headers_provider.hpp +++ b/map/catalog_headers_provider.hpp @@ -10,7 +10,7 @@ #include -class BookmarkCatalog; +class BookmarkManager; class CatalogHeadersProvider { @@ -18,7 +18,7 @@ public: CatalogHeadersProvider(PositionProvider const & positionProvider, storage::Storage const & storage); - void SetBookmarkCatalog(BookmarkCatalog const * bookmarkCatalog); + void SetBookmarkManager(BookmarkManager const * bookmarkManager); platform::HttpClient::Headers GetHeaders(); std::optional GetPositionHeader(); @@ -26,5 +26,5 @@ public: private: PositionProvider const & m_positionProvider; storage::Storage const & m_storage; - BookmarkCatalog const * m_bookmarkCatalog = nullptr; + BookmarkManager const * m_bookmarkManager = nullptr; }; diff --git a/map/framework.cpp b/map/framework.cpp index 9d2d097d52..ca16a4624f 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -467,7 +467,7 @@ Framework::Framework(FrameworkParams const & params) m_bmManager->InitRegionAddressGetter(m_featuresFetcher.GetDataSource(), *m_infoGetter); - catalogHeadersProvider->SetBookmarkCatalog(&m_bmManager->GetCatalog()); + catalogHeadersProvider->SetBookmarkManager(m_bmManager.get()); m_parsedMapApi.SetBookmarkManager(m_bmManager.get()); m_routingManager.SetBookmarkManager(m_bmManager.get()); m_guidesManager.SetBookmarkManager(m_bmManager.get());