[promo] load cities section into delegate lazy

This commit is contained in:
Arsentiy Milchakov 2019-07-12 13:33:22 +03:00 committed by mpimenov
parent 34aa3d4379
commit 81ceea3847
2 changed files with 13 additions and 7 deletions

View file

@ -8,9 +8,8 @@
#include "base/string_utils.hpp"
PromoDelegate::PromoDelegate(DataSource const & dataSource, search::CityFinder & cityFinder)
: m_dataSource(dataSource), m_cityFinder(cityFinder), m_cities(dataSource)
: m_dataSource(dataSource), m_cityFinder(cityFinder)
{
m_cities.Load();
}
std::string PromoDelegate::GetCityId(m2::PointD const & point)
@ -25,12 +24,18 @@ std::string PromoDelegate::GetCityId(m2::PointD const & point)
if (!feature)
return {};
base::GeoObjectId id;
if (ftypes::IsPromoCatalogChecker::Instance()(*feature) &&
m_cities.GetGeoObjectId(feature->GetID(), id))
if (!ftypes::IsPromoCatalogChecker::Instance()(*feature))
return {};
if (!m_cities)
{
return strings::to_string(id);
m_cities = std::make_unique<indexer::FeatureIdToGeoObjectIdBimap>(m_dataSource);
m_cities->Load();
}
base::GeoObjectId id;
if (m_cities->GetGeoObjectId(feature->GetID(), id))
return strings::to_string(id);
return {};
}

View file

@ -6,6 +6,7 @@
#include "geometry/point2d.hpp"
#include <memory>
#include <string>
class DataSource;
@ -25,5 +26,5 @@ public:
private:
DataSource const & m_dataSource;
search::CityFinder & m_cityFinder;
indexer::FeatureIdToGeoObjectIdBimap m_cities;
std::unique_ptr<indexer::FeatureIdToGeoObjectIdBimap> m_cities;
};