From d1c3f8eef58b29eb8760eeb1ac03852a2387f927 Mon Sep 17 00:00:00 2001
From: Oren Hurvitz
Date: Mon, 31 Mar 2014 11:53:12 +0300
Subject: Added assets service method AssetsExist(), which returns whether the
given list of assets exist.
This method is used to optimize sending assets with embedded assets: e.g., when a Hypergrid visitor takes an item into the inventory.
---
OpenSim/Data/MySQL/MySQLXAssetData.cs | 40 +++++++++++++++++------------------
1 file changed, 19 insertions(+), 21 deletions(-)
(limited to 'OpenSim/Data/MySQL/MySQLXAssetData.cs')
diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs
index 91389ce..1bf6a9a 100644
--- a/OpenSim/Data/MySQL/MySQLXAssetData.cs
+++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs
@@ -397,45 +397,43 @@ namespace OpenSim.Data.MySQL
}
///
- /// Check if the asset exists in the database
+ /// Check if the assets exist in the database.
///
- /// The asset UUID
- /// true if it exists, false otherwise.
- public bool ExistsAsset(UUID uuid)
+ /// The asset UUID's
+ /// For each asset: true if it exists, false otherwise
+ public bool[] AssetsExist(UUID[] uuids)
{
-// m_log.DebugFormat("[ASSETS DB]: Checking for asset {0}", uuid);
+ if (uuids.Length == 0)
+ return new bool[0];
+
+ HashSet exists = new HashSet();
- bool assetExists = false;
+ string ids = "'" + string.Join("','", uuids) + "'";
+ string sql = string.Format("SELECT ID FROM assets WHERE ID IN ({0})", ids);
lock (m_dbLock)
{
using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
{
dbcon.Open();
- using (MySqlCommand cmd = new MySqlCommand("SELECT ID FROM XAssetsMeta WHERE ID=?ID", dbcon))
+ using (MySqlCommand cmd = new MySqlCommand(sql, dbcon))
{
- cmd.Parameters.AddWithValue("?ID", uuid.ToString());
-
- try
+ using (MySqlDataReader dbReader = cmd.ExecuteReader())
{
- using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
+ while (dbReader.Read())
{
- if (dbReader.Read())
- {
-// m_log.DebugFormat("[ASSETS DB]: Found asset {0}", uuid);
- assetExists = true;
- }
+ UUID id = DBGuid.FromDB(dbReader["ID"]);
+ exists.Add(id);
}
}
- catch (Exception e)
- {
- m_log.Error(string.Format("[XASSETS DB]: MySql failure fetching asset {0}", uuid), e);
- }
}
}
}
- return assetExists;
+ bool[] results = new bool[uuids.Length];
+ for (int i = 0; i < uuids.Length; i++)
+ results[i] = exists.Contains(uuids[i]);
+ return results;
}
--
cgit v1.1