Skip to content
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

Refactoring and Improving Price related API Route #290

Merged
merged 16 commits into from
Jan 14, 2025
Merged

Conversation

Aliiiu
Copy link
Contributor

@Aliiiu Aliiiu commented Jan 8, 2025

Refactoring and Improving Price-related API Route

This PR works on improving the caching on price related API route to reduce load on server, Resolve issue with twitter following API continuous loading.

Linked issues

closes EveripediaNetwork/issues#3728

Copy link

stackblitz bot commented Jan 8, 2025

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

vercel bot commented Jan 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
iq-dashboard ✅ Ready (Inspect) Visit Preview Jan 14, 2025 3:24pm

@@ -164,7 +168,7 @@ const StatsPage = () => {
>
{isFailedToFetchData
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we rename showData to a component that accepts <StatInfo ...{props} /> then we use composition api to render the outcome.

res: NextApiResponse,
cacheHeader = `public, s-maxage=${config.CACHE_DURATION_SECONDS}, stale-while-revalidate=${config.CACHE_STALE_WHILE_REVALIDATE_SECONDS}`,
) => {
res.setHeader('Cache-Control', cacheHeader)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
res.setHeader('Cache-Control', cacheHeader)
import config from '@/config'
import { NextApiResponse } from 'next'
export const setCacheHeaders = (
res: NextApiResponse,
cacheHeader = `public, s-maxage=${config.CACHE_DURATION_SECONDS}, stale-while-revalidate=${config.CACHE_STALE_WHILE_REVALIDATE_SECONDS}`
): void => {
const headers = [
['Cache-Control', cacheHeader],
['CDN-Cache-Control', cacheHeader],
['Vercel-CDN-Cache-Control', cacheHeader]
] as const
headers.forEach(([name, value]) => res.setHeader(name, value))
}

<span>Loading...</span>
</Spinner>
)
const ShowData = ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this to

const NumericDisplay = ({
  value,
  prefix,
  isFetched,
  isFailedToFetchData
}: NumericDisplayProps) => {
  // ... same implementation
}

Also, we could handle the isFailedToFetchData inside it not outside, i.e

interface NumericDisplayProps {
  value: number | undefined
  prefix?: string
  isFetched?: boolean
  isFailedToFetchData?: boolean
}

const NumericDisplay = ({
  value,
  prefix,
  isFetched,
  isFailedToFetchData
}: ShowDataProps) => {
  if (isFailedToFetchData) {
    return '-'
  }

  if (value === undefined && !isFetched) {
    return (
      <Spinner variant="primary" role="status" size="sm">
        <span>Loading...</span>
      </Spinner>
    )
  }

  return value ? (prefix || '') + Humanize.formatNumber(value) : '-'
}

Copy link

codeclimate bot commented Jan 14, 2025

Code Climate has analyzed commit 6f7383d and detected 0 issues on this pull request.

View more on Code Climate.

useRadio(radioProps)
return (
<chakra.label
{...htmlProps}
cursor={state.isDisabled ? 'not-allowed' : 'pointer'}
>
<input {...getInputProps({})} hidden />
<Box {...getCheckboxProps()}>
<Box {...getRadioProps()}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this, why radio props?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getCheckboxProps is deprecated

@Aliiiu Aliiiu merged commit 8ab9781 into main Jan 14, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Twitter Followers keeps loading endlessly on Stat page
2 participants