From 9ff4d38cc9bd624946a8cee0279369dd5a3e38f7 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 6 Nov 2012 23:44:52 +0000 Subject: [PATCH] Update folder version numbers when moving items and making the Delete(string[], string[]) call (not just string, string). This is to stop viewer inventory cache version numbers becoming out of sync with grid stored numbers when viewer performs these actions. If there are no problems with these changes, they will be propogated to SQLite (and MSSQL if that's simple enough). May also need to do the same on folder store/create/delete and maybe propogate version increments up the folder hierarchy, but that requires investigation. --- .../Data/MySQL/MySQLGenericTableHandler.cs | 6 +++ OpenSim/Data/MySQL/MySQLXInventoryData.cs | 53 +++++++++++++++++-- 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs index da8e958b07..995c6a5317 100644 --- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs +++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs @@ -219,6 +219,8 @@ namespace OpenSim.Data.MySQL public virtual bool Store(T row) { +// m_log.DebugFormat("[MYSQL GENERIC TABLE HANDLER]: Store(T row) invoked"); + using (MySqlCommand cmd = new MySqlCommand()) { string query = ""; @@ -273,6 +275,10 @@ namespace OpenSim.Data.MySQL public virtual bool Delete(string[] fields, string[] keys) { +// m_log.DebugFormat( +// "[MYSQL GENERIC TABLE HANDLER]: Delete(string[] fields, string[] keys) invoked with {0}:{1}", +// string.Join(",", fields), string.Join(",", keys)); + if (fields.Length != keys.Length) return false; diff --git a/OpenSim/Data/MySQL/MySQLXInventoryData.cs b/OpenSim/Data/MySQL/MySQLXInventoryData.cs index 189ee5e64d..cccc500861 100644 --- a/OpenSim/Data/MySQL/MySQLXInventoryData.cs +++ b/OpenSim/Data/MySQL/MySQLXInventoryData.cs @@ -26,9 +26,10 @@ */ using System; -using System.Data; -using System.Reflection; using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Reflection; using log4net; using MySql.Data.MySqlClient; using OpenMetaverse; @@ -118,6 +119,8 @@ namespace OpenSim.Data.MySQL public class MySqlItemHandler : MySQLGenericTableHandler { +// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + public MySqlItemHandler(string c, string t, string m) : base(c, t, m) { @@ -132,21 +135,53 @@ namespace OpenSim.Data.MySQL if (!base.Delete(field, val)) return false; - IncrementFolderVersion(retrievedItems[0].parentFolderID); + // Don't increment folder version here since Delete(string, string) calls Delete(string[], string[]) +// IncrementFolderVersion(retrievedItems[0].parentFolderID); + + return true; + } + + public override bool Delete(string[] fields, string[] vals) + { + XInventoryItem[] retrievedItems = Get(fields, vals); + if (retrievedItems.Length == 0) + return false; + + if (!base.Delete(fields, vals)) + return false; + + HashSet deletedItemFolderUUIDs = new HashSet(); + + Array.ForEach(retrievedItems, i => deletedItemFolderUUIDs.Add(i.parentFolderID)); + + foreach (UUID deletedItemFolderUUID in deletedItemFolderUUIDs) + IncrementFolderVersion(deletedItemFolderUUID); return true; } public bool MoveItem(string id, string newParent) { + XInventoryItem[] retrievedItems = Get(new string[] { "inventoryID" }, new string[] { id }); + if (retrievedItems.Length == 0) + return false; + + UUID oldParent = retrievedItems[0].parentFolderID; + using (MySqlCommand cmd = new MySqlCommand()) { cmd.CommandText = String.Format("update {0} set parentFolderID = ?ParentFolderID where inventoryID = ?InventoryID", m_Realm); cmd.Parameters.AddWithValue("?ParentFolderID", newParent); cmd.Parameters.AddWithValue("?InventoryID", id); - return ExecuteNonQuery(cmd) == 0 ? false : true; + if (ExecuteNonQuery(cmd) == 0) + return false; } + + IncrementFolderVersion(oldParent); + IncrementFolderVersion(newParent); + + return true; } public XInventoryItem[] GetActiveGestures(UUID principalID) @@ -204,6 +239,14 @@ namespace OpenSim.Data.MySQL private bool IncrementFolderVersion(UUID folderID) { + return IncrementFolderVersion(folderID.ToString()); + } + + private bool IncrementFolderVersion(string folderID) + { +// m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID); +// Util.PrintCallStack(); + using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) { dbcon.Open(); @@ -213,7 +256,7 @@ namespace OpenSim.Data.MySQL cmd.Connection = dbcon; cmd.CommandText = String.Format("update inventoryfolders set version=version+1 where folderID = ?folderID"); - cmd.Parameters.AddWithValue("?folderID", folderID.ToString()); + cmd.Parameters.AddWithValue("?folderID", folderID); try {