[map] Updated wiki loader.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako
2025-09-17 23:31:25 -03:00
committed by x7z4w
parent 61f665c7d4
commit c63135159c
3 changed files with 23 additions and 22 deletions

View File

@@ -2,8 +2,6 @@
#include "indexer/data_source.hpp"
#include "base/assert.hpp"
#include "defines.hpp"
namespace descriptions
@@ -20,17 +18,28 @@ std::string Loader::GetWikiDescription(FeatureID const & featureId, std::vector<
if (!value.m_cont.IsExist(DESCRIPTIONS_FILE_TAG))
return {};
EntryPtr entry;
{
std::lock_guard<std::mutex> lock(m_mutex);
entry = m_deserializers.try_emplace(featureId.m_mwmId, std::make_shared<Entry>()).first->second;
}
// No need to have separate mutexes for each MWM since there is no concurrent Wiki pages reading.
// Pros: lock is called once and a simple logic with OnMwmDeregistered synchronization.
/// @todo Consider removing mutex at all or make wiki loading async (PlacePage info).
ASSERT(entry, ());
std::lock_guard lock(m_mutex);
Deserializer & deserializer = m_deserializers[featureId.m_mwmId];
auto readerPtr = value.m_cont.GetReader(DESCRIPTIONS_FILE_TAG);
std::lock_guard<std::mutex> lock(entry->m_mutex);
return entry->m_deserializer.Deserialize(*readerPtr.GetPtr(), featureId.m_index, langPriority);
return deserializer.Deserialize(*readerPtr.GetPtr(), featureId.m_index, langPriority);
}
void Loader::OnMwmDeregistered(platform::LocalCountryFile const & countryFile)
{
std::lock_guard lock(m_mutex);
for (auto it = m_deserializers.begin(); it != m_deserializers.end(); ++it)
{
if (it->first.IsDeregistered(countryFile))
{
m_deserializers.erase(it);
break;
}
}
}
} // namespace descriptions

View File

@@ -5,9 +5,7 @@
#include "indexer/feature_decl.hpp"
#include "indexer/mwm_set.hpp"
#include <cstdint>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
@@ -23,18 +21,11 @@ public:
explicit Loader(DataSource const & dataSource) : m_dataSource(dataSource) {}
std::string GetWikiDescription(FeatureID const & featureId, std::vector<int8_t> const & langPriority);
void OnMwmDeregistered(platform::LocalCountryFile const & countryFile);
private:
struct Entry
{
std::mutex m_mutex;
Deserializer m_deserializer;
};
using EntryPtr = std::shared_ptr<Entry>;
DataSource const & m_dataSource;
std::map<MwmSet::MwmId, EntryPtr> m_deserializers;
std::map<MwmSet::MwmId, Deserializer> m_deserializers;
std::mutex m_mutex;
};
} // namespace descriptions

View File

@@ -452,6 +452,7 @@ void Framework::OnMapDeregistered(platform::LocalCountryFile const & localFile)
m_transitManager.OnMwmDeregistered(localFile);
m_isolinesManager.OnMwmDeregistered(localFile);
m_trafficManager.OnMwmDeregistered(localFile);
m_descriptionsLoader->OnMwmDeregistered(localFile);
m_storage.DeleteCustomCountryVersion(localFile);
};