Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions .changeset/major-comics-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@opennextjs/cloudflare": patch
---

fix cache population hanging
8 changes: 6 additions & 2 deletions packages/cloudflare/src/cli/commands/populate-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ async function populateR2IncrementalCache(

const config = unstable_readConfig({ env: populateCacheOptions.environment });
const proxy = await getPlatformProxy<CloudflareEnv>(populateCacheOptions);
const prefix = proxy.env[R2_CACHE_PREFIX_ENV_NAME]; // Set the cache type to R2 for the current environment
await proxy.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

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

2 nits:

  • Maybe extract this into async getEnvFromPlatformProxy()?
  • Only call it after line 109 (i.e. skip if not needed)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Maybe extract this into async getEnvFromPlatformProxy()

I was thinking actually that we could use the proxy bindings when target is local. I just tested that and it's like a 60 times speed up WDYT ?
Probably in another PR though

Copy link
Contributor

Choose a reason for hiding this comment

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

We can create an issue for now.

I think implementing batch population in wrangler would be better as it could benefit other projects.


const binding = config.r2_buckets.find(({ binding }) => binding === R2_CACHE_BINDING_NAME);
if (!binding) {
Expand All @@ -115,7 +117,7 @@ async function populateR2IncrementalCache(

for (const { fullPath, key, buildId, isFetch } of tqdm(assets)) {
const cacheKey = computeCacheKey(key, {
prefix: proxy.env[R2_CACHE_PREFIX_ENV_NAME],
prefix,
buildId,
cacheType: isFetch ? "fetch" : "cache",
});
Expand All @@ -139,6 +141,8 @@ async function populateKVIncrementalCache(

const config = unstable_readConfig({ env: populateCacheOptions.environment });
const proxy = await getPlatformProxy<CloudflareEnv>(populateCacheOptions);
const prefix = proxy.env[KV_CACHE_PREFIX_ENV_NAME];
await proxy.dispose();

const binding = config.kv_namespaces.find(({ binding }) => binding === KV_CACHE_BINDING_NAME);
if (!binding) {
Expand All @@ -159,7 +163,7 @@ async function populateKVIncrementalCache(
.slice(i * chunkSize, (i + 1) * chunkSize)
.map(({ fullPath, key, buildId, isFetch }) => ({
key: computeCacheKey(key, {
prefix: proxy.env[KV_CACHE_PREFIX_ENV_NAME],
prefix,
buildId,
cacheType: isFetch ? "fetch" : "cache",
}),
Expand Down