Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
e99e2da7
Unverified
Commit
e99e2da7
authored
5 years ago
by
Tom Robinson
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix expression string literal performance. Resolves #12154 (#12213)
parent
a1ab89e8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frontend/src/metabase/lib/expressions/lexer.js
+13
-5
13 additions, 5 deletions
frontend/src/metabase/lib/expressions/lexer.js
frontend/test/metabase/lib/expressions/compile.unit.spec.js
+34
-20
34 additions, 20 deletions
frontend/test/metabase/lib/expressions/compile.unit.spec.js
with
47 additions
and
25 deletions
frontend/src/metabase/lib/expressions/lexer.js
+
13
−
5
View file @
e99e2da7
...
...
@@ -196,6 +196,14 @@ const getQuoteCategories = character => {
:
[];
};
const
quotedStringRegex
=
(
character
,
closed
=
true
)
=>
{
const
open
=
character
;
const
close
=
closed
?
character
:
""
;
return
new
RegExp
(
`
${
open
}
(?:[^
\\\\
${
character
}
]|
\\\\
(?:[bfnrtv
${
character
}
\\\\
/]|u[0-9a-fA-F]{4}))*
${
close
}
`
,
);
};
export
const
BracketQuotedString
=
createToken
({
name
:
"
BracketQuotedString
"
,
pattern
:
/
\[[^\]]
*
\]
/
,
...
...
@@ -203,12 +211,12 @@ export const BracketQuotedString = createToken({
});
export
const
SingleQuotedString
=
createToken
({
name
:
"
SingleQuotedString
"
,
pattern
:
/'
(?:[^\\
'
]
+|
\\(?:[
bfnrtv'
\\/]
|u
[
0-9a-fA-F
]{4}))
*'/
,
pattern
:
quotedStringRegex
(
"
'
"
)
,
categories
:
getQuoteCategories
(
"
'
"
),
});
export
const
DoubleQuotedString
=
createToken
({
name
:
"
DoubleQuotedString
"
,
pattern
:
/"
(?:[^\\
"
]
+|
\\(?:[
bfnrtv"
\\/]
|u
[
0-9a-fA-F
]{4}))
*"/
,
pattern
:
quotedStringRegex
(
'
"
'
)
,
categories
:
getQuoteCategories
(
'
"
'
),
});
...
...
@@ -274,12 +282,12 @@ export const UnclosedBracketQuotedString = createToken({
});
export
const
UnclosedSingleQuotedString
=
createToken
({
name
:
"
UnclosedSingleQuotedString
"
,
pattern
:
/'
(?:[^\\
'
]
+|
\\(?:[
bfnrtv'
\\/]
|u
[
0-9a-fA-F
]{4}))
*/
,
pattern
:
quotedStringRegex
(
"
'
"
,
false
)
,
categories
:
[
RecoveryToken
,
UnclosedQuotedString
,
...
getQuoteCategories
(
"
'
"
)],
});
export
const
UnclosedDoubleQuotedString
=
createToken
({
name
:
"
DoubleQuo
UnclosedDoubleQuotedString
tedString
"
,
pattern
:
/"
(?:[^\\
"
]
+|
\\(?:[
bfnrtv"
\\/]
|u
[
0-9a-fA-F
]{4}))
*/
,
name
:
"
UnclosedDoubleQuotedString
"
,
pattern
:
quotedStringRegex
(
'
"
'
,
false
)
,
categories
:
[
RecoveryToken
,
UnclosedQuotedString
,
...
getQuoteCategories
(
'
"
'
)],
});
export
const
Any
=
createToken
({
...
...
This diff is collapsed.
Click to expand it.
frontend/test/metabase/lib/expressions/compile.unit.spec.js
+
34
−
20
View file @
e99e2da7
...
...
@@ -6,17 +6,26 @@ import {
expressionOpts
,
}
from
"
./__support__/expressions
"
;
const
ENABLE_PERF_TESTS
=
false
;
const
ENABLE_PERF_TESTS
=
!
process
.
env
[
"
CI
"
];
function
expectFast
(
fn
,
milliseconds
=
1000
)
{
const
start
=
Date
.
now
();
fn
();
const
end
=
Date
.
now
();
if
(
ENABLE_PERF_TESTS
)
{
expect
(
end
-
start
).
toBeLessThan
(
milliseconds
);
}
}
describe
(
"
metabase/lib/expressions/compile
"
,
()
=>
{
let
compile
,
parseOperators
;
it
(
"
should load compile
within 3 seconds
"
,
()
=>
{
const
start
=
Date
.
now
();
({
compile
,
parseOperators
}
=
require
(
"
metabase/lib/expressions/compile
"
));
const
end
=
Date
.
now
();
if
(
ENABLE_PERF_TESTS
)
{
expect
(
end
-
start
).
toBeLessThan
(
3000
);
}
it
(
"
should load compile
quickly
"
,
()
=>
{
expectFast
(()
=>
{
({
compile
,
parseOperators
,
}
=
require
(
"
metabase/lib/expressions/compile
"
)
);
}
);
});
describe
(
"
parseOperators
"
,
()
=>
{
...
...
@@ -58,21 +67,15 @@ describe("metabase/lib/expressions/compile", () => {
for
(
const
[
source
,
mbql
,
description
]
of
cases
)
{
if
(
mbql
)
{
it
(
`should compile
${
description
}
`
,
()
=>
{
const
start
=
Date
.
now
();
expect
(
compile
({
source
,
...
opts
})).
toEqual
(
mbql
);
const
elapsed
=
Date
.
now
()
-
start
;
if
(
ENABLE_PERF_TESTS
)
{
expect
(
elapsed
).
toBeLessThan
(
250
);
}
expectFast
(()
=>
{
expect
(
compile
({
source
,
...
opts
})).
toEqual
(
mbql
);
},
250
);
});
}
else
{
it
(
`should not compile
${
description
}
`
,
()
=>
{
const
start
=
Date
.
now
();
expect
(()
=>
compile
({
source
,
...
opts
})).
toThrow
();
const
elapsed
=
Date
.
now
()
-
start
;
if
(
ENABLE_PERF_TESTS
)
{
expect
(
elapsed
).
toBeLessThan
(
250
);
}
expectFast
(()
=>
{
expect
(()
=>
compile
({
source
,
...
opts
})).
toThrow
();
},
250
);
});
}
}
...
...
@@ -97,5 +100,16 @@ describe("metabase/lib/expressions/compile", () => {
[
"
field-id
"
,
1
],
]);
});
it
(
"
should not take a long time to parse long string literals
"
,
()
=>
{
expectFast
(()
=>
{
try
{
compile
({
source
:
'
"12345678901234567901234567890
'
,
...
expressionOpts
,
});
}
catch
(
e
)
{}
});
});
});
});
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment