Fixed caching of databases during runtime (#7275)
* Fixes #7268 Thanks to @jmsngls
This commit is contained in:
parent
4c42bcbb34
commit
ba9770ce95
@ -111,7 +111,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void put( keytype key, std::shared_ptr<datatype> ptr ){
|
virtual void put( keytype key, std::shared_ptr<datatype> ptr ){
|
||||||
this->data[key] = ptr;
|
this->data[key] = ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,7 +135,7 @@ public:
|
|||||||
return rathena::util::umap_random( this->data );
|
return rathena::util::umap_random( this->data );
|
||||||
}
|
}
|
||||||
|
|
||||||
void erase(keytype key) {
|
virtual void erase(keytype key) {
|
||||||
this->data.erase(key);
|
this->data.erase(key);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -143,20 +143,22 @@ public:
|
|||||||
template <typename keytype, typename datatype> class TypesafeCachedYamlDatabase : public TypesafeYamlDatabase<keytype, datatype>{
|
template <typename keytype, typename datatype> class TypesafeCachedYamlDatabase : public TypesafeYamlDatabase<keytype, datatype>{
|
||||||
private:
|
private:
|
||||||
std::vector<std::shared_ptr<datatype>> cache;
|
std::vector<std::shared_ptr<datatype>> cache;
|
||||||
|
bool loaded;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TypesafeCachedYamlDatabase( const std::string& type_, uint16 version_, uint16 minimumVersion_ ) : TypesafeYamlDatabase<keytype, datatype>( type_, version_, minimumVersion_ ){
|
TypesafeCachedYamlDatabase( const std::string& type_, uint16 version_, uint16 minimumVersion_ ) : TypesafeYamlDatabase<keytype, datatype>( type_, version_, minimumVersion_ ){
|
||||||
|
this->loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
TypesafeCachedYamlDatabase( const std::string& type_, uint16 version_ ) : TypesafeYamlDatabase<keytype, datatype>( type_, version_, version_ ){
|
TypesafeCachedYamlDatabase( const std::string& type_, uint16 version_ ) : TypesafeYamlDatabase<keytype, datatype>( type_, version_, version_ ){
|
||||||
|
this->loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() override{
|
void clear() override{
|
||||||
TypesafeYamlDatabase<keytype, datatype>::clear();
|
TypesafeYamlDatabase<keytype, datatype>::clear();
|
||||||
cache.clear();
|
cache.clear();
|
||||||
cache.shrink_to_fit();
|
cache.shrink_to_fit();
|
||||||
|
this->loaded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<datatype> find( keytype key ) override{
|
std::shared_ptr<datatype> find( keytype key ) override{
|
||||||
@ -206,6 +208,26 @@ public:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->loaded = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void erase( keytype key ) override{
|
||||||
|
TypesafeYamlDatabase<keytype, datatype>::erase( key );
|
||||||
|
|
||||||
|
// Prevent excessive usage during loading
|
||||||
|
if( this->loaded ){
|
||||||
|
this->cache[this->calculateCacheKey( key )] = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void put( keytype key, std::shared_ptr<datatype> ptr ) override{
|
||||||
|
TypesafeYamlDatabase<keytype, datatype>::put( key, ptr );
|
||||||
|
|
||||||
|
// Prevent excessive usage during loading
|
||||||
|
if( this->loaded ){
|
||||||
|
this->cache[this->calculateCacheKey( key )] = ptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user