Unverified Commit 19f9692b authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Update URL provided from unstable_cache (#66651)

As discussed this updates the URL value provided from `unstable_cache`
to include the current pathname and sorted search params so that it's
easier to identify where the call is being done for using debug metrics.

x-ref: [slack
thread](https://vercel.slack.com/archives/C042LHPJ1NX/p1717012449080709?thread_ts=1716942410.700499&cid=C042LHPJ1NX)
parent a1f70ae2
...@@ -105,12 +105,24 @@ export function unstable_cache<T extends Callback>( ...@@ -105,12 +105,24 @@ export function unstable_cache<T extends Callback>(
} }
const incrementalCache = maybeIncrementalCache const incrementalCache = maybeIncrementalCache
const { pathname, searchParams } = new URL(
store?.urlPathname || '/',
'http://n'
)
const sortedSearchKeys = [...searchParams.keys()].sort((a, b) => {
return a.localeCompare(b)
})
const sortedSearch = sortedSearchKeys
.map((key) => searchParams.get(key))
.join('&')
// Construct the complete cache key for this function invocation // Construct the complete cache key for this function invocation
// @TODO stringify is likely not safe here. We will coerce undefined to null which will make // @TODO stringify is likely not safe here. We will coerce undefined to null which will make
// the keyspace smaller than the execution space // the keyspace smaller than the execution space
const invocationKey = `${fixedKey}-${JSON.stringify(args)}` const invocationKey = `${fixedKey}-${JSON.stringify(args)}`
const cacheKey = await incrementalCache.fetchCacheKey(invocationKey) const cacheKey = await incrementalCache.fetchCacheKey(invocationKey)
const fetchUrl = `unstable_cache ${cb.name ? ` ${cb.name}` : cacheKey}` // $urlWithPath,$sortedQueryStringKeys,$hashOfEveryThingElse
const fetchUrl = `unstable_cache ${pathname}${sortedSearch.length ? '?' : ''}${sortedSearch} ${cb.name ? ` ${cb.name}` : cacheKey}`
const fetchIdx = (store ? store.nextFetchId : noStoreFetchIdx) ?? 1 const fetchIdx = (store ? store.nextFetchId : noStoreFetchIdx) ?? 1
if (store) { if (store) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment