aboutsummaryrefslogtreecommitdiff
path: root/src/server/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/database')
-rw-r--r--src/server/database/Database/QueryResult.cpp2
-rw-r--r--src/server/database/PrecompiledHeaders/databasePCH.h1
-rw-r--r--src/server/database/Updater/UpdateFetcher.cpp59
-rw-r--r--src/server/database/Updater/UpdateFetcher.h23
4 files changed, 46 insertions, 39 deletions
diff --git a/src/server/database/Database/QueryResult.cpp b/src/server/database/Database/QueryResult.cpp
index 99f81ae7ec6..02bbcefd2a9 100644
--- a/src/server/database/Database/QueryResult.cpp
+++ b/src/server/database/Database/QueryResult.cpp
@@ -389,7 +389,7 @@ void InitializeDatabaseFieldMetadata(QueryResultFieldMetadata* meta, MySQLField
meta->TypeName = FieldTypeToString(field->type, field->flags);
meta->Index = fieldIndex;
meta->Type = MysqlTypeToFieldType(field->type, field->flags);
- meta->Converter = binaryProtocol ? BinaryValueConverters[AsUnderlyingType(meta->Type)].get() : FromStringValueConverters[AsUnderlyingType(meta->Type)].get();
+ meta->Converter = binaryProtocol ? BinaryValueConverters[std::ptrdiff_t(meta->Type)].get() : FromStringValueConverters[std::ptrdiff_t(meta->Type)].get();
}
}
diff --git a/src/server/database/PrecompiledHeaders/databasePCH.h b/src/server/database/PrecompiledHeaders/databasePCH.h
index d8c2af9bb0e..59943cb99a9 100644
--- a/src/server/database/PrecompiledHeaders/databasePCH.h
+++ b/src/server/database/PrecompiledHeaders/databasePCH.h
@@ -16,5 +16,6 @@
*/
#include "DatabaseEnv.h"
+#include "Errors.h"
#include "Log.h"
#include "MySQLHacks.h"
diff --git a/src/server/database/Updater/UpdateFetcher.cpp b/src/server/database/Updater/UpdateFetcher.cpp
index 659b919cf3d..fbcb3625a8a 100644
--- a/src/server/database/Updater/UpdateFetcher.cpp
+++ b/src/server/database/Updater/UpdateFetcher.cpp
@@ -46,9 +46,7 @@ UpdateFetcher::UpdateFetcher(Path const& sourceDirectory,
{
}
-UpdateFetcher::~UpdateFetcher()
-{
-}
+UpdateFetcher::~UpdateFetcher() = default;
UpdateFetcher::LocaleFileStorage UpdateFetcher::GetFileList() const
{
@@ -80,7 +78,7 @@ void UpdateFetcher::FillFileListRecursively(Path const& path, LocaleFileStorage&
// Check for doubled filenames
// Because elements are only compared by their filenames, this is ok
- if (storage.find(entry) != storage.end())
+ if (storage.contains(entry))
{
TC_LOG_FATAL("sql.updates", "Duplicate filename \"{}\" occurred. Because updates are ordered " \
"by their filenames, every name needs to be unique!", itr->path().generic_string());
@@ -106,7 +104,7 @@ UpdateFetcher::DirectoryStorage UpdateFetcher::ReceiveIncludedDirectories() cons
Field* fields = result->Fetch();
std::string path = fields[0].GetString();
- if (path.substr(0, 1) == "$")
+ if (path.starts_with("$"))
path = _sourceDirectory->generic_string() + path.substr(1);
Path const p(path);
@@ -117,7 +115,7 @@ UpdateFetcher::DirectoryStorage UpdateFetcher::ReceiveIncludedDirectories() cons
continue;
}
- DirectoryEntry const entry = { p, AppliedFileEntry::StateConvert(fields[1].GetString()) };
+ DirectoryEntry const entry = { p, AppliedFileEntry::StateConvert(fields[1].GetStringView()) };
directories.push_back(entry);
TC_LOG_TRACE("sql.updates", "Added applied file \"{}\" from remote.", p.filename().generic_string());
@@ -140,7 +138,7 @@ UpdateFetcher::AppliedFileStorage UpdateFetcher::ReceiveAppliedFiles() const
Field* fields = result->Fetch();
AppliedFileEntry const entry = { fields[0].GetString(), fields[1].GetString(),
- AppliedFileEntry::StateConvert(fields[2].GetString()), fields[3].GetUInt64() };
+ AppliedFileEntry::StateConvert(fields[2].GetStringView()), fields[3].GetUInt64() };
map.insert(std::make_pair(entry.name, entry));
}
@@ -184,24 +182,26 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
size_t countArchivedUpdates = 0;
// Count updates
- for (auto const& entry : applied)
- if (entry.second.state == RELEASED)
+ for (auto const& [_, appliedFile] : applied)
+ if (appliedFile.state == RELEASED)
++countRecentUpdates;
else
++countArchivedUpdates;
// Fill hash to name cache
HashToFileNameStorage hashToName;
- for (auto entry : applied)
- hashToName.insert(std::make_pair(entry.second.hash, entry.first));
+ for (auto const& [name, appliedFile] : applied)
+ hashToName.try_emplace(appliedFile.hash, name);
size_t importedUpdates = 0;
for (auto const& availableQuery : available)
{
- TC_LOG_DEBUG("sql.updates", "Checking update \"{}\"...", availableQuery.first.filename().generic_string());
+ std::string availableQueryFilename = availableQuery.first.filename().string();
+
+ TC_LOG_DEBUG("sql.updates", "Checking update \"{}\"...", availableQueryFilename);
- AppliedFileStorage::const_iterator iter = applied.find(availableQuery.first.filename().string());
+ AppliedFileStorage::const_iterator iter = applied.find(availableQueryFilename);
if (iter != applied.end())
{
// If redundancy is disabled, skip it, because the update is already applied.
@@ -234,26 +234,23 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
if (hashIter != hashToName.end())
{
// Check if the original file was removed. If not, we've got a problem.
- LocaleFileStorage::const_iterator localeIter;
- // Push localeIter forward
- for (localeIter = available.begin(); (localeIter != available.end()) &&
- (localeIter->first.filename().string() != hashIter->second); ++localeIter);
+ LocaleFileStorage::const_iterator localeIter = available.find(hashIter->second);
// Conflict!
if (localeIter != available.end())
{
- TC_LOG_WARN("sql.updates", ">> It seems like the update \"{}\" \'{}\' was renamed, but the old file is still there! " \
+ TC_LOG_WARN("sql.updates", ">> It seems like the update \"{}\" \'{}\' was renamed, but the old file is still there! "
"Treating it as a new file! (It is probably an unmodified copy of the file \"{}\")",
- availableQuery.first.filename().string(), hash.substr(0, 7),
+ availableQueryFilename, hash.substr(0, 7),
localeIter->first.filename().string());
}
// It is safe to treat the file as renamed here
else
{
TC_LOG_INFO("sql.updates", ">> Renaming update \"{}\" to \"{}\" \'{}\'.",
- hashIter->second, availableQuery.first.filename().string(), hash.substr(0, 7));
+ hashIter->second, availableQueryFilename, hash.substr(0, 7));
- RenameEntry(hashIter->second, availableQuery.first.filename().string());
+ RenameEntry(hashIter->second, availableQueryFilename);
applied.erase(hashIter->second);
continue;
}
@@ -262,7 +259,7 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
else
{
TC_LOG_INFO("sql.updates", ">> Applying update \"{}\" \'{}\'...",
- availableQuery.first.filename().string(), hash.substr(0, 7));
+ availableQueryFilename, hash.substr(0, 7));
}
}
// Rehash the update entry if it exists in our database with an empty hash.
@@ -270,7 +267,7 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
{
mode = MODE_REHASH;
- TC_LOG_INFO("sql.updates", ">> Re-hashing update \"{}\" \'{}\'...", availableQuery.first.filename().string(),
+ TC_LOG_INFO("sql.updates", ">> Re-hashing update \"{}\" \'{}\'...", availableQueryFilename,
hash.substr(0, 7));
}
else
@@ -278,7 +275,7 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
// If the hash of the files differs from the one stored in our database, reapply the update (because it changed).
if (iter->second.hash != hash)
{
- TC_LOG_INFO("sql.updates", ">> Reapplying update \"{}\" \'{}\' -> \'{}\' (it changed)...", availableQuery.first.filename().string(),
+ TC_LOG_INFO("sql.updates", ">> Reapplying update \"{}\" \'{}\' -> \'{}\' (it changed)...", availableQueryFilename,
iter->second.hash.substr(0, 7), hash.substr(0, 7));
}
else
@@ -287,9 +284,9 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
if (iter->second.state != availableQuery.second)
{
TC_LOG_DEBUG("sql.updates", ">> Updating the state of \"{}\" to \'{}\'...",
- availableQuery.first.filename().string(), AppliedFileEntry::StateConvert(availableQuery.second));
+ availableQueryFilename, AppliedFileEntry::StateConvert(availableQuery.second));
- UpdateState(availableQuery.first.filename().string(), availableQuery.second);
+ UpdateState(availableQueryFilename, availableQuery.second);
}
TC_LOG_DEBUG("sql.updates", ">> Update is already applied and matches the hash \'{}\'.", hash.substr(0, 7));
@@ -300,7 +297,7 @@ UpdateResult UpdateFetcher::Update(bool const redundancyChecks,
}
uint32 speed = 0;
- AppliedFileEntry const file = { availableQuery.first.filename().string(), hash, availableQuery.second, 0 };
+ AppliedFileEntry const file = { availableQueryFilename, hash, availableQuery.second, 0 };
switch (mode)
{
@@ -361,8 +358,8 @@ uint32 UpdateFetcher::Apply(Path const& path) const
void UpdateFetcher::UpdateEntry(AppliedFileEntry const& entry, uint32 const speed) const
{
- std::string const update = "REPLACE INTO `updates` (`name`, `hash`, `state`, `speed`) VALUES (\"" +
- entry.name + "\", \"" + entry.hash + "\", \'" + entry.GetStateAsString() + "\', " + std::to_string(speed) + ")";
+ std::string const update = Trinity::StringFormat(R"(REPLACE INTO `updates` (`name`, `hash`, `state`, `speed`) VALUES ("{}", "{}", '{}', {}))",
+ entry.name, entry.hash, entry.GetStateAsString(), speed);
// Update database
_apply(update);
@@ -418,7 +415,7 @@ void UpdateFetcher::UpdateState(std::string const& name, State const state) cons
_apply(update);
}
-bool UpdateFetcher::PathCompare::operator()(LocaleFileEntry const& left, LocaleFileEntry const& right) const
+std::string UpdateFetcher::PathCompare::MakeComparisonObject(LocaleFileEntry const& arg)
{
- return left.first.filename().string() < right.first.filename().string();
+ return arg.first.filename().string();
}
diff --git a/src/server/database/Updater/UpdateFetcher.h b/src/server/database/Updater/UpdateFetcher.h
index 3accf8e3a92..324041ceaca 100644
--- a/src/server/database/Updater/UpdateFetcher.h
+++ b/src/server/database/Updater/UpdateFetcher.h
@@ -18,7 +18,7 @@
#ifndef UpdateFetcher_h__
#define UpdateFetcher_h__
-#include "Define.h"
+#include "Common.h"
#include "DatabaseEnvFwd.h"
#include <functional>
#include <set>
@@ -87,17 +87,17 @@ private:
uint64 const timestamp;
- static inline State StateConvert(std::string const& state)
+ static inline State StateConvert(std::string_view const& state)
{
- return (state == "RELEASED") ? RELEASED : ARCHIVED;
+ return (state == "RELEASED"sv) ? RELEASED : ARCHIVED;
}
- static inline std::string StateConvert(State const state)
+ static inline std::string_view StateConvert(State const state)
{
- return (state == RELEASED) ? "RELEASED" : "ARCHIVED";
+ return (state == RELEASED) ? "RELEASED"sv : "ARCHIVED"sv;
}
- std::string GetStateAsString() const
+ std::string_view GetStateAsString() const
{
return StateConvert(state);
}
@@ -109,7 +109,16 @@ private:
struct PathCompare
{
- bool operator()(LocaleFileEntry const& left, LocaleFileEntry const& right) const;
+ static std::string MakeComparisonObject(LocaleFileEntry const& arg);
+ static std::string const& MakeComparisonObject(std::string const& arg) { return arg; }
+
+ template<typename L, typename R>
+ bool operator()(L const& left, R const& right) const
+ {
+ return PathCompare::MakeComparisonObject(left) < PathCompare::MakeComparisonObject(right);
+ }
+
+ using is_transparent = int;
};
typedef std::set<LocaleFileEntry, PathCompare> LocaleFileStorage;