-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): add remote cache counter (#3271)
- Loading branch information
Showing
6 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import RemoteCacheCounter from "./RemoteCacheCounter"; | ||
import { useTurboSite } from "./SiteSwitcher"; | ||
|
||
export default function ExtraContent() { | ||
const site = useTurboSite(); | ||
|
||
if (site === "repo") { | ||
return <RemoteCacheCounter />; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import cn from "classnames"; | ||
import { useState, useEffect } from "react"; | ||
import { animated, useSpring, config } from "@react-spring/web"; | ||
import useTurborepoMinutesSaved from "../lib/useTurborepoMinutesSaved"; | ||
import Link from "next/link"; | ||
|
||
const counterFormatter = Intl.NumberFormat(undefined, { | ||
minimumIntegerDigits: 7, | ||
maximumFractionDigits: 0, | ||
}); | ||
|
||
export default function RemoteCacheCounter() { | ||
const [targetMinutes, setTargetMinutes] = useState(0); | ||
const timeSaved = useTurborepoMinutesSaved(); | ||
useEffect(() => { | ||
if (timeSaved) { | ||
setTargetMinutes( | ||
timeSaved.local_cache_minutes_saved + | ||
timeSaved.remote_cache_minutes_saved | ||
); | ||
} | ||
}, [timeSaved]); | ||
|
||
const spring = useSpring({ | ||
from: { minutesSaved: 0 }, | ||
minutesSaved: targetMinutes, | ||
config: config.molasses, | ||
}); | ||
|
||
return ( | ||
<Link | ||
href="/repo/docs/core-concepts/remote-caching" | ||
className="group mt-4 w-full h-full rounded-lg p-[1px] bg-gradient-to-r from-red-500 to-blue-500 dark:text-[#9ca3af] text-[#6b7280]" | ||
> | ||
<div className="justify-between h-full rounded-lg p-4 dark:bg-[#111111] bg-white"> | ||
<animated.p className="inline-block text-xl bg-gradient-to-r from-red-500 to-blue-500 bg-clip-text text-transparent"> | ||
{spring.minutesSaved.to((t) => counterFormatter.format(t))} | ||
</animated.p> | ||
<div className="text-xs">Total Compute Minutes Saved</div> | ||
|
||
<div className="text-xs mt-4 group-hover:underline"> | ||
Get Started With Remote Caching → | ||
</div> | ||
</div> | ||
</Link> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import useSWR from "swr"; | ||
import axios from "axios"; | ||
|
||
const fetcher = (url) => axios.get(url).then((res) => res.data); | ||
|
||
const path = | ||
"https://api.us-east.tinybird.co/v0/pipes/turborepo_time_saved_ticker.json?token=p.eyJ1IjogIjAzYzA0Y2MyLTM1YTAtNDhhNC05ZTZjLThhMWE0NGNhNjhkZiIsICJpZCI6ICJmOWIzMTU5Yi0wOTVjLTQyM2UtOWIwNS04ZDZlNzIyNjEwNzIifQ.A3TOPdm3Lhmn-1x5m6jNvulCQbbgUeQfAIO3IaaAt5k"; | ||
|
||
const REFRESH_INTERVAL_IN_MS = 3500; | ||
|
||
interface QueryResponse { | ||
meta: { name: string; type: string }[]; | ||
data: { | ||
last_update_time: string; | ||
remote_cache_minutes_saved: number; | ||
local_cache_minutes_saved: number; | ||
}[]; | ||
rows: number; | ||
statistics: { | ||
elapsed: number; | ||
rows_read: number; | ||
bytes_read: number; | ||
}; | ||
} | ||
|
||
export default function useTurborepoMinutesSaved(): | ||
| { | ||
last_update_time: string; | ||
remote_cache_minutes_saved: number; | ||
local_cache_minutes_saved: number; | ||
} | ||
| undefined { | ||
const swr = useSWR<QueryResponse, unknown>(path, fetcher, { | ||
refreshInterval: REFRESH_INTERVAL_IN_MS, | ||
}); | ||
|
||
return swr.data?.data[0]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
88b8c5f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
turbo-site – ./docs
turbo.vercel.sh
turbopack.org
www.turbo.build
turbo.build
turbo-site.vercel.sh
turbo.vercel.app
www.turborepo.com
turborepo.org
turbo-site-git-main.vercel.sh
www.turborepo.org
www.turbopack.org