Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
df6c44d2
Unverified
Commit
df6c44d2
authored
Sep 22, 2023
by
eddie
Committed by
GitHub
Sep 22, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: use Date as a performance tracker fallback (#7349)
parent
59e7a286
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
7 deletions
+17
-7
SwapEventTimestampTracker.test.ts
src/tracing/SwapEventTimestampTracker.test.ts
+1
-1
SwapEventTimestampTracker.ts
src/tracing/SwapEventTimestampTracker.ts
+3
-2
utils.ts
src/tracing/utils.ts
+13
-4
No files found.
src/tracing/SwapEventTimestampTracker.test.ts
View file @
df6c44d2
import
{
SwapEventTimestampTracker
,
SwapEventType
}
from
'
./SwapEventTimestampTracker
'
jest
.
mock
(
'
./utils
'
,
()
=>
({
calculateElapsedTimeWithPerformanceMark
:
(
mark
:
string
)
=>
{
calculateElapsedTimeWithPerformanceMark
Ms
:
(
mark
:
string
)
=>
{
switch
(
mark
)
{
case
SwapEventType
.
FIRST_SWAP_ACTION
:
return
100
...
...
src/tracing/SwapEventTimestampTracker.ts
View file @
df6c44d2
import
{
calculateElapsedTimeWithPerformanceMark
}
from
'
./utils
'
import
{
calculateElapsedTimeWithPerformanceMark
Ms
}
from
'
./utils
'
// These events should happen in this order.
export
enum
SwapEventType
{
...
...
@@ -18,6 +18,7 @@ export enum SwapEventType {
export
class
SwapEventTimestampTracker
{
private
static
_instance
:
SwapEventTimestampTracker
private
createdAt
=
Date
.
now
()
private
constructor
()
{
// Private constructor to prevent direct construction calls with the `new` operator.
}
...
...
@@ -36,7 +37,7 @@ export class SwapEventTimestampTracker {
public
setElapsedTime
(
eventType
:
SwapEventType
):
number
|
undefined
{
if
(
this
.
timestamps
.
has
(
eventType
))
return
undefined
const
elapsedTime
=
calculateElapsedTimeWithPerformanceMark
(
eventType
)
const
elapsedTime
=
calculateElapsedTimeWithPerformanceMark
Ms
(
eventType
,
this
.
createdAt
)
if
(
elapsedTime
)
{
this
.
timestamps
.
set
(
eventType
,
elapsedTime
)
}
...
...
src/tracing/utils.ts
View file @
df6c44d2
/**
* Returns the time elapsed between page load and now.
* Returns the time elapsed between page load and now
in milliseconds
.
* @param markName the identifier for the performance mark to be created and measured.
*/
export
function
calculateElapsedTimeWithPerformanceMark
(
markName
:
string
):
number
|
undefined
{
export
function
calculateElapsedTimeWithPerformanceMarkMs
(
markName
:
string
,
fallbackStartTime
?:
number
):
number
|
undefined
{
const
elapsedTime
=
performance
.
mark
(
markName
)
if
(
!
elapsedTime
)
return
undefined
return
elapsedTime
.
startTime
if
(
elapsedTime
)
{
return
elapsedTime
.
startTime
}
if
(
fallbackStartTime
)
{
// On some browsers like iOS WebViews, performance.mark is not supported.
return
Date
.
now
()
-
fallbackStartTime
}
return
undefined
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment