Skip to content

Commit

Permalink
feat: cache storage actuator search results for better performance
Browse files Browse the repository at this point in the history
Closes #1021
  • Loading branch information
klikli-dev committed Dec 30, 2023
1 parent b3c357b commit 9518818
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ public abstract class StorageControllerGuiBase<T extends StorageControllerContai
protected boolean forceFocus;
protected long lastClick;

private List<ItemStack> cachedStacksToDisplay;
private String cachedSearchString;

public StorageControllerGuiBase(T container, Inventory playerInventory, Component name) {
super(container, playerInventory, name);
this.storageControllerContainer = container;
Expand Down Expand Up @@ -725,11 +728,18 @@ protected List<ItemStack> applySearchToItems() {
String searchText = this.searchBar.getValue();

if (!searchText.equals("")) {
if (this.cachedStacksToDisplay != null && this.cachedSearchString != null && this.cachedSearchString.equals(searchText))
return this.cachedStacksToDisplay;

List<ItemStack> stacksToDisplay = new ArrayList<>();
for (ItemStack stack : this.stacks) {
if (this.itemMatchesSearch(stack))
stacksToDisplay.add(stack);
}

this.cachedStacksToDisplay = stacksToDisplay;
this.cachedSearchString = searchText;

return stacksToDisplay;
}
return new ArrayList<>(this.stacks);
Expand Down

0 comments on commit 9518818

Please sign in to comment.