From 23587391f855b5aa6f7a2e511aba68e304ee5692 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 14 Oct 2019 11:32:00 +0100 Subject: basic search: fix people search, add some caching --- .../Framework/Search/BasicSearchModule.cs | 49 +++++++++++++++++++--- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'OpenSim/Region/CoreModules/Framework/Search') diff --git a/OpenSim/Region/CoreModules/Framework/Search/BasicSearchModule.cs b/OpenSim/Region/CoreModules/Framework/Search/BasicSearchModule.cs index 8a44ba4..583e45d 100644 --- a/OpenSim/Region/CoreModules/Framework/Search/BasicSearchModule.cs +++ b/OpenSim/Region/CoreModules/Framework/Search/BasicSearchModule.cs @@ -60,6 +60,9 @@ namespace OpenSim.Region.CoreModules.Framework.Search private IGroupsModule m_GroupsService = null; + private ExpiringCache> queryPeopleCache = new ExpiringCache>(); + private ExpiringCache> queryGroupCache = new ExpiringCache>(); + #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 accounts = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, queryText); + List 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 answer = m_GroupsService.FindGroups(remoteClient, queryText); + List 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]); -- cgit v1.1