From 4f97ecc073663ede16cff77ed87a5a4fbd8fe3b9 Mon Sep 17 00:00:00 2001 From: ElectScholar Date: Sat, 3 May 2025 20:19:31 -0700 Subject: [PATCH] fix: lastUpdatedTime updating (#1784) * Create new LastSave() Method for Database and renew LastUpdatedTime in Save() * Attach UpdateLastSave() to sqlite and mysql * Fix compilation issues * Add updateTime functionality to UpdatePropertyDetails() --- dDatabase/GameDatabase/ITables/IProperty.h | 3 +++ dDatabase/GameDatabase/MySQL/MySQLDatabase.h | 1 + dDatabase/GameDatabase/MySQL/Tables/Property.cpp | 4 ++++ dDatabase/GameDatabase/SQLite/SQLiteDatabase.h | 1 + dDatabase/GameDatabase/SQLite/Tables/Property.cpp | 4 ++++ dDatabase/GameDatabase/TestSQL/TestSQLDatabase.cpp | 4 ++++ dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h | 1 + dGame/dComponents/PropertyManagementComponent.cpp | 8 +++++++- 8 files changed, 25 insertions(+), 1 deletion(-) diff --git a/dDatabase/GameDatabase/ITables/IProperty.h b/dDatabase/GameDatabase/ITables/IProperty.h index f3437154..9019c176 100644 --- a/dDatabase/GameDatabase/ITables/IProperty.h +++ b/dDatabase/GameDatabase/ITables/IProperty.h @@ -53,6 +53,9 @@ public: // Update the property details for the given property id. virtual void UpdatePropertyDetails(const IProperty::Info& info) = 0; + // Update the last updated time for the given property id. + virtual void UpdateLastSave(const IProperty::Info& info) = 0; + // Update the property performance cost for the given property id. virtual void UpdatePerformanceCost(const LWOZONEID& zoneId, const float performanceCost) = 0; diff --git a/dDatabase/GameDatabase/MySQL/MySQLDatabase.h b/dDatabase/GameDatabase/MySQL/MySQLDatabase.h index 0f50f174..e998f488 100644 --- a/dDatabase/GameDatabase/MySQL/MySQLDatabase.h +++ b/dDatabase/GameDatabase/MySQL/MySQLDatabase.h @@ -70,6 +70,7 @@ public: std::optional GetPropertyInfo(const LWOMAPID mapId, const LWOCLONEID cloneId) override; void UpdatePropertyModerationInfo(const IProperty::Info& info) override; void UpdatePropertyDetails(const IProperty::Info& info) override; + void UpdateLastSave(const IProperty::Info& info) override; void InsertNewProperty(const IProperty::Info& info, const uint32_t templateId, const LWOZONEID& zoneId) override; std::vector GetPropertyModels(const LWOOBJID& propertyId) override; void RemoveUnreferencedUgcModels() override; diff --git a/dDatabase/GameDatabase/MySQL/Tables/Property.cpp b/dDatabase/GameDatabase/MySQL/Tables/Property.cpp index bf372874..fcb35751 100644 --- a/dDatabase/GameDatabase/MySQL/Tables/Property.cpp +++ b/dDatabase/GameDatabase/MySQL/Tables/Property.cpp @@ -173,6 +173,10 @@ void MySQLDatabase::UpdatePropertyDetails(const IProperty::Info& info) { ExecuteUpdate("UPDATE properties SET name = ?, description = ? WHERE id = ? LIMIT 1;", info.name, info.description, info.id); } +void MySQLDatabase::UpdateLastSave(const IProperty::Info& info) { + ExecuteUpdate("UPDATE properties SET last_updated = ? WHERE id = ?;", info.lastUpdatedTime, info.id); +} + void MySQLDatabase::UpdatePerformanceCost(const LWOZONEID& zoneId, const float performanceCost) { ExecuteUpdate("UPDATE properties SET performance_cost = ? WHERE zone_id = ? AND clone_id = ? LIMIT 1;", performanceCost, zoneId.GetMapID(), zoneId.GetCloneID()); } diff --git a/dDatabase/GameDatabase/SQLite/SQLiteDatabase.h b/dDatabase/GameDatabase/SQLite/SQLiteDatabase.h index f456c459..15e0176f 100644 --- a/dDatabase/GameDatabase/SQLite/SQLiteDatabase.h +++ b/dDatabase/GameDatabase/SQLite/SQLiteDatabase.h @@ -68,6 +68,7 @@ public: std::optional GetPropertyInfo(const LWOMAPID mapId, const LWOCLONEID cloneId) override; void UpdatePropertyModerationInfo(const IProperty::Info& info) override; void UpdatePropertyDetails(const IProperty::Info& info) override; + void UpdateLastSave(const IProperty::Info& info) override; void InsertNewProperty(const IProperty::Info& info, const uint32_t templateId, const LWOZONEID& zoneId) override; std::vector GetPropertyModels(const LWOOBJID& propertyId) override; void RemoveUnreferencedUgcModels() override; diff --git a/dDatabase/GameDatabase/SQLite/Tables/Property.cpp b/dDatabase/GameDatabase/SQLite/Tables/Property.cpp index 7374e941..195fee2a 100644 --- a/dDatabase/GameDatabase/SQLite/Tables/Property.cpp +++ b/dDatabase/GameDatabase/SQLite/Tables/Property.cpp @@ -175,6 +175,10 @@ void SQLiteDatabase::UpdatePropertyDetails(const IProperty::Info& info) { ExecuteUpdate("UPDATE properties SET name = ?, description = ? WHERE id = ?;", info.name, info.description, info.id); } +void SQLiteDatabase::UpdateLastSave(const IProperty::Info& info) { + ExecuteUpdate("UPDATE properties SET last_updated = ? WHERE id = ?;", info.lastUpdatedTime, info.id); +} + void SQLiteDatabase::UpdatePerformanceCost(const LWOZONEID& zoneId, const float performanceCost) { ExecuteUpdate("UPDATE properties SET performance_cost = ? WHERE zone_id = ? AND clone_id = ?;", performanceCost, zoneId.GetMapID(), zoneId.GetCloneID()); } diff --git a/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.cpp b/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.cpp index 0cae0fc2..733f281b 100644 --- a/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.cpp +++ b/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.cpp @@ -148,6 +148,10 @@ void TestSQLDatabase::UpdatePropertyDetails(const IProperty::Info& info) { } +void TestSQLDatabase::UpdateLastSave(const IProperty::Info& info) { + +} + void TestSQLDatabase::InsertNewProperty(const IProperty::Info& info, const uint32_t templateId, const LWOZONEID& zoneId) { } diff --git a/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h b/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h index 1cbb3c7b..e9cf8acb 100644 --- a/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h +++ b/dDatabase/GameDatabase/TestSQL/TestSQLDatabase.h @@ -47,6 +47,7 @@ class TestSQLDatabase : public GameDatabase { std::optional GetPropertyInfo(const LWOMAPID mapId, const LWOCLONEID cloneId) override; void UpdatePropertyModerationInfo(const IProperty::Info& info) override; void UpdatePropertyDetails(const IProperty::Info& info) override; + void UpdateLastSave(const IProperty::Info& info) override; void InsertNewProperty(const IProperty::Info& info, const uint32_t templateId, const LWOZONEID& zoneId) override; std::vector GetPropertyModels(const LWOOBJID& propertyId) override; void RemoveUnreferencedUgcModels() override; diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index d7be22ac..4fae6d50 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -165,7 +165,9 @@ void PropertyManagementComponent::UpdatePropertyDetails(std::string name, std::s info.id = propertyId; info.name = propertyName; info.description = propertyDescription; - + info.lastUpdatedTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + + Database::Get()->UpdateLastSave(info); Database::Get()->UpdatePropertyDetails(info); OnQueryPropertyData(GetOwner(), UNASSIGNED_SYSTEM_ADDRESS); @@ -688,6 +690,10 @@ void PropertyManagementComponent::Save() { Database::Get()->RemoveModel(model.id); } + IProperty::Info info; + info.id = propertyId; + info.lastUpdatedTime = std::chrono::duration_cast(std::chrono::system_clock::now().time_since_epoch()).count(); + Database::Get()->UpdateLastSave(info); } void PropertyManagementComponent::AddModel(LWOOBJID modelId, LWOOBJID spawnerId) {