diff options
author | Arsentiy Milchakov <milcars@mapswithme.com> | 2019-04-08 16:42:27 +0300 |
---|---|---|
committer | Tatiana Yan <tatiana.kondakova@gmail.com> | 2019-04-22 18:47:33 +0300 |
commit | 2397d5d659b53cd7d7f4787ba6ae5e24189302f2 (patch) | |
tree | a03443d801702e87dc59daa0b20e5578f37254f9 /map | |
parent | 6316937a10f0d6622890b607774b6d6668cd49f2 (diff) |
[booking] reduce count of requests to booking during filtration on map
Diffstat (limited to 'map')
-rw-r--r-- | map/booking_availability_filter.cpp | 6 | ||||
-rw-r--r-- | map/booking_filter_cache.hpp | 4 | ||||
-rw-r--r-- | map/framework.cpp | 55 | ||||
-rw-r--r-- | map/framework.hpp | 2 | ||||
-rw-r--r-- | map/search_api.cpp | 16 | ||||
-rw-r--r-- | map/search_api.hpp | 7 | ||||
-rw-r--r-- | map/viewport_search_callback.cpp | 9 | ||||
-rw-r--r-- | map/viewport_search_callback.hpp | 11 |
8 files changed, 102 insertions, 8 deletions
diff --git a/map/booking_availability_filter.cpp b/map/booking_availability_filter.cpp index 0456828b0d..ad0535dd76 100644 --- a/map/booking_availability_filter.cpp +++ b/map/booking_availability_filter.cpp @@ -129,9 +129,9 @@ void FillResults(HotelToResults && hotelToResults, std::vector<std::string> cons void FillResults(HotelToFeatureIds && hotelToFeatureIds, std::vector<std::string> const & hotelIds, availability::Cache & cache, std::vector<FeatureID> & results) { - auto const inserter = [&results](FeatureID result) + auto const inserter = [&results](FeatureID && result) { - results.push_back(result); + results.emplace_back(std::move(result)); }; FillResults(std::move(hotelToFeatureIds), hotelIds, cache, inserter); @@ -279,7 +279,7 @@ void AvailabilityFilter::ApplyFilterInternal(Source const & source, Parameters c ASSERT_LESS_OR_EQUAL(m_apiParams.m_hotelIds.size(), kMaxCountInRequest, ()); - if (m_apiParams.m_hotelIds.empty() || m_apiParams.m_hotelIds.size() > kMaxCountInRequest) + if (m_apiParams.m_hotelIds.empty()) { Source result; FillResults(std::move(hotelsToSourceValue), {} /* hotelIds */, *m_cache, result); diff --git a/map/booking_filter_cache.hpp b/map/booking_filter_cache.hpp index 049f086838..78064df4fe 100644 --- a/map/booking_filter_cache.hpp +++ b/map/booking_filter_cache.hpp @@ -61,9 +61,9 @@ private: HotelsMap m_notReadyHotels; // Max count of |m_hotelToStatus| container. // Count is unlimited when |m_maxCount| is equal to zero. - size_t const m_maxCount = 1000; + size_t const m_maxCount = 5000; // Do not use aging when |m_expiryPeriodSeconds| is equal to zero. - size_t const m_expiryPeriodSeconds = 60; + size_t const m_expiryPeriodSeconds = 300; }; std::string DebugPrint(Cache::HotelStatus status); diff --git a/map/framework.cpp b/map/framework.cpp index 2664e48280..88a1527b4d 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -313,6 +313,11 @@ void Framework::OnUserPositionChanged(m2::PointD const & position, bool hasPosit void Framework::OnViewportChanged(ScreenBase const & screen) { + auto const isSameViewport = m2::IsEqual(screen.ClipRect(), m_currentModelView.ClipRect(), + kMwmPointAccuracy, kMwmPointAccuracy); + if (isSameViewport) + return; + m_currentModelView = screen; GetSearchAPI().OnViewportChanged(GetCurrentViewport()); @@ -3848,6 +3853,56 @@ void Framework::FilterResultsForHotelsQuery(booking::filter::Tasks const & filte m_bookingFilterProcessor.ApplyFilters(results, std::move(tasksInternal), filterTasks.GetMode()); } +void Framework::FilterHotels(booking::filter::Tasks const & filterTasks, + vector<FeatureID> && featureIds) +{ + if (featureIds.size() > booking::RawApi::GetMaxHotelsInAvailabilityRequest()) + return; + + using namespace booking::filter; + + TasksRawInternal tasksInternal; + + for (auto const & task : filterTasks) + { + auto const type = task.m_type; + auto const & apiParams = task.m_filterParams.m_apiParams; + auto const & cb = task.m_filterParams.m_callback; + + if (apiParams->IsEmpty()) + continue; + + ParamsRawInternal paramsInternal + { + apiParams, + [this, type, apiParams, cb](vector<FeatureID> const & features) + { + if (features.empty()) + return; + + GetPlatform().RunTask(Platform::Thread::Gui, [this, type, features]() + { + switch (type) + { + case Type::Deals: + m_searchMarks.SetSales(features, true /* hasSale */); + break; + case Type::Availability: + m_searchMarks.SetPreparingState(features, false /* isPreparing */); + break; + } + }); + cb(apiParams, features); + } + }; + + tasksInternal.emplace_back(type, std::move(paramsInternal)); + } + + m_bookingFilterProcessor.ApplyFilters(std::move(featureIds), std::move(tasksInternal), + filterTasks.GetMode()); +} + void Framework::OnBookingFilterParamsUpdate(booking::filter::Tasks const & filterTasks) { for (auto const & task : filterTasks) diff --git a/map/framework.hpp b/map/framework.hpp index 78f3b3809d..28ef5d81e3 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -902,6 +902,8 @@ private: public: void FilterResultsForHotelsQuery(booking::filter::Tasks const & filterTasks, search::Results const & results, bool inViewport) override; + void FilterHotels(booking::filter::Tasks const & filterTasks, + vector<FeatureID> && featureIds) override; void OnBookingFilterParamsUpdate(booking::filter::Tasks const & filterTasks) override; booking::AvailabilityParams GetLastBookingAvailabilityParams() const; diff --git a/map/search_api.cpp b/map/search_api.cpp index 170497bb77..11e9d86f3b 100644 --- a/map/search_api.cpp +++ b/map/search_api.cpp @@ -9,6 +9,7 @@ #include "search/geometry_utils.hpp" #include "search/hotels_filter.hpp" #include "search/tracer.hpp" +#include "search/utils.hpp" #include "storage/downloader_search_params.hpp" @@ -210,6 +211,7 @@ bool SearchAPI::SearchInViewport(ViewportSearchParams const & params) }; p.m_onResults = ViewportSearchCallback( + m_viewport, static_cast<ViewportSearchCallback::Delegate &>(*this), params.m_bookingFilterTasks, [this, params](Results const & results) { @@ -336,6 +338,20 @@ void SearchAPI::FilterResultsForHotelsQuery(booking::filter::Tasks const & filte m_delegate.FilterResultsForHotelsQuery(filterTasks, results, inViewport); } +void SearchAPI::FilterAllHotelsInViewport(m2::RectD const & viewport, + booking::filter::Tasks const & filterTasks) +{ + vector<FeatureID> featureIds; + auto const types = search::GetCategoryTypes("hotel", "en", GetDefaultCategories()); + search::ForEachOfTypesInRect(m_dataSource, types, m_viewport, + [&featureIds](FeatureID const & id) + { + featureIds.push_back(id); + }); + + m_delegate.FilterHotels(filterTasks, move(featureIds)); +} + void SearchAPI::OnBookmarksCreated(vector<pair<kml::MarkId, kml::BookmarkData>> const & marks) { vector<BookmarkIdDoc> data; diff --git a/map/search_api.hpp b/map/search_api.hpp index a2707859ba..c6c4dde85b 100644 --- a/map/search_api.hpp +++ b/map/search_api.hpp @@ -84,6 +84,11 @@ public: { } + virtual void FilterHotels(booking::filter::Tasks const & filterTasks, + vector<FeatureID> && featureIds) + { + } + virtual void OnBookingFilterParamsUpdate(booking::filter::Tasks const & filterTasks) {} virtual search::ProductInfo GetProductInfo(search::Result const & result) const { return {}; }; @@ -136,6 +141,8 @@ public: search::ProductInfo GetProductInfo(search::Result const & result) const override; void FilterResultsForHotelsQuery(booking::filter::Tasks const & filterTasks, search::Results const & results, bool inViewport) override; + void FilterAllHotelsInViewport(m2::RectD const & viewport, + booking::filter::Tasks const & filterTasks) override; void OnBookmarksCreated(std::vector<std::pair<kml::MarkId, kml::BookmarkData>> const & marks); void OnBookmarksUpdated(std::vector<std::pair<kml::MarkId, kml::BookmarkData>> const & marks); diff --git a/map/viewport_search_callback.cpp b/map/viewport_search_callback.cpp index 88e598333d..40f89c0866 100644 --- a/map/viewport_search_callback.cpp +++ b/map/viewport_search_callback.cpp @@ -1,6 +1,7 @@ #include "map/viewport_search_callback.hpp" #include "search/result.hpp" +#include "search/utils.hpp" #include "base/assert.hpp" @@ -31,10 +32,11 @@ booking::filter::Types FillBookingFilterTypes(search::Results const & results, namespace search { -ViewportSearchCallback::ViewportSearchCallback(Delegate & delegate, +ViewportSearchCallback::ViewportSearchCallback(m2::RectD const & viewport, Delegate & delegate, booking::filter::Tasks const & bookingFilterTasks, OnResults const & onResults) - : m_delegate(delegate) + : m_viewport(viewport) + , m_delegate(delegate) , m_onResults(onResults) , m_firstCall(true) , m_lastResultsSize(0) @@ -94,6 +96,9 @@ void ViewportSearchCallback::operator()(Results const & results) if (results.IsEndedNormal() && results.GetType() == Results::Type::Hotels && !m_bookingFilterTasks.IsEmpty()) { + if (m_viewport.IsValid()) + m_delegate.FilterAllHotelsInViewport(m_viewport, m_bookingFilterTasks); + m_delegate.FilterResultsForHotelsQuery(m_bookingFilterTasks, results, true /* inViewport */); } diff --git a/map/viewport_search_callback.hpp b/map/viewport_search_callback.hpp index 1603df3193..78e508c01a 100644 --- a/map/viewport_search_callback.hpp +++ b/map/viewport_search_callback.hpp @@ -6,7 +6,11 @@ #include "search/result.hpp" #include "search/search_params.hpp" +#include "geometry/rect2d.hpp" + #include <functional> +#include <string> +#include <vector> namespace search { @@ -30,16 +34,21 @@ public: bool clear, booking::filter::Types types) = 0; virtual void FilterResultsForHotelsQuery(booking::filter::Tasks const & filterTasks, search::Results const & results, bool inViewport) = 0; + virtual void FilterAllHotelsInViewport(m2::RectD const & viewport, + booking::filter::Tasks const & filterTasks) = 0; }; using OnResults = SearchParams::OnResults; - ViewportSearchCallback(Delegate & delegate, booking::filter::Tasks const & bookingFilterTasks, + ViewportSearchCallback(m2::RectD const & viewport, Delegate & delegate, + booking::filter::Tasks const & bookingFilterTasks, OnResults const & onResults); void operator()(Results const & results); private: + m2::RectD m_viewport; + Delegate & m_delegate; OnResults m_onResults; |