From 629b0d9f28d2027b4d0aecc10bc78f7aefb5d7f3 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Thu, 6 Nov 2008 21:21:46 +0000 Subject: add create_time and access_time to asset db for mysql, as well as the code to update these at the appropriate time. This isn't surfaced in AssetBase yet. Change the replace into to an insert into for asset create. Assets are not supposed to be updatable, and the replace into is more expensive. From: Sean Dague --- OpenSim/Data/MySQL/MySQLAssetData.cs | 48 +++++++++++++++++++++++-- OpenSim/Data/MySQL/Resources/005_AssetStore.sql | 6 ++++ 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 OpenSim/Data/MySQL/Resources/005_AssetStore.sql diff --git a/OpenSim/Data/MySQL/MySQLAssetData.cs b/OpenSim/Data/MySQL/MySQLAssetData.cs index e270b9c..4b51bda 100644 --- a/OpenSim/Data/MySQL/MySQLAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLAssetData.cs @@ -45,6 +45,7 @@ namespace OpenSim.Data.MySQL private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); private MySQLManager _dbConnection; + private long TicksToEpoch; #region IPlugin Members @@ -61,6 +62,8 @@ namespace OpenSim.Data.MySQL /// connect string override public void Initialise(string connect) { + TicksToEpoch = new System.DateTime(1970,1,1).Ticks; + // TODO: This will let you pass in the connect string in // the config, though someone will need to write that. if (connect == String.Empty) @@ -146,6 +149,8 @@ namespace OpenSim.Data.MySQL dbReader.Close(); cmd.Dispose(); } + if (asset != null) + UpdateAccessTime(asset); } catch (Exception e) { @@ -178,8 +183,8 @@ namespace OpenSim.Data.MySQL MySqlCommand cmd = new MySqlCommand( - "REPLACE INTO assets(id, name, description, assetType, local, temporary, data)" + - "VALUES(?id, ?name, ?description, ?assetType, ?local, ?temporary, ?data)", + "insert INTO assets(id, name, description, assetType, local, temporary, create_time, access_time, data)" + + "VALUES(?id, ?name, ?description, ?assetType, ?local, ?temporary, ?create_time, ?access_time, ?data)", _dbConnection.Connection); // need to ensure we dispose @@ -187,12 +192,16 @@ namespace OpenSim.Data.MySQL { using (cmd) { + // create unix epoch time + int now = (int)((System.DateTime.Now.Ticks - TicksToEpoch) / 10000000); cmd.Parameters.AddWithValue("?id", asset.FullID.ToString()); cmd.Parameters.AddWithValue("?name", asset.Name); cmd.Parameters.AddWithValue("?description", asset.Description); cmd.Parameters.AddWithValue("?assetType", asset.Type); cmd.Parameters.AddWithValue("?local", asset.Local); cmd.Parameters.AddWithValue("?temporary", asset.Temporary); + cmd.Parameters.AddWithValue("?create_time", now); + cmd.Parameters.AddWithValue("?access_time", now); cmd.Parameters.AddWithValue("?data", asset.Data); cmd.ExecuteNonQuery(); cmd.Dispose(); @@ -209,6 +218,41 @@ namespace OpenSim.Data.MySQL } } + private void UpdateAccessTime(AssetBase asset) + { + lock (_dbConnection) + { + _dbConnection.CheckConnection(); + + MySqlCommand cmd = + new MySqlCommand("update assets set access_time=?access_time where id=?id", + _dbConnection.Connection); + + // need to ensure we dispose + try + { + using (cmd) + { + // create unix epoch time + int now = (int)((System.DateTime.Now.Ticks - TicksToEpoch) / 10000000); + cmd.Parameters.AddWithValue("?id", asset.FullID.ToString()); + cmd.Parameters.AddWithValue("?access_time", now); + cmd.ExecuteNonQuery(); + cmd.Dispose(); + } + } + catch (Exception e) + { + m_log.ErrorFormat( + "[ASSETS DB]: " + + "MySql failure updating access_time for asset {0} with name {1}" + Environment.NewLine + e.ToString() + + Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name); + _dbConnection.Reconnect(); + } + } + + } + /// /// Update a asset in database, see /// diff --git a/OpenSim/Data/MySQL/Resources/005_AssetStore.sql b/OpenSim/Data/MySQL/Resources/005_AssetStore.sql new file mode 100644 index 0000000..bfeb652 --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/005_AssetStore.sql @@ -0,0 +1,6 @@ +BEGIN; + +ALTER TABLE assets add create_time integer default 0; +ALTER TABLE assets add access_time integer default 0; + +COMMIT; -- cgit v1.1