Update parent inventory folder version numbers when folders are moved/created/deleted to match version numbers cached by viewers.

This is done in the way that one would expect (e.g. moving a folder increments version number on both source and destination parent folders).
This should hopefully improve viewer reuse of its cached inventory information.
Currently MySQL only but will be implement for SQLite/MSSQL if there are no issues.
0.7.4-post-fixes
Justin Clark-Casey (justincc) 2012-11-09 00:59:18 +00:00
parent 5676f1d037
commit 909d4dca82
6 changed files with 223 additions and 58 deletions

View File

@ -116,7 +116,22 @@ namespace OpenSim.Data
/// <returns>true if the delete was successful, false if it was not</returns> /// <returns>true if the delete was successful, false if it was not</returns>
bool DeleteItems(string[] fields, string[] vals); bool DeleteItems(string[] fields, string[] vals);
/// <summary>
/// Move an item to a new folder.
/// </summary>
/// <returns>/returns>
/// <param name='id'>UUID of the item</param>
/// <param name='newParent'>UUID of the new folder.</param>
bool MoveItem(string id, string newParent); bool MoveItem(string id, string newParent);
/// <summary>
/// Move a folder to a new folder.
/// </summary>
/// <returns>/returns>
/// <param name='id'>UUID of the item</param>
/// <param name='newParent'>UUID of the new folder.</param>
bool MoveFolder(string id, string newParent);
XInventoryItem[] GetActiveGestures(UUID principalID); XInventoryItem[] GetActiveGestures(UUID principalID);
int GetAssetPermissions(UUID principalID, UUID assetID); int GetAssetPermissions(UUID principalID, UUID assetID);
} }

View File

@ -43,12 +43,12 @@ namespace OpenSim.Data.MSSQL
// private static readonly ILog m_log = LogManager.GetLogger( // private static readonly ILog m_log = LogManager.GetLogger(
// MethodBase.GetCurrentMethod().DeclaringType); // MethodBase.GetCurrentMethod().DeclaringType);
private MSSQLGenericTableHandler<XInventoryFolder> m_Folders; private MSSQLFolderHandler m_Folders;
private MSSQLItemHandler m_Items; private MSSQLItemHandler m_Items;
public MSSQLXInventoryData(string conn, string realm) public MSSQLXInventoryData(string conn, string realm)
{ {
m_Folders = new MSSQLGenericTableHandler<XInventoryFolder>( m_Folders = new MSSQLFolderHandler(
conn, "inventoryfolders", "InventoryStore"); conn, "inventoryfolders", "InventoryStore");
m_Items = new MSSQLItemHandler( m_Items = new MSSQLItemHandler(
conn, "inventoryitems", String.Empty); conn, "inventoryitems", String.Empty);
@ -85,6 +85,7 @@ namespace OpenSim.Data.MSSQL
{ {
return m_Folders.Delete(field, val); return m_Folders.Delete(field, val);
} }
public bool DeleteFolders(string[] fields, string[] vals) public bool DeleteFolders(string[] fields, string[] vals)
{ {
return m_Folders.Delete(fields, vals); return m_Folders.Delete(fields, vals);
@ -94,15 +95,22 @@ namespace OpenSim.Data.MSSQL
{ {
return m_Items.Delete(field, val); return m_Items.Delete(field, val);
} }
public bool DeleteItems(string[] fields, string[] vals) public bool DeleteItems(string[] fields, string[] vals)
{ {
return m_Items.Delete(fields, vals); return m_Items.Delete(fields, vals);
} }
public bool MoveItem(string id, string newParent) public bool MoveItem(string id, string newParent)
{ {
return m_Items.MoveItem(id, newParent); return m_Items.MoveItem(id, newParent);
} }
public bool MoveFolder(string id, string newParent)
{
return m_Folders.MoveFolder(id, newParent);
}
public XInventoryItem[] GetActiveGestures(UUID principalID) public XInventoryItem[] GetActiveGestures(UUID principalID)
{ {
return m_Items.GetActiveGestures(principalID); return m_Items.GetActiveGestures(principalID);
@ -124,6 +132,7 @@ namespace OpenSim.Data.MSSQL
public bool MoveItem(string id, string newParent) public bool MoveItem(string id, string newParent)
{ {
using (SqlConnection conn = new SqlConnection(m_ConnectionString)) using (SqlConnection conn = new SqlConnection(m_ConnectionString))
{
using (SqlCommand cmd = new SqlCommand()) using (SqlCommand cmd = new SqlCommand())
{ {
@ -135,10 +144,12 @@ namespace OpenSim.Data.MSSQL
return cmd.ExecuteNonQuery() == 0 ? false : true; return cmd.ExecuteNonQuery() == 0 ? false : true;
} }
} }
}
public XInventoryItem[] GetActiveGestures(UUID principalID) public XInventoryItem[] GetActiveGestures(UUID principalID)
{ {
using (SqlConnection conn = new SqlConnection(m_ConnectionString)) using (SqlConnection conn = new SqlConnection(m_ConnectionString))
{
using (SqlCommand cmd = new SqlCommand()) using (SqlCommand cmd = new SqlCommand())
{ {
cmd.CommandText = String.Format("select * from inventoryitems where avatarId = @uuid and assetType = @type and flags = 1", m_Realm); cmd.CommandText = String.Format("select * from inventoryitems where avatarId = @uuid and assetType = @type and flags = 1", m_Realm);
@ -150,10 +161,12 @@ namespace OpenSim.Data.MSSQL
return DoQuery(cmd); return DoQuery(cmd);
} }
} }
}
public int GetAssetPermissions(UUID principalID, UUID assetID) public int GetAssetPermissions(UUID principalID, UUID assetID)
{ {
using (SqlConnection conn = new SqlConnection(m_ConnectionString)) using (SqlConnection conn = new SqlConnection(m_ConnectionString))
{
using (SqlCommand cmd = new SqlCommand()) using (SqlCommand cmd = new SqlCommand())
{ {
cmd.CommandText = String.Format("select bit_or(inventoryCurrentPermissions) as inventoryCurrentPermissions from inventoryitems where avatarID = @PrincipalID and assetID = @AssetID group by assetID", m_Realm); cmd.CommandText = String.Format("select bit_or(inventoryCurrentPermissions) as inventoryCurrentPermissions from inventoryitems where avatarID = @PrincipalID and assetID = @AssetID group by assetID", m_Realm);
@ -176,12 +189,16 @@ namespace OpenSim.Data.MSSQL
} }
} }
}
public override bool Store(XInventoryItem item) public override bool Store(XInventoryItem item)
{ {
if (!base.Store(item)) if (!base.Store(item))
return false; return false;
string sql = "update inventoryfolders set version=version+1 where folderID = @folderID"; string sql = "update inventoryfolders set version=version+1 where folderID = @folderID";
using (SqlConnection conn = new SqlConnection(m_ConnectionString)) using (SqlConnection conn = new SqlConnection(m_ConnectionString))
{
using (SqlCommand cmd = new SqlCommand(sql, conn)) using (SqlCommand cmd = new SqlCommand(sql, conn))
{ {
conn.Open(); conn.Open();
@ -196,7 +213,34 @@ namespace OpenSim.Data.MSSQL
return false; return false;
} }
} }
return true; return true;
} }
} }
} }
public class MSSQLFolderHandler : MSSQLGenericTableHandler<XInventoryFolder>
{
public MSSQLFolderHandler(string c, string t, string m) :
base(c, t, m)
{
}
public bool MoveFolder(string id, string newParentFolderID)
{
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
{
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = String.Format("update {0} set parentFolderID = @ParentFolderID where folderID = @folderID", m_Realm);
cmd.Parameters.Add(m_database.CreateParameter("@ParentFolderID", newParentFolderID));
cmd.Parameters.Add(m_database.CreateParameter("@folderID", id));
cmd.Connection = conn;
conn.Open();
return cmd.ExecuteNonQuery() == 0 ? false : true;
}
}
}
}
}

View File

@ -42,12 +42,12 @@ namespace OpenSim.Data.MySQL
/// </summary> /// </summary>
public class MySQLXInventoryData : IXInventoryData public class MySQLXInventoryData : IXInventoryData
{ {
private MySQLGenericTableHandler<XInventoryFolder> m_Folders; private MySqlFolderHandler m_Folders;
private MySqlItemHandler m_Items; private MySqlItemHandler m_Items;
public MySQLXInventoryData(string conn, string realm) public MySQLXInventoryData(string conn, string realm)
{ {
m_Folders = new MySQLGenericTableHandler<XInventoryFolder>( m_Folders = new MySqlFolderHandler(
conn, "inventoryfolders", "InventoryStore"); conn, "inventoryfolders", "InventoryStore");
m_Items = new MySqlItemHandler( m_Items = new MySqlItemHandler(
conn, "inventoryitems", String.Empty); conn, "inventoryitems", String.Empty);
@ -106,6 +106,11 @@ namespace OpenSim.Data.MySQL
return m_Items.MoveItem(id, newParent); return m_Items.MoveItem(id, newParent);
} }
public bool MoveFolder(string id, string newParent)
{
return m_Folders.MoveFolder(id, newParent);
}
public XInventoryItem[] GetActiveGestures(UUID principalID) public XInventoryItem[] GetActiveGestures(UUID principalID)
{ {
return m_Items.GetActiveGestures(principalID); return m_Items.GetActiveGestures(principalID);
@ -275,4 +280,89 @@ namespace OpenSim.Data.MySQL
return true; return true;
} }
} }
public class MySqlFolderHandler : MySQLGenericTableHandler<XInventoryFolder>
{
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public MySqlFolderHandler(string c, string t, string m) :
base(c, t, m)
{
}
public bool MoveFolder(string id, string newParentFolderID)
{
XInventoryFolder[] folders = Get(new string[] { "folderID" }, new string[] { id });
if (folders.Length == 0)
return false;
UUID oldParentFolderUUID = folders[0].parentFolderID;
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.CommandText
= String.Format(
"update {0} set parentFolderID = ?ParentFolderID where folderID = ?folderID", m_Realm);
cmd.Parameters.AddWithValue("?ParentFolderID", newParentFolderID);
cmd.Parameters.AddWithValue("?folderID", id);
if (ExecuteNonQuery(cmd) == 0)
return false;
}
IncrementFolderVersion(oldParentFolderUUID);
IncrementFolderVersion(newParentFolderID);
return true;
}
public override bool Store(XInventoryFolder folder)
{
if (!base.Store(folder))
return false;
IncrementFolderVersion(folder.parentFolderID);
return true;
}
private bool IncrementFolderVersion(UUID folderID)
{
return IncrementFolderVersion(folderID.ToString());
}
private bool IncrementFolderVersion(string folderID)
{
// m_log.DebugFormat("[MYSQL FOLDER HANDLER]: Incrementing version on folder {0}", folderID);
// Util.PrintCallStack();
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Connection = dbcon;
cmd.CommandText = String.Format("update inventoryfolders set version=version+1 where folderID = ?folderID");
cmd.Parameters.AddWithValue("?folderID", folderID);
try
{
cmd.ExecuteNonQuery();
}
catch (Exception)
{
return false;
}
cmd.Dispose();
}
dbcon.Close();
}
return true;
}
}
} }

View File

@ -47,7 +47,7 @@ namespace OpenSim.Data.SQLite
{ {
// private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private SQLiteGenericTableHandler<XInventoryFolder> m_Folders; private SqliteFolderHandler m_Folders;
private SqliteItemHandler m_Items; private SqliteItemHandler m_Items;
public SQLiteXInventoryData(string conn, string realm) public SQLiteXInventoryData(string conn, string realm)
@ -55,7 +55,7 @@ namespace OpenSim.Data.SQLite
if (Util.IsWindows()) if (Util.IsWindows())
Util.LoadArchSpecificWindowsDll("sqlite3.dll"); Util.LoadArchSpecificWindowsDll("sqlite3.dll");
m_Folders = new SQLiteGenericTableHandler<XInventoryFolder>( m_Folders = new SqliteFolderHandler(
conn, "inventoryfolders", "XInventoryStore"); conn, "inventoryfolders", "XInventoryStore");
m_Items = new SqliteItemHandler( m_Items = new SqliteItemHandler(
conn, "inventoryitems", String.Empty); conn, "inventoryitems", String.Empty);
@ -114,6 +114,11 @@ namespace OpenSim.Data.SQLite
return m_Items.MoveItem(id, newParent); return m_Items.MoveItem(id, newParent);
} }
public bool MoveFolder(string id, string newParent)
{
return m_Folders.MoveFolder(id, newParent);
}
public XInventoryItem[] GetActiveGestures(UUID principalID) public XInventoryItem[] GetActiveGestures(UUID principalID)
{ {
return m_Items.GetActiveGestures(principalID); return m_Items.GetActiveGestures(principalID);
@ -177,4 +182,23 @@ namespace OpenSim.Data.SQLite
return perms; return perms;
} }
} }
public class SqliteFolderHandler : SQLiteGenericTableHandler<XInventoryFolder>
{
public SqliteFolderHandler(string c, string t, string m) :
base(c, t, m)
{
}
public bool MoveFolder(string id, string newParentFolderID)
{
SqliteCommand cmd = new SqliteCommand();
cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where folderID = :FolderID", m_Realm);
cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParentFolderID));
cmd.Parameters.Add(new SqliteParameter(":FolderID", id));
return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true;
}
}
} }

View File

@ -400,16 +400,7 @@ namespace OpenSim.Services.InventoryService
public virtual bool MoveFolder(InventoryFolderBase folder) public virtual bool MoveFolder(InventoryFolderBase folder)
{ {
XInventoryFolder[] x = m_Database.GetFolders( return m_Database.MoveFolder(folder.ID.ToString(), folder.ParentID.ToString());
new string[] { "folderID" },
new string[] { folder.ID.ToString() });
if (x.Length == 0)
return false;
x[0].parentFolderID = folder.ParentID;
return m_Database.StoreFolder(x[0]);
} }
// We don't check the principal's ID here // We don't check the principal's ID here

View File

@ -125,6 +125,7 @@ namespace OpenSim.Tests.Common.Mock
} }
public bool MoveItem(string id, string newParent) { throw new NotImplementedException(); } public bool MoveItem(string id, string newParent) { throw new NotImplementedException(); }
public bool MoveFolder(string id, string newParent) { throw new NotImplementedException(); }
public XInventoryItem[] GetActiveGestures(UUID principalID) { throw new NotImplementedException(); } public XInventoryItem[] GetActiveGestures(UUID principalID) { throw new NotImplementedException(); }
public int GetAssetPermissions(UUID principalID, UUID assetID) { throw new NotImplementedException(); } public int GetAssetPermissions(UUID principalID, UUID assetID) { throw new NotImplementedException(); }
} }