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
49358630
Unverified
Commit
49358630
authored
7 months ago
by
Oleksandr Yakushev
Committed by
GitHub
7 months ago
Browse files
Options
Downloads
Patches
Plain Diff
perf: [date-2.parse] Add a fastpath for timestamps that are likely ISO instants (#47143)
parent
65b3ef01
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/metabase/util/date_2/parse.clj
+13
-3
13 additions, 3 deletions
src/metabase/util/date_2/parse.clj
with
13 additions
and
3 deletions
src/metabase/util/date_2/parse.clj
+
13
−
3
View file @
49358630
...
...
@@ -7,8 +7,8 @@
[
metabase.util.i18n
:refer
[
tru
]]
[
metabase.util.malli
:as
mu
])
(
:import
(
java.time
LocalDateTime
OffsetDateTime
OffsetTime
ZonedDateTime
ZoneOffset
)
(
java.time.format
DateTimeFormatter
)
(
java.time
Instant
LocalDateTime
OffsetDateTime
OffsetTime
ZonedDateTime
ZoneOffset
)
(
java.time.format
DateTimeFormatter
DateTimeParseException
)
(
java.time.temporal
Temporal
TemporalAccessor
TemporalField
TemporalQueries
)))
(
set!
*warn-on-reflection*
true
)
...
...
@@ -49,6 +49,15 @@
(
def
^
:private
utc-zone-region
(
t/zone-id
"UTC"
))
(
defn-
try-parse-as-iso-timestamp
"Fastpath for parsing ISO Instant timestamp if it matches the required length. Return nil if the length doesn't match
or the parsing fails, otherwise return a ZonedDateTime instance at UTC."
[
^
String
s
]
(
when
(
and
s
(
=
(
.length
s
)
(
.length
"1970-01-01T00:00:00Z"
)))
(
try
(
let
[
temporal-accessor
(
.parse
DateTimeFormatter/ISO_INSTANT
s
)]
(
.atZone
(
Instant/from
temporal-accessor
)
utc-zone-region
))
(
catch
DateTimeParseException
_
))))
(
mu/defn
parse-with-formatter
:-
[
:maybe
InstanceOfTemporal
]
"Parse a String with a DateTimeFormatter, returning an appropriate instance of an `java.time` temporal class."
[
formattr
...
...
@@ -137,4 +146,5 @@
(
defn
parse
"Parse a string into a `java.time` object."
[
^
String
s
]
(
parse-with-formatter
formatter
s
))
(
or
(
try-parse-as-iso-timestamp
s
)
;; Try the fastpath first.
(
parse-with-formatter
formatter
s
)))
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