Skip to content

Commit c00a11a

Browse files
committed
Add inventory prefetching support
Introduces configuration options and logic for prefetching inventory folders on startup, including depth control. Updates Dockerfile and DataStoreConfig to support new settings, and modifies DataStoreService to handle inventory preloading asynchronously.
1 parent c40c551 commit c00a11a

File tree

4 files changed

+75
-5
lines changed

4 files changed

+75
-5
lines changed

Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ ENV basic_Username='' \
4747
datastore_ImChatHistoryLimit=50 \
4848
datastore_PrefetchGroupMembers='true' \
4949
datastore_PrefetchGroupRoles='false' \
50+
datastore_PrefetchInventory='false' \
51+
datastore_PrefetchInventoryDepth='2' \
5052
datastore_PrefetchEstateBanlist='true' \
5153
datastore_AutoCleanKeyValueStore='true' \
5254
datastore_CleanKeyValueStoreAfterMins=10 \

SecondBotEvents/Config/DataStoreConfig.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,21 @@ protected override void MakeSettings()
1818
settings.Add("PrefetchGroupRoles");
1919
settings.Add("PrefetchEstateBanlist");
2020
settings.Add("PrefetchAvatarDisplaynames");
21+
settings.Add("PrefetchInventory");
22+
settings.Add("PrefetchInventoryDepth");
2123
settings.Add("AutoCleanKeyValueStore");
2224
settings.Add("CleanKeyValueStoreAfterMins");
2325
settings.Add("CommandHistoryLimit");
2426
settings.Add("HideStatusOutput");
2527
}
28+
public int GetPrefetchInventoryDepth()
29+
{
30+
return ReadSettingAsInt("PrefetchInventoryDepth", 2);
31+
}
32+
public bool GetPrefetchInventory()
33+
{
34+
return ReadSettingAsBool("PrefetchInventory", false);
35+
}
2636

2737
public bool GetPrefetchAvatarDisplaynames()
2838
{

SecondBotEvents/Services/CommandsService.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,14 +436,15 @@ protected void BotLoggedIn(object o, SimConnectedEventArgs e)
436436

437437
public void CommandNotice(string command,string source, string args,bool accepted, string results)
438438
{
439-
if(myConfig.GetCommandHistoryLogResults() == false)
440-
{
441-
results = "";
442-
}
439+
443440
BotCommandNotice e = new(command, args, source, accepted, results);
444441
EventHandler<BotCommandNotice> handler = BotclientCommandEventNotices;
445442
handler?.Invoke(this, e);
446-
if(master.BotClient.basicCfg.GetLogCommands() == true)
443+
if (myConfig.GetCommandHistoryLogResults() == false)
444+
{
445+
return;
446+
}
447+
if (master.BotClient.basicCfg.GetLogCommands() == true)
447448
{
448449
LogFormater.Info("Command log:" + JsonConvert.SerializeObject(e));
449450
}

SecondBotEvents/Services/DataStoreService.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using OpenMetaverse.ImportExport.Collada14;
1111
using System.Threading.Tasks;
1212
using OpenMetaverse.Messages.Linden;
13+
using Org.BouncyCastle.Asn1.BC;
14+
using Swan;
1315

1416
namespace SecondBotEvents.Services
1517
{
@@ -208,6 +210,17 @@ public override string Status()
208210
}
209211
}
210212
}
213+
if (myConfig.GetPrefetchInventory() == true)
214+
{
215+
if(preloadDone == false)
216+
{
217+
if(preloadingFolders.Count() == 0)
218+
{
219+
preloadDone = true;
220+
}
221+
return "Loading "+preloadingFolders.Count()+" inventory folders";
222+
}
223+
}
211224
int sum = commandHistories.Count + KeyValueStoreLastUsed.Count + KeyValueStore.Count +
212225
chatWindowsOwner.Count + chatWindowsIsGroup.Count + chatWindowsUnread.Count +
213226
chatWindows.Count + localChatHistory.Count + groupRoles.Count +
@@ -999,7 +1012,51 @@ protected void AttachEventsAfterDelay()
9991012
GetClient().Avatars.AvatarPropertiesReply += AvatarDetailsReply;
10001013
GetClient().Groups.RequestCurrentGroups();
10011014
_ = GetClient().Self.RetrieveInstantMessages();
1015+
if(myConfig.GetPrefetchInventory() == true)
1016+
{
1017+
preloadDone = false;
1018+
Task.Run(() =>
1019+
{
1020+
preloadFolder("root", GetClient().Inventory.Store.RootFolder.UUID, myConfig.GetPrefetchInventoryDepth(), 0);
1021+
});
1022+
}
1023+
}
1024+
1025+
protected List<string> preloadingFolders = [];
1026+
protected bool preloadDone = true;
1027+
1028+
protected async void preloadFolder(string foldername,UUID folder, int maxDepth, int currentDepth)
1029+
{
1030+
await Task.Run(async () =>
1031+
{
1032+
lock (preloadingFolders)
1033+
{
1034+
preloadingFolders.Add(folder.Guid.ToString());
1035+
}
1036+
await Task.Delay(1000 * currentDepth);
1037+
List<InventoryBase> foldercontents = GetClient().Inventory.FolderContents(
1038+
GetClient().Inventory.Store.RootFolder.UUID,
1039+
GetClient().Self.AgentID, true, true,
1040+
InventorySortOrder.ByName, TimeSpan.FromSeconds(30), false);
1041+
foreach (InventoryBase item in foldercontents)
1042+
{
1043+
if (item is InventoryFolder == false)
1044+
{
1045+
continue;
1046+
}
1047+
if ((currentDepth + 1) > maxDepth)
1048+
{
1049+
continue;
1050+
}
1051+
preloadFolder(item.Name, item.UUID, maxDepth, currentDepth + 1);
1052+
}
1053+
lock (preloadingFolders)
1054+
{
1055+
preloadingFolders.Remove(folder.Guid.ToString());
1056+
}
1057+
});
10021058
}
1059+
10031060
readonly string[] hard_blocked_agents = ["secondlife", "second life"];
10041061
protected void ChatFromSim(object o, ChatEventArgs e)
10051062
{

0 commit comments

Comments
 (0)