0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 08:50:43 -05:00

Fix ballooning recursive function (!120)

The `BotEquipmentModPoolService.generatePool()` method is recursive, but it does not check if the pool it creates already contains data for sub items when it finds them and calls itself on them. This creates substantial bloat in the function that is undetectable to end users, but causes some additional delay when it is called.

I noticed this when using a server mod that allows for less restrictions on mod combinations (as it would hit the system recursion limit and error out) but the bloat still affects vanilla - it takes ~1 minute for all the recursive calls to end, whereas this fix reduces that to <10 seconds.

To fix this, I've moved a block of code into the conditional block that checks if the item we're adding (and its' sub items) are already in the pool before it calls itself.

This is my first pull request, so let me know if I've fudged up somewhere and I'll do my best to fix it.

I submitted a previous request about this, but I removed my name from the commits so I had to delete the branch.

Co-authored-by: gasmo <burr.cameron@gmail.com>
Reviewed-on: SPT-AKI/Server#120
Co-authored-by: gasmo <gasmo@noreply.dev.sp-tarkov.com>
Co-committed-by: gasmo <gasmo@noreply.dev.sp-tarkov.com>
This commit is contained in:
gasmo 2023-08-18 14:17:54 +00:00 committed by chomp
parent 1b387f706d
commit 8d911ccc19

View File

@ -83,16 +83,16 @@ export class BotEquipmentModPoolService
if (!pool[item._id][slot._name].some(x => x === itemToAdd))
{
pool[item._id][slot._name].push(itemToAdd);
}
// Check item added into array for slots, need to iterate over those
const subItemDetails = this.databaseServer.getTables().templates.items[itemToAdd];
const hasSubItemsToAdd = subItemDetails?._props?.Slots?.length > 0;
if (hasSubItemsToAdd)
{
// Recursive call
this.generatePool([subItemDetails], poolType);
}
// Check item added into array for slots, need to iterate over those
const subItemDetails = this.databaseServer.getTables().templates.items[itemToAdd];
const hasSubItemsToAdd = subItemDetails?._props?.Slots?.length > 0;
if (hasSubItemsToAdd && !pool[subItemDetails._id])
{
// Recursive call
this.generatePool([subItemDetails], poolType);
}
}
}
}
}