8000 feat: adds ui load tester & getStaticProps from getServerSideProps by YazeedLoonat · Pull Request #4882 · bloom-housing/bloom · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: adds ui load tester & getStaticProps from getServerSideProps #4882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"test:backend:new:dbsetup": "cd api && yarn db:migration:run",
"test:backend:new:dbsetup:withseed": "cd api && yarn db:migration:run && yarn db:seed:staging --jurisdictionName Bloomington",
"backend:new:install": "cd api && yarn install",
"prettier": "prettier --write \"./**/*.{js,jsx,ts,tsx,json}\""
"prettier": "prettier --write \"./**/*.{js,jsx,ts,tsx,json}\"",
"ui-load-test": "ruby ./utilities/ui-load-tester.rb"
},
"devDependencies": {
"@commitlint/cli": "^13.1.0",
Expand Down
5 changes: 3 additions & 2 deletions sites/public/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ RTL_LANGUAGES=ar
IDLE_TIMEOUT=5
JURISDICTION_NAME=Bloomington
CLOUDINARY_CLOUD_NAME=exygy
# next js cache revalidate
CACHE_REVALIDATE=60
NEW_RELIC_APP_NAME=Bloom Public
NEW_RELIC_LICENSE_KEY=
SENTRY_ORG=
Expand Down Expand Up @@ -49,3 +47,6 @@ DD_API_KEY=
DD_SITE=
# DataDog Agent Version
DD_AGENT_MAJOR_VERSION=

# used to control how long we hold onto a listing detail page server side render cache (in seconds)
CACHE_REVALIDATE=30
2 changes: 1 addition & 1 deletion sites/public/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = withBundleAnalyzer({
gtmKey: process.env.GTM_KEY || null,
idleTimeout: process.env.IDLE_TIMEOUT,
jurisdictionName: process.env.JURISDICTION_NAME,
cacheRevalidate: process.env.CACHE_REVALIDATE ? Number(process.env.CACHE_REVALIDATE) : 60,
cacheRevalidate: process.env.CACHE_REVALIDATE ? Number(process.env.CACHE_REVALIDATE) : 30,
cloudinaryCloudName: process.env.CLOUDINARY_CLOUD_NAME,
showPublicLottery: process.env.SHOW_PUBLIC_LOTTERY === "TRUE",
showNewSeedsDesigns: process.env.SHOW_NEW_SEEDS_DESIGNS === "TRUE",
Expand Down
59 changes: 11 additions & 48 deletions sites/public/src/pages/listing/[id]/[slug].tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useContext } from "react"
import Head from "next/head"
import { GetStaticPaths, GetStaticProps } from "next"
import axios from "axios"
import { t } from "@bloom-housing/ui-components"
import {
Expand Down Expand Up @@ -79,68 +80,30 @@ export default function ListingPage(props: ListingProps) {
</Layout>
)
}
/**
*
* getStaticPaths and getStaticProps with revalidation isn't actually working on netflify, so we have to use getServerSideProps until it does
*/
/* export async function getStaticPaths(context: { locales: Array<string> }) {
try {
const response = await axios.get(process.env.listingServiceUrl, {
params: {
view: "base",
limit: "all",
filter: [
{
$comparison: "<>",
status: "pending",
},
],
},
paramsSerializer: (params) => {
return qs.stringify(params)
},
})

return {
paths: response?.data?.items
? context.locales.flatMap((locale: string) =>
response.data.items.map((listing) => ({
params: { id: listing.id, slug: listing.urlSlug },
locale: locale,
}))
)
: [],
fallback: "blocking",
}
} catch (error) {
console.error("listings getStaticPaths error = ", error)
return {
paths: [],
fallback: "blocking",
}
}
} */
export const getStaticPaths: GetStaticPaths = () => {
return { paths: [], fallback: "blocking" }
}

export async function getServerSideProps(context: {
export const getStaticProps: GetStaticProps = async (context: {
params: Record<string, string>
locale: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
req: any
}) {
}) => {
let response
try {
response = await axios.get(`${process.env.backendApiBase}/listings/${context.params.id}`, {
headers: {
language: context.locale,
passkey: process.env.API_PASS_KEY,
"x-forwarded-for":
context.req.headers["x-forwarded-for"] ?? context.req.socket.remoteAddress,
},
})
} catch (e) {
return { notFound: true }
}
const jurisdiction = fetchJurisdictionByName(context.req)
const jurisdiction = fetchJurisdictionByName()

return { props: { listing: response.data, jurisdiction: await jurisdiction } }
return {
props: { listing: response.data, jurisdiction: await jurisdiction },
revalidate: Number(process.env.cacheRevalidate),
}
}
30 changes: 30 additions & 0 deletions utilities/ui-load-tester.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# What is this:
# This is a ruby script to load test any of our front end urls

# Why is this written in ruby?
# Ruby supports multithreading much better natively than node/js does

# How to use:
# `ab` is a benchmarking utility, its used here to mock traffic to whatever url you pass along
# You can check out how `ab` works separately. On mac you can run `man ab` in a terminal to get the manual for ab
# you can change the n arguments on these calls to increase the total number of requests
# you can change the c arguments on these calls to increase the throughput basically (number of requests made concurrently)
# you can change the url arguments on these calls to direct which url will receive the traffic
# to execute once your changes are made from the root directory run `yarn ui-load-test`
# In order to test mem usage you can attach the node debugger to either the public or partner sites and track mem usage that way
# You can also track cpu usage, or track it through a cpu activity monitor

def main()
# call main page english
spawnProcess(100, 10, "http://localhost:3000/")
end

# n: the number of requests
# c: the number of calls made concurrently
# url: the url you are trying to hit
def spawnProcess(n, c, url)
spawn("ab -n #{n} -c #{c} \"#{url}\"")
end

main()

0