postgres
postgres copied to clipboard
fix: default max connections in cloudflare to lower
Fixes https://github.com/porsager/postgres/issues/1023
That's a compiled file, so the change will be removed on publish.
Ah I see, sorry. Would it make sense to add this to the transpile.cf.js file instead?
Let me know if you'd like to see any other changes here @porsager. It'd be good to get this merged to prevent this common footgun!
Let me know if there's anything else I can do to get this landed @porsager, thanks!
Hi James.. Yes - let's get this finished.
I'm wondering if maybe dynamic resolution is better? If we at one point can move the Cloudflare polyfill I'm afraid we'll forget the max: 3 limit.
Is there an env var we could rely on in cloudflare or perhaps a global?
Cloudflare does make globalThis.Cloudflare available on any modern workers (I'm not 100% certain if this is available on older service worker formatted Workers), which might suffice for checking? Alternatively, we could add a test that just asserts the output for the cloudflare build to have max: 3 which should catch any regressions?
Something like this should work after the defaults setting:
// Adjust max connections for Cloudflare Workers
// https://github.com/porsager/postgres/issues/1023
if (typeof globalThis !== 'undefined' && 'Cloudflare' in globalThis) {
defaults.max = 3;
}
Happy to do that if preferred, let me know!
Cool! globalThis is available on all supported platforms, so if you add it as a ternary to defaults like this instead that'd be great!
max : globalThis.Cloudflare ? 3 : 10
A nice and simple one line PR ;)
Done, thanks! Let me know if any other changes are needed.
Nice - just remove the changes to everything but src/index.js as those are built automatically anyway. Also remove the comment - git keeps enough history ;)
Sounds good, done, thanks