aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorSean Dague2008-11-06 21:21:46 +0000
committerSean Dague2008-11-06 21:21:46 +0000
commit629b0d9f28d2027b4d0aecc10bc78f7aefb5d7f3 (patch)
tree7a024be534000336d5216095ac41c5d1fbc33c7f
parent* minor: remove some mono compiler warnings (diff)
downloadopensim-SC_OLD-629b0d9f28d2027b4d0aecc10bc78f7aefb5d7f3.zip
opensim-SC_OLD-629b0d9f28d2027b4d0aecc10bc78f7aefb5d7f3.tar.gz
opensim-SC_OLD-629b0d9f28d2027b4d0aecc10bc78f7aefb5d7f3.tar.bz2
opensim-SC_OLD-629b0d9f28d2027b4d0aecc10bc78f7aefb5d7f3.tar.xz
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 <sdague@gmail.com>
-rw-r--r--OpenSim/Data/MySQL/MySQLAssetData.cs48
-rw-r--r--OpenSim/Data/MySQL/Resources/005_AssetStore.sql6
2 files changed, 52 insertions, 2 deletions
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
45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 45 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
46 46
47 private MySQLManager _dbConnection; 47 private MySQLManager _dbConnection;
48 private long TicksToEpoch;
48 49
49 #region IPlugin Members 50 #region IPlugin Members
50 51
@@ -61,6 +62,8 @@ namespace OpenSim.Data.MySQL
61 /// <param name="connect">connect string</param> 62 /// <param name="connect">connect string</param>
62 override public void Initialise(string connect) 63 override public void Initialise(string connect)
63 { 64 {
65 TicksToEpoch = new System.DateTime(1970,1,1).Ticks;
66
64 // TODO: This will let you pass in the connect string in 67 // TODO: This will let you pass in the connect string in
65 // the config, though someone will need to write that. 68 // the config, though someone will need to write that.
66 if (connect == String.Empty) 69 if (connect == String.Empty)
@@ -146,6 +149,8 @@ namespace OpenSim.Data.MySQL
146 dbReader.Close(); 149 dbReader.Close();
147 cmd.Dispose(); 150 cmd.Dispose();
148 } 151 }
152 if (asset != null)
153 UpdateAccessTime(asset);
149 } 154 }
150 catch (Exception e) 155 catch (Exception e)
151 { 156 {
@@ -178,8 +183,8 @@ namespace OpenSim.Data.MySQL
178 183
179 MySqlCommand cmd = 184 MySqlCommand cmd =
180 new MySqlCommand( 185 new MySqlCommand(
181 "REPLACE INTO assets(id, name, description, assetType, local, temporary, data)" + 186 "insert INTO assets(id, name, description, assetType, local, temporary, create_time, access_time, data)" +
182 "VALUES(?id, ?name, ?description, ?assetType, ?local, ?temporary, ?data)", 187 "VALUES(?id, ?name, ?description, ?assetType, ?local, ?temporary, ?create_time, ?access_time, ?data)",
183 _dbConnection.Connection); 188 _dbConnection.Connection);
184 189
185 // need to ensure we dispose 190 // need to ensure we dispose
@@ -187,12 +192,16 @@ namespace OpenSim.Data.MySQL
187 { 192 {
188 using (cmd) 193 using (cmd)
189 { 194 {
195 // create unix epoch time
196 int now = (int)((System.DateTime.Now.Ticks - TicksToEpoch) / 10000000);
190 cmd.Parameters.AddWithValue("?id", asset.FullID.ToString()); 197 cmd.Parameters.AddWithValue("?id", asset.FullID.ToString());
191 cmd.Parameters.AddWithValue("?name", asset.Name); 198 cmd.Parameters.AddWithValue("?name", asset.Name);
192 cmd.Parameters.AddWithValue("?description", asset.Description); 199 cmd.Parameters.AddWithValue("?description", asset.Description);
193 cmd.Parameters.AddWithValue("?assetType", asset.Type); 200 cmd.Parameters.AddWithValue("?assetType", asset.Type);
194 cmd.Parameters.AddWithValue("?local", asset.Local); 201 cmd.Parameters.AddWithValue("?local", asset.Local);
195 cmd.Parameters.AddWithValue("?temporary", asset.Temporary); 202 cmd.Parameters.AddWithValue("?temporary", asset.Temporary);
203 cmd.Parameters.AddWithValue("?create_time", now);
204 cmd.Parameters.AddWithValue("?access_time", now);
196 cmd.Parameters.AddWithValue("?data", asset.Data); 205 cmd.Parameters.AddWithValue("?data", asset.Data);
197 cmd.ExecuteNonQuery(); 206 cmd.ExecuteNonQuery();
198 cmd.Dispose(); 207 cmd.Dispose();
@@ -209,6 +218,41 @@ namespace OpenSim.Data.MySQL
209 } 218 }
210 } 219 }
211 220
221 private void UpdateAccessTime(AssetBase asset)
222 {
223 lock (_dbConnection)
224 {
225 _dbConnection.CheckConnection();
226
227 MySqlCommand cmd =
228 new MySqlCommand("update assets set access_time=?access_time where id=?id",
229 _dbConnection.Connection);
230
231 // need to ensure we dispose
232 try
233 {
234 using (cmd)
235 {
236 // create unix epoch time
237 int now = (int)((System.DateTime.Now.Ticks - TicksToEpoch) / 10000000);
238 cmd.Parameters.AddWithValue("?id", asset.FullID.ToString());
239 cmd.Parameters.AddWithValue("?access_time", now);
240 cmd.ExecuteNonQuery();
241 cmd.Dispose();
242 }
243 }
244 catch (Exception e)
245 {
246 m_log.ErrorFormat(
247 "[ASSETS DB]: " +
248 "MySql failure updating access_time for asset {0} with name {1}" + Environment.NewLine + e.ToString()
249 + Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name);
250 _dbConnection.Reconnect();
251 }
252 }
253
254 }
255
212 /// <summary> 256 /// <summary>
213 /// Update a asset in database, see <see cref="CreateAsset"/> 257 /// Update a asset in database, see <see cref="CreateAsset"/>
214 /// </summary> 258 /// </summary>
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 @@
1BEGIN;
2
3ALTER TABLE assets add create_time integer default 0;
4ALTER TABLE assets add access_time integer default 0;
5
6COMMIT;