basic search: fix people search, add some caching

0.9.1.0-post-fixes
UbitUmarov 2019-10-14 11:32:00 +01:00
parent 6d1ad6acd5
commit 23587391f8
2 changed files with 45 additions and 6 deletions

View File

@ -75,7 +75,7 @@ namespace OpenSim
/// The protocol version that we will use for outgoing transfers
/// Valid values are
/// "SIMULATION/0.3"
/// - This is the latest, and it supports teleports to variable-sized regions
/// - supports teleports to variable-sized regions
/// - Older versions can teleport to this one, but only if the destination region
/// is 256x256
/// "SIMULATION/0.2"

View File

@ -60,6 +60,9 @@ namespace OpenSim.Region.CoreModules.Framework.Search
private IGroupsModule m_GroupsService = null;
private ExpiringCache<string, List<UserAccount>> queryPeopleCache = new ExpiringCache<string, List<UserAccount>>();
private ExpiringCache<string, List<DirGroupsReplyData>> queryGroupCache = new ExpiringCache<string, List<DirGroupsReplyData>>();
#region ISharedRegionModule
public void Initialise(IConfigSource config)
@ -150,16 +153,31 @@ namespace OpenSim.Region.CoreModules.Framework.Search
void OnDirFindQuery(IClientAPI remoteClient, UUID queryID, string queryText, uint queryFlags, int queryStart)
{
queryText = queryText.Trim();
if (!string.IsNullOrEmpty(queryText))
{
queryText = queryText.Trim();
queryText = queryText.ToLowerInvariant();
}
if (((DirFindFlags)queryFlags & DirFindFlags.People) == DirFindFlags.People)
{
if (string.IsNullOrEmpty(queryText))
remoteClient.SendDirPeopleReply(queryID, new DirPeopleReplyData[0]);
List<UserAccount> accounts = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, queryText);
List<UserAccount> accounts;
if (!queryPeopleCache.TryGetValue(queryText, out accounts))
accounts = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, queryText);
queryPeopleCache.AddOrUpdate(queryText, accounts, 30.0);
if (accounts.Count == 0)
{
remoteClient.SendDirPeopleReply(queryID, new DirPeopleReplyData[0]);
return;
}
DirPeopleReplyData[] hits = new DirPeopleReplyData[accounts.Count];
int i = 0;
int count = 0;
foreach (UserAccount acc in accounts)
{
DirPeopleReplyData d = new DirPeopleReplyData();
@ -168,9 +186,25 @@ namespace OpenSim.Region.CoreModules.Framework.Search
d.lastName = acc.LastName;
d.online = false;
hits[i++] = d;
hits[count++] = d;
}
// viewers don't sent sorting, so results they show are a nice mess
if ((queryStart > 0) && (queryStart < count))
{
int len = count - queryStart;
if (len > 101) // a viewer page is 100
len = 101;
DirPeopleReplyData[] tmp = new DirPeopleReplyData[len];
Array.Copy(hits, queryStart, tmp, 0, len);
hits = tmp;
}
else if (count > 101)
{
DirPeopleReplyData[] tmp = new DirPeopleReplyData[101];
Array.Copy(hits, 0, tmp, 0, 101);
hits = tmp;
}
// TODO: This currently ignores pretty much all the query flags including Mature and sort order
remoteClient.SendDirPeopleReply(queryID, hits);
}
@ -186,7 +220,12 @@ namespace OpenSim.Region.CoreModules.Framework.Search
if (string.IsNullOrEmpty(queryText))
remoteClient.SendDirGroupsReply(queryID, new DirGroupsReplyData[0]);
List<DirGroupsReplyData> answer = m_GroupsService.FindGroups(remoteClient, queryText);
List<DirGroupsReplyData> answer;
if (!queryGroupCache.TryGetValue(queryText, out answer))
answer = m_GroupsService.FindGroups(remoteClient, queryText);
queryGroupCache.AddOrUpdate(queryText, answer, 30.0);
if(answer.Count == 0)
{
remoteClient.SendDirGroupsReply(queryID, new DirGroupsReplyData[0]);