mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-18 08:28:32 +01:00
Core/Updater: Add some info about the count of applied updates.
* some minor improvements
* add a log message when database updates are disabled.
(cherry picked from commit a5b3862bc1)
This commit is contained in:
@@ -117,6 +117,9 @@ DatabaseLoader& DatabaseLoader::AddDatabase(DatabaseWorkerPool<T>& pool, std::st
|
||||
|
||||
bool DatabaseLoader::Load()
|
||||
{
|
||||
if (!_updateFlags)
|
||||
TC_LOG_INFO("sql.updates", "Automatic database updates are disabled for all databases!");
|
||||
|
||||
if (!OpenDatabases())
|
||||
return false;
|
||||
|
||||
|
||||
@@ -271,10 +271,10 @@ bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool)
|
||||
[&](Path const& file) { DBUpdater<T>::ApplyFile(pool, file); },
|
||||
[&](std::string const& query) -> QueryResult { return DBUpdater<T>::Retrieve(pool, query); });
|
||||
|
||||
uint32 count;
|
||||
UpdateResult result;
|
||||
try
|
||||
{
|
||||
count = updateFetcher.Update(
|
||||
result = updateFetcher.Update(
|
||||
sConfigMgr->GetBoolDefault("Updates.Redundancy", true),
|
||||
sConfigMgr->GetBoolDefault("Updates.AllowRehash", true),
|
||||
sConfigMgr->GetBoolDefault("Updates.ArchivedRedundancy", false),
|
||||
@@ -285,10 +285,13 @@ bool DBUpdater<T>::Update(DatabaseWorkerPool<T>& pool)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!count)
|
||||
TC_LOG_INFO("sql.updates", ">> %s database is up-to-date!", DBUpdater<T>::GetTableName().c_str());
|
||||
std::string const info = Trinity::StringFormat("Containing " SZFMTD " new and " SZFMTD " archived updates.",
|
||||
result.recent, result.archived);
|
||||
|
||||
if (!result.updated)
|
||||
TC_LOG_INFO("sql.updates", ">> %s database is up-to-date! %s", DBUpdater<T>::GetTableName().c_str(), info.c_str());
|
||||
else
|
||||
TC_LOG_INFO("sql.updates", ">> Applied %d %s.", count, count == 1 ? "query" : "queries");
|
||||
TC_LOG_INFO("sql.updates", ">> Applied %d %s. %s", result.updated, result.updated == 1 ? "query" : "queries", info.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,19 @@ enum BaseLocation
|
||||
LOCATION_DOWNLOAD
|
||||
};
|
||||
|
||||
struct UpdateResult
|
||||
{
|
||||
UpdateResult()
|
||||
: updated(0), recent(0), archived(0) { }
|
||||
|
||||
UpdateResult(size_t const updated_, size_t const recent_, size_t const archived_)
|
||||
: updated(updated_), recent(recent_), archived(archived_) { }
|
||||
|
||||
size_t updated;
|
||||
size_t recent;
|
||||
size_t archived;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class DBUpdater
|
||||
{
|
||||
|
||||
@@ -154,17 +154,27 @@ UpdateFetcher::SQLUpdate UpdateFetcher::ReadSQLUpdate(boost::filesystem::path co
|
||||
return update;
|
||||
}
|
||||
|
||||
uint32 UpdateFetcher::Update(bool const redundancyChecks, bool const allowRehash, bool const archivedRedundancy, int32 const cleanDeadReferencesMaxCount) const
|
||||
UpdateResult UpdateFetcher::Update(bool const redundancyChecks, bool const allowRehash, bool const archivedRedundancy, int32 const cleanDeadReferencesMaxCount) const
|
||||
{
|
||||
LocaleFileStorage const available = GetFileList();
|
||||
AppliedFileStorage applied = ReceiveAppliedFiles();
|
||||
|
||||
size_t countRecentUpdates = 0;
|
||||
size_t countArchivedUpdates = 0;
|
||||
|
||||
// Count updates
|
||||
for (auto const& entry : applied)
|
||||
if (entry.second.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));
|
||||
|
||||
uint32 importedUpdates = 0;
|
||||
size_t importedUpdates = 0;
|
||||
|
||||
for (auto const& availableQuery : available)
|
||||
{
|
||||
@@ -314,7 +324,7 @@ uint32 UpdateFetcher::Update(bool const redundancyChecks, bool const allowRehash
|
||||
}
|
||||
}
|
||||
|
||||
return importedUpdates;
|
||||
return UpdateResult(importedUpdates, countRecentUpdates, countArchivedUpdates);
|
||||
}
|
||||
|
||||
std::string UpdateFetcher::CalculateHash(SQLUpdate const& query) const
|
||||
@@ -329,7 +339,6 @@ std::string UpdateFetcher::CalculateHash(SQLUpdate const& query) const
|
||||
uint32 UpdateFetcher::Apply(Path const& path) const
|
||||
{
|
||||
using Time = std::chrono::high_resolution_clock;
|
||||
using ms = std::chrono::milliseconds;
|
||||
|
||||
// Benchmark query speed
|
||||
auto const begin = Time::now();
|
||||
@@ -338,7 +347,7 @@ uint32 UpdateFetcher::Apply(Path const& path) const
|
||||
_applyFile(path);
|
||||
|
||||
// Return time the query took to apply
|
||||
return std::chrono::duration_cast<ms>(Time::now() - begin).count();
|
||||
return std::chrono::duration_cast<std::chrono::milliseconds>(Time::now() - begin).count();
|
||||
}
|
||||
|
||||
void UpdateFetcher::UpdateEntry(AppliedFileEntry const& entry, uint32 const speed) const
|
||||
|
||||
@@ -35,7 +35,7 @@ public:
|
||||
std::function<void(Path const& path)> const& applyFile,
|
||||
std::function<QueryResult(std::string const&)> const& retrieve);
|
||||
|
||||
uint32 Update(bool const redundancyChecks, bool const allowRehash,
|
||||
UpdateResult Update(bool const redundancyChecks, bool const allowRehash,
|
||||
bool const archivedRedundancy, int32 const cleanDeadReferencesMaxCount) const;
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user