Skip to content

Commit 65bae5d

Browse files
committed
Limit the number of "string forms" a block can have
1 parent f7b6ce6 commit 65bae5d

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

addons/middle-click-popup/WorkspaceQuerier.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@ class TokenTypeBlock extends TokenType {
733733
strings.push(...blockPart.toLowerCase().split(" "));
734734
} else if (blockPart.type === BlockInputType.ENUM) {
735735
for (const enumValue of blockPart.values) {
736+
737+
if (this.stringForms.length >= WorkspaceQuerier.MAX_RESULTS)
738+
return;
739+
736740
enumerateStringForms(
737741
partIdx + 1,
738742
[...strings, ...enumValue.string.toLowerCase().split(" ")],
@@ -749,11 +753,16 @@ class TokenTypeBlock extends TokenType {
749753
};
750754

751755
enumerateStringForms();
756+
757+
if (this.stringForms.length >= WorkspaceQuerier.MAX_STRING_FORMS) {
758+
console.log("Warning: Block '" + this.block.id + "' has too many string forms. Search results may not be very good.");
759+
this.stringForms.length = 0;
760+
}
752761
}
753762

754763
/**
755764
* @param {QueryInfo} query
756-
* @param {number} idx
765+
* @param {number} idxi
757766
* @param {number} depth
758767
* @returns
759768
*/
@@ -1159,12 +1168,17 @@ export default class WorkspaceQuerier {
11591168
/**
11601169
* The maximum number of results to find before we give up searching sub-blocks.
11611170
*/
1162-
static MAX_RESULTS = 1000;
1171+
static MAX_RESULTS = 2000;
11631172

11641173
/**
11651174
* The maximum number of tokens to find before giving up.
11661175
*/
1167-
static MAX_TOKENS = 10000;
1176+
static MAX_TOKENS = 100000;
1177+
1178+
/**
1179+
* The maximum number of string forms a block can have before we give up.
1180+
*/
1181+
static MAX_STRING_FORMS = 500;
11681182

11691183
/**
11701184
* Indexes a workspace in preparation for querying it.

0 commit comments

Comments
 (0)