From 7d6426f156a428d9d2b0b0478845b25bec87a1ff Mon Sep 17 00:00:00 2001
From: Sean Dague
Date: Tue, 14 Oct 2008 20:07:11 +0000
Subject: move from index based to exists strategy here
---
OpenSim/Data/SQLite/SQLiteUserData.cs | 46 +++++++++++++++++++++++++++--------
1 file changed, 36 insertions(+), 10 deletions(-)
diff --git a/OpenSim/Data/SQLite/SQLiteUserData.cs b/OpenSim/Data/SQLite/SQLiteUserData.cs
index 4beae07..420b6e5 100644
--- a/OpenSim/Data/SQLite/SQLiteUserData.cs
+++ b/OpenSim/Data/SQLite/SQLiteUserData.cs
@@ -117,13 +117,6 @@ namespace OpenSim.Data.SQLite
setupUserFriendsCommands(daf, conn);
daf.Fill(ds.Tables["userfriends"]);
-
- string Unique = "create unique index friend_unique on userfriends (ownerID,friendID)";
- using (SqliteCommand cmd = new SqliteCommand(Unique, g_conn))
- {
- cmd.ExecuteNonQuery();
- }
-
}
return;
@@ -206,9 +199,39 @@ namespace OpenSim.Data.SQLite
}
}
}
-
+
#region User Friends List Data
-
+
+ private bool ExistsFriend(UUID owner, UUID friend)
+ {
+ string FindFriends = "select * from userfriends where (ownerID=:ownerID and friendID=:friendID) or (ownerID=:friendID and friendID=:ownerID)";
+ using (SqliteCommand cmd = new SqliteCommand(FindFriends, g_conn))
+ {
+ cmd.Parameters.Add(new SqliteParameter(":ownerID", owner.ToString()));
+ cmd.Parameters.Add(new SqliteParameter(":friendID", friend.ToString()));
+ try
+ {
+ using (IDataReader reader = cmd.ExecuteReader())
+ {
+ if(reader.Read())
+ {
+ reader.Close();
+ return true;
+ }
+ else
+ {
+ reader.Close();
+ return false;
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ m_log.Error("[USER DB]: Exception getting friends list for user: " + ex.ToString());
+ return false;
+ }
+ }
+ }
///
/// Add a new friend in the friendlist
///
@@ -217,7 +240,10 @@ namespace OpenSim.Data.SQLite
/// permission flag
override public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
{
- string InsertFriends = "insert or ignore into userfriends(ownerID, friendID, friendPerms) values(:ownerID, :friendID, :perms)";
+ if (ExistsFriend(friendlistowner, friend))
+ return;
+
+ string InsertFriends = "insert into userfriends(ownerID, friendID, friendPerms) values(:ownerID, :friendID, :perms)";
using (SqliteCommand cmd = new SqliteCommand(InsertFriends, g_conn))
{
cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString()));
--
cgit v1.1