forked from organicmaps/organicmaps
[search] Search FMD_CUISINE for old mwms only due to perfomance reasons.
This commit is contained in:
parent
d4971ec2da
commit
0b8b83c8ff
12 changed files with 99 additions and 46 deletions
|
@ -1,12 +1,15 @@
|
|||
#include "base/timer.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
#include "base/get_time.hpp"
|
||||
#include "base/gmtime.hpp"
|
||||
#include "base/macros.hpp"
|
||||
#include "base/timegm.hpp"
|
||||
#include "base/timer.hpp"
|
||||
|
||||
#include "std/target_os.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <iomanip>
|
||||
|
@ -60,6 +63,37 @@ uint32_t GenerateYYMMDD(int year, int month, int day)
|
|||
return result;
|
||||
}
|
||||
|
||||
uint32_t GenerateYYMMDD(uint64_t secondsSinceEpoch)
|
||||
{
|
||||
auto const tm = GmTime(SecondsSinceEpochToTimeT(secondsSinceEpoch));
|
||||
return GenerateYYMMDD(tm.tm_year, tm.tm_mon, tm.tm_mday);
|
||||
}
|
||||
|
||||
uint64_t YYMMDDToSecondsSinceEpoch(uint32_t yymmdd)
|
||||
{
|
||||
auto constexpr partsCount = 3;
|
||||
// From left to right YY MM DD.
|
||||
std::array<int, partsCount> parts{}; // Initialize with zeros.
|
||||
for (auto i = partsCount - 1; i >= 0; --i)
|
||||
{
|
||||
parts[i] = yymmdd % 100;
|
||||
yymmdd /= 100;
|
||||
}
|
||||
ASSERT_EQUAL(yymmdd, 0, ("Version is too big."));
|
||||
|
||||
ASSERT_GREATER_OR_EQUAL(parts[1], 1, ("Month should be in range [1, 12]"));
|
||||
ASSERT_LESS_OR_EQUAL(parts[1], 12, ("Month should be in range [1, 12]"));
|
||||
ASSERT_GREATER_OR_EQUAL(parts[2], 1, ("Day should be in range [1, 31]"));
|
||||
ASSERT_LESS_OR_EQUAL(parts[2], 31, ("Day should be in range [1, 31]"));
|
||||
|
||||
std::tm tm{};
|
||||
tm.tm_year = parts[0] + 100;
|
||||
tm.tm_mon = parts[1] - 1;
|
||||
tm.tm_mday = parts[2];
|
||||
|
||||
return TimeTToSecondsSinceEpoch(TimeGM(tm));
|
||||
}
|
||||
|
||||
uint64_t SecondsSinceEpoch()
|
||||
{
|
||||
return TimeTToSecondsSinceEpoch(::time(nullptr));
|
||||
|
|
|
@ -40,6 +40,8 @@ std::string FormatCurrentTime();
|
|||
/// \param day The day of the month, in the range 1 to 31.
|
||||
/// \return Timestamp.
|
||||
uint32_t GenerateYYMMDD(int year, int month, int day);
|
||||
uint32_t GenerateYYMMDD(uint64_t secondsSinceEpoch);
|
||||
uint64_t YYMMDDToSecondsSinceEpoch(uint32_t yymmdd);
|
||||
|
||||
uint64_t SecondsSinceEpoch();
|
||||
|
||||
|
|
|
@ -53,11 +53,13 @@ namespace generator
|
|||
{
|
||||
namespace tests_support
|
||||
{
|
||||
TestMwmBuilder::TestMwmBuilder(platform::LocalCountryFile & file, feature::DataHeader::MapType type)
|
||||
TestMwmBuilder::TestMwmBuilder(platform::LocalCountryFile & file, feature::DataHeader::MapType type,
|
||||
uint32_t version)
|
||||
: m_file(file)
|
||||
, m_type(type)
|
||||
, m_collector(make_unique<feature::FeaturesCollector>(m_file.GetPath(MapOptions::Map) +
|
||||
EXTENSION_TMP))
|
||||
, m_collector(
|
||||
make_unique<feature::FeaturesCollector>(m_file.GetPath(MapOptions::Map) + EXTENSION_TMP))
|
||||
, m_version(version)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -121,6 +123,7 @@ void TestMwmBuilder::Finish()
|
|||
feature::GenerateInfo info;
|
||||
info.m_targetDir = m_file.GetDirectory();
|
||||
info.m_tmpDir = m_file.GetDirectory();
|
||||
info.m_versionDate = static_cast<uint32_t>(base::YYMMDDToSecondsSinceEpoch(m_version));
|
||||
CHECK(GenerateFinalFeatures(info, m_file.GetCountryFile().GetName(), m_type),
|
||||
("Can't sort features."));
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "indexer/data_header.hpp"
|
||||
|
||||
#include "base/timer.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -27,7 +29,8 @@ class TestFeature;
|
|||
class TestMwmBuilder
|
||||
{
|
||||
public:
|
||||
TestMwmBuilder(platform::LocalCountryFile & file, feature::DataHeader::MapType type);
|
||||
TestMwmBuilder(platform::LocalCountryFile & file, feature::DataHeader::MapType type,
|
||||
uint32_t version = base::GenerateYYMMDD(base::SecondsSinceEpoch()));
|
||||
|
||||
~TestMwmBuilder();
|
||||
|
||||
|
@ -43,6 +46,7 @@ private:
|
|||
std::vector<std::string> m_languages;
|
||||
std::unique_ptr<feature::FeaturesCollector> m_collector;
|
||||
TestIdToBoundariesTable m_boundariesTable;
|
||||
uint32_t m_version = 0;
|
||||
};
|
||||
} // namespace tests_support
|
||||
} // namespace generator
|
||||
|
|
|
@ -3,11 +3,17 @@
|
|||
#include "platform/local_country_file_utils.hpp"
|
||||
|
||||
#include "base/stl_helpers.hpp"
|
||||
#include "base/timer.hpp"
|
||||
|
||||
namespace generator
|
||||
{
|
||||
namespace tests_support
|
||||
{
|
||||
TestWithCustomMwms::TestWithCustomMwms()
|
||||
{
|
||||
m_version = base::GenerateYYMMDD(base::SecondsSinceEpoch());
|
||||
}
|
||||
|
||||
TestWithCustomMwms::~TestWithCustomMwms()
|
||||
{
|
||||
for (auto const & file : m_files)
|
||||
|
@ -20,5 +26,7 @@ void TestWithCustomMwms::Cleanup(platform::LocalCountryFile const & file)
|
|||
platform::CountryIndexes::DeleteFromDisk(file);
|
||||
file.DeleteFromDisk(MapOptions::Map);
|
||||
}
|
||||
|
||||
void TestWithCustomMwms::SetMwmVersion(uint32_t version) { m_version = version; }
|
||||
} // namespace tests_support
|
||||
} // namespace generator
|
||||
|
|
|
@ -26,6 +26,8 @@ namespace tests_support
|
|||
class TestWithCustomMwms : public TestWithClassificator
|
||||
{
|
||||
public:
|
||||
TestWithCustomMwms();
|
||||
|
||||
~TestWithCustomMwms() override;
|
||||
|
||||
// Creates a physical country file on a disk, which will be removed
|
||||
|
@ -43,7 +45,7 @@ public:
|
|||
Cleanup(file);
|
||||
|
||||
{
|
||||
generator::tests_support::TestMwmBuilder builder(file, type);
|
||||
generator::tests_support::TestMwmBuilder builder(file, type, m_version);
|
||||
fn(builder);
|
||||
}
|
||||
|
||||
|
@ -83,6 +85,8 @@ public:
|
|||
return BuildMwm(name, feature::DataHeader::country, std::forward<BuildFn>(fn));
|
||||
}
|
||||
|
||||
void SetMwmVersion(uint32_t version);
|
||||
|
||||
protected:
|
||||
static void Cleanup(platform::LocalCountryFile const & file);
|
||||
|
||||
|
@ -90,6 +94,7 @@ protected:
|
|||
|
||||
EditableDataSource m_dataSource;
|
||||
std::vector<platform::LocalCountryFile> m_files;
|
||||
uint32_t m_version = 0;
|
||||
};
|
||||
} // namespace tests_support
|
||||
} // namespace generator
|
||||
|
|
|
@ -31,6 +31,12 @@ bool MwmTraits::HasRoutingIndex() const
|
|||
return GetVersion() >= kFirstVersionWithRoutingIndex;
|
||||
}
|
||||
|
||||
bool MwmTraits::HasCuisineTypes() const
|
||||
{
|
||||
uint32_t constexpr kFirstVersionWithCuisineTypes = 180917;
|
||||
return GetVersion() >= kFirstVersionWithCuisineTypes;
|
||||
}
|
||||
|
||||
string DebugPrint(MwmTraits::SearchIndexFormat format)
|
||||
{
|
||||
switch (format)
|
||||
|
|
|
@ -52,6 +52,8 @@ public:
|
|||
// Check whether mwm has routing index section.
|
||||
bool HasRoutingIndex() const;
|
||||
|
||||
bool HasCuisineTypes() const;
|
||||
|
||||
private:
|
||||
Format GetFormat() const { return m_version.GetFormat(); }
|
||||
uint32_t GetVersion() const { return m_version.GetVersion(); }
|
||||
|
|
|
@ -24,30 +24,6 @@ namespace
|
|||
// because a user can forget to update maps after a new app version has been installed
|
||||
// automatically in the background.
|
||||
uint64_t constexpr kMaxSecondsTillNoEdits = 3600 * 24 * 31 * 2;
|
||||
|
||||
uint64_t VersionToSecondsSinceEpoch(uint64_t version)
|
||||
{
|
||||
auto constexpr partsCount = 3;
|
||||
// From left to right YY MM DD.
|
||||
array<int, partsCount> parts{}; // Initialize with zeros.
|
||||
for (auto i = partsCount - 1; i >= 0; --i)
|
||||
{
|
||||
parts[i] = version % 100;
|
||||
version /= 100;
|
||||
}
|
||||
ASSERT_EQUAL(version, 0, ("Version is too big."));
|
||||
|
||||
ASSERT_LESS_OR_EQUAL(parts[1], 12, ("Month should be in range [1, 12]"));
|
||||
ASSERT_LESS_OR_EQUAL(parts[2], 31, ("Day should be in range [1, 31]"));
|
||||
|
||||
std::tm tm{};
|
||||
tm.tm_year = parts[0] + 100;
|
||||
tm.tm_mon = parts[1] - 1;
|
||||
tm.tm_mday = parts[2];
|
||||
|
||||
return base::TimeTToSecondsSinceEpoch(base::TimeGM(tm));
|
||||
}
|
||||
|
||||
char const MWM_PROLOG[] = "MWM";
|
||||
|
||||
template <class TSource>
|
||||
|
@ -60,7 +36,7 @@ void ReadVersionT(TSource & src, MwmVersion & version)
|
|||
if (strcmp(prolog, MWM_PROLOG) != 0)
|
||||
{
|
||||
version.SetFormat(Format::v2);
|
||||
version.SetSecondsSinceEpoch(VersionToSecondsSinceEpoch(111101));
|
||||
version.SetSecondsSinceEpoch(base::YYMMDDToSecondsSinceEpoch(111101));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -68,9 +44,14 @@ void ReadVersionT(TSource & src, MwmVersion & version)
|
|||
// with the correspondent return value.
|
||||
version.SetFormat(static_cast<Format>(ReadVarUint<uint32_t>(src)));
|
||||
if (version.GetFormat() < Format::v8)
|
||||
version.SetSecondsSinceEpoch(VersionToSecondsSinceEpoch(ReadVarUint<uint64_t>(src)));
|
||||
{
|
||||
version.SetSecondsSinceEpoch(
|
||||
base::YYMMDDToSecondsSinceEpoch(static_cast<uint32_t>(ReadVarUint<uint64_t>(src))));
|
||||
}
|
||||
else
|
||||
{
|
||||
version.SetSecondsSinceEpoch(ReadVarUint<uint32_t>(src));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
#include "indexer/feature_meta.hpp"
|
||||
#include "indexer/ftypes_matcher.hpp"
|
||||
|
||||
#include "platform/mwm_traits.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
#include "base/checked_cast.hpp"
|
||||
|
||||
|
@ -17,18 +19,19 @@ namespace search
|
|||
namespace cuisine_filter
|
||||
{
|
||||
// Description -------------------------------------------------------------------------------------
|
||||
void Description::FromFeature(FeatureType & ft)
|
||||
Description::Description(FeatureType & ft, bool fromMetadata)
|
||||
{
|
||||
m_types.clear();
|
||||
ft.ForEachType([this](uint32_t t) {
|
||||
if (ftypes::IsCuisineChecker::Instance().IsMatched(t))
|
||||
m_types.push_back(t);
|
||||
});
|
||||
if (!fromMetadata)
|
||||
{
|
||||
ft.ForEachType([this](uint32_t t) {
|
||||
if (ftypes::IsCuisineChecker::Instance().IsMatched(t))
|
||||
m_types.push_back(t);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Old maps support.
|
||||
if (!m_types.empty())
|
||||
return;
|
||||
|
||||
auto const & metadata = ft.GetMetadata();
|
||||
if (!metadata.Has(feature::Metadata::FMD_CUISINE))
|
||||
return;
|
||||
|
@ -93,16 +96,17 @@ CuisineFilter::Descriptions const & CuisineFilter::GetDescriptions(MwmContext co
|
|||
if (it != m_descriptions.end())
|
||||
return it->second;
|
||||
|
||||
auto & value = context.m_value;
|
||||
version::MwmTraits mwmTraits(value.GetMwmVersion());
|
||||
auto const loadFromMetadata = !mwmTraits.HasCuisineTypes();
|
||||
|
||||
auto const food = m_food.Get(context);
|
||||
auto & descriptions = m_descriptions[mwmId];
|
||||
food.ForEach([&descriptions, &context](uint64_t bit) {
|
||||
food.ForEach([&descriptions, &context, &loadFromMetadata](uint64_t bit) {
|
||||
auto const id = base::asserted_cast<uint32_t>(bit);
|
||||
FeatureType ft;
|
||||
|
||||
Description description;
|
||||
if (context.GetFeature(id, ft))
|
||||
description.FromFeature(ft);
|
||||
descriptions.emplace_back(id, description);
|
||||
descriptions.emplace_back(id, Description(ft, loadFromMetadata));
|
||||
});
|
||||
return descriptions;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,8 @@ namespace cuisine_filter
|
|||
{
|
||||
struct Description
|
||||
{
|
||||
void FromFeature(FeatureType & ft);
|
||||
Description() = default;
|
||||
Description(FeatureType & ft, bool fromMetadata);
|
||||
|
||||
std::vector<uint32_t> m_types;
|
||||
};
|
||||
|
|
|
@ -1483,6 +1483,9 @@ UNIT_CLASS_TEST(ProcessorTest, CuisineMetadataTest)
|
|||
TestCafeWithCuisine kebab(m2::PointD(1.0, 1.0), "Useless name", "en", "kebab");
|
||||
TestCafeWithCuisine tapas(m2::PointD(1.0, 1.0), "Useless name", "en", "tapas");
|
||||
|
||||
// Metadata is supported for old maps only.
|
||||
SetMwmVersion(180801);
|
||||
|
||||
auto countryId = BuildCountry(countryName, [&](TestMwmBuilder & builder) {
|
||||
builder.Add(kebab);
|
||||
builder.Add(tapas);
|
||||
|
|
Loading…
Add table
Reference in a new issue