Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
frontend
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
vicotor
frontend
Commits
794d02e6
Commit
794d02e6
authored
Jan 26, 2023
by
tom
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
server timings
parent
2e6bd017
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
0 deletions
+36
-0
serverTiming.ts
lib/next/serverTiming.ts
+10
-0
_document.tsx
pages/_document.tsx
+19
-0
search-results.tsx
pages/search-results.tsx
+7
-0
No files found.
lib/next/serverTiming.ts
0 → 100644
View file @
794d02e6
import
type
{
ServerResponse
}
from
'
http
'
;
export
function
appendValue
(
res
:
ServerResponse
|
undefined
,
name
:
string
,
value
:
number
)
{
const
currentValue
=
res
?.
getHeader
(
'
Server-Timing
'
)
||
''
;
const
nextValue
=
[
currentValue
,
`
${
name
}
;dur=
${
value
}
`
,
].
filter
(
Boolean
).
join
(
'
,
'
);
res
?.
setHeader
(
'
Server-Timing
'
,
nextValue
);
}
pages/_document.tsx
View file @
794d02e6
import
{
ColorModeScript
}
from
'
@chakra-ui/react
'
;
import
type
{
DocumentContext
}
from
'
next/document
'
;
import
Document
,
{
Html
,
Head
,
Main
,
NextScript
}
from
'
next/document
'
;
import
React
from
'
react
'
;
import
*
as
serverTiming
from
'
lib/next/serverTiming
'
;
import
theme
from
'
theme
'
;
class
MyDocument
extends
Document
{
static
async
getInitialProps
(
ctx
:
DocumentContext
)
{
const
originalRenderPage
=
ctx
.
renderPage
;
ctx
.
renderPage
=
async
()
=>
{
const
start
=
Date
.
now
();
const
result
=
await
originalRenderPage
();
const
end
=
Date
.
now
();
serverTiming
.
appendValue
(
ctx
.
res
,
'
renderPage
'
,
end
-
start
);
return
result
;
};
const
initialProps
=
await
Document
.
getInitialProps
(
ctx
);
return
initialProps
;
}
render
()
{
return
(
<
Html
lang=
"en"
>
...
...
pages/search-results.tsx
View file @
794d02e6
...
...
@@ -10,6 +10,7 @@ import link from 'lib/link/link';
import
getNetworkTitle
from
'
lib/networks/getNetworkTitle
'
;
import
type
{
Props
}
from
'
lib/next/getServerSideProps
'
;
import
{
getServerSideProps
as
getServerSidePropsBase
}
from
'
lib/next/getServerSideProps
'
;
import
*
as
serverTiming
from
'
lib/next/serverTiming
'
;
import
SearchResults
from
'
ui/pages/SearchResults
'
;
const
SearchResultsPage
:
NextPage
=
()
=>
{
...
...
@@ -27,6 +28,8 @@ const SearchResultsPage: NextPage = () => {
export
default
SearchResultsPage
;
export
const
getServerSideProps
:
GetServerSideProps
<
Props
>
=
async
({
req
,
res
,
resolvedUrl
,
query
})
=>
{
const
start
=
Date
.
now
();
try
{
const
q
=
String
(
query
.
q
);
const
url
=
buildUrlNode
(
'
search_check_redirect
'
,
undefined
,
{
q
});
...
...
@@ -63,5 +66,9 @@ export const getServerSideProps: GetServerSideProps<Props> = async({ req, res, r
};
}
catch
(
error
)
{}
const
end
=
Date
.
now
();
serverTiming
.
appendValue
(
res
,
'
query.search.check-redirect
'
,
end
-
start
);
return
getServerSidePropsBase
({
req
,
res
,
resolvedUrl
,
query
});
};
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