diff options
author | UbitUmarov | 2019-10-14 11:32:00 +0100 |
---|---|---|
committer | UbitUmarov | 2019-10-14 11:32:00 +0100 |
commit | 23587391f855b5aa6f7a2e511aba68e304ee5692 (patch) | |
tree | af5dee3848e4a0b329dc515d2a9c1b46bc0315de /OpenSim/Region/CoreModules/Framework/Search | |
parent | viewers group search page size is 100 ( and not way to detect other value, so... (diff) | |
download | opensim-SC-23587391f855b5aa6f7a2e511aba68e304ee5692.zip opensim-SC-23587391f855b5aa6f7a2e511aba68e304ee5692.tar.gz opensim-SC-23587391f855b5aa6f7a2e511aba68e304ee5692.tar.bz2 opensim-SC-23587391f855b5aa6f7a2e511aba68e304ee5692.tar.xz |
basic search: fix people search, add some caching
Diffstat (limited to 'OpenSim/Region/CoreModules/Framework/Search')
-rw-r--r-- | OpenSim/Region/CoreModules/Framework/Search/BasicSearchModule.cs | 49 |
1 files changed, 44 insertions, 5 deletions
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 | |||
60 | 60 | ||
61 | private IGroupsModule m_GroupsService = null; | 61 | private IGroupsModule m_GroupsService = null; |
62 | 62 | ||
63 | private ExpiringCache<string, List<UserAccount>> queryPeopleCache = new ExpiringCache<string, List<UserAccount>>(); | ||
64 | private ExpiringCache<string, List<DirGroupsReplyData>> queryGroupCache = new ExpiringCache<string, List<DirGroupsReplyData>>(); | ||
65 | |||
63 | #region ISharedRegionModule | 66 | #region ISharedRegionModule |
64 | 67 | ||
65 | public void Initialise(IConfigSource config) | 68 | public void Initialise(IConfigSource config) |
@@ -150,16 +153,31 @@ namespace OpenSim.Region.CoreModules.Framework.Search | |||
150 | 153 | ||
151 | void OnDirFindQuery(IClientAPI remoteClient, UUID queryID, string queryText, uint queryFlags, int queryStart) | 154 | void OnDirFindQuery(IClientAPI remoteClient, UUID queryID, string queryText, uint queryFlags, int queryStart) |
152 | { | 155 | { |
153 | queryText = queryText.Trim(); | 156 | if (!string.IsNullOrEmpty(queryText)) |
157 | { | ||
158 | queryText = queryText.Trim(); | ||
159 | queryText = queryText.ToLowerInvariant(); | ||
160 | } | ||
154 | 161 | ||
155 | if (((DirFindFlags)queryFlags & DirFindFlags.People) == DirFindFlags.People) | 162 | if (((DirFindFlags)queryFlags & DirFindFlags.People) == DirFindFlags.People) |
156 | { | 163 | { |
157 | if (string.IsNullOrEmpty(queryText)) | 164 | if (string.IsNullOrEmpty(queryText)) |
158 | remoteClient.SendDirPeopleReply(queryID, new DirPeopleReplyData[0]); | 165 | remoteClient.SendDirPeopleReply(queryID, new DirPeopleReplyData[0]); |
159 | 166 | ||
160 | List<UserAccount> accounts = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, queryText); | 167 | List<UserAccount> accounts; |
168 | if (!queryPeopleCache.TryGetValue(queryText, out accounts)) | ||
169 | accounts = m_Scenes[0].UserAccountService.GetUserAccounts(m_Scenes[0].RegionInfo.ScopeID, queryText); | ||
170 | |||
171 | queryPeopleCache.AddOrUpdate(queryText, accounts, 30.0); | ||
172 | |||
173 | if (accounts.Count == 0) | ||
174 | { | ||
175 | remoteClient.SendDirPeopleReply(queryID, new DirPeopleReplyData[0]); | ||
176 | return; | ||
177 | } | ||
178 | |||
161 | DirPeopleReplyData[] hits = new DirPeopleReplyData[accounts.Count]; | 179 | DirPeopleReplyData[] hits = new DirPeopleReplyData[accounts.Count]; |
162 | int i = 0; | 180 | int count = 0; |
163 | foreach (UserAccount acc in accounts) | 181 | foreach (UserAccount acc in accounts) |
164 | { | 182 | { |
165 | DirPeopleReplyData d = new DirPeopleReplyData(); | 183 | DirPeopleReplyData d = new DirPeopleReplyData(); |
@@ -168,9 +186,25 @@ namespace OpenSim.Region.CoreModules.Framework.Search | |||
168 | d.lastName = acc.LastName; | 186 | d.lastName = acc.LastName; |
169 | d.online = false; | 187 | d.online = false; |
170 | 188 | ||
171 | hits[i++] = d; | 189 | hits[count++] = d; |
172 | } | 190 | } |
173 | 191 | ||
192 | // viewers don't sent sorting, so results they show are a nice mess | ||
193 | if ((queryStart > 0) && (queryStart < count)) | ||
194 | { | ||
195 | int len = count - queryStart; | ||
196 | if (len > 101) // a viewer page is 100 | ||
197 | len = 101; | ||
198 | DirPeopleReplyData[] tmp = new DirPeopleReplyData[len]; | ||
199 | Array.Copy(hits, queryStart, tmp, 0, len); | ||
200 | hits = tmp; | ||
201 | } | ||
202 | else if (count > 101) | ||
203 | { | ||
204 | DirPeopleReplyData[] tmp = new DirPeopleReplyData[101]; | ||
205 | Array.Copy(hits, 0, tmp, 0, 101); | ||
206 | hits = tmp; | ||
207 | } | ||
174 | // TODO: This currently ignores pretty much all the query flags including Mature and sort order | 208 | // TODO: This currently ignores pretty much all the query flags including Mature and sort order |
175 | remoteClient.SendDirPeopleReply(queryID, hits); | 209 | remoteClient.SendDirPeopleReply(queryID, hits); |
176 | } | 210 | } |
@@ -186,7 +220,12 @@ namespace OpenSim.Region.CoreModules.Framework.Search | |||
186 | if (string.IsNullOrEmpty(queryText)) | 220 | if (string.IsNullOrEmpty(queryText)) |
187 | remoteClient.SendDirGroupsReply(queryID, new DirGroupsReplyData[0]); | 221 | remoteClient.SendDirGroupsReply(queryID, new DirGroupsReplyData[0]); |
188 | 222 | ||
189 | List<DirGroupsReplyData> answer = m_GroupsService.FindGroups(remoteClient, queryText); | 223 | List<DirGroupsReplyData> answer; |
224 | if (!queryGroupCache.TryGetValue(queryText, out answer)) | ||
225 | answer = m_GroupsService.FindGroups(remoteClient, queryText); | ||
226 | |||
227 | queryGroupCache.AddOrUpdate(queryText, answer, 30.0); | ||
228 | |||
190 | if(answer.Count == 0) | 229 | if(answer.Count == 0) |
191 | { | 230 | { |
192 | remoteClient.SendDirGroupsReply(queryID, new DirGroupsReplyData[0]); | 231 | remoteClient.SendDirGroupsReply(queryID, new DirGroupsReplyData[0]); |