Comments (3)
Update: This appears to not be related to applyTransform
or loadOne
at all. There's a simpler repro here with just each
: https://github.com/scottravio/grafast-memory-spike-repro
from crystal.
This is due to the each()
creating a subroutine (since it's not used as the return result of a plan resolver, but instead as input to another step), and subroutines are currently not hoisted (see #2041); as such we're having to run the each
transform with a batch size of 1000 (because you're fetching 1000 users, and this is a field in the User
type), and for each of those 1,000 user we're then mapping over the 1000 languages ultimately resulting in 1000*1000 = 1,000,000 values.
Since your step here is not dependent on $user
, theoretically we should be able to hoist it (see #2041) but we currently do not. Instead, try and ensure that the steps that you use can all be hoisted (see the plan diagram to see which bucket the steps exist in); for example:
plans: {
User: {
totalLanguages() {
const $allLangugages = withPgClient(
executor,
constant(null),
async (pgClient) => {
const { rows } = await pgClient.query({
text: `select language from languages`,
});
return rows;
},
);
$allLangugages.hasSideEffects = false;
return lambda(
$allLangugages,
(allLangugages) => allLangugages.length,
);
},
},
},
However, it would be better to directly address your need, which in this case seems to be counting the number of languages on a per-user basis, so perhaps something like:
plans: {
User: {
totalLanguages($user) {
const $agg = user_config.find({ user_id: $user.get("id") }).clone("aggregate");
return $agg.single().select(sql`count(*)`, TYPES.bigint);
},
},
},
Note that .clone
is currently marked as an internal API, but that is resolved in #2039.
from crystal.
Closing this issue in favour of the related issues #2039, #2040 and #2041.
from crystal.
Related Issues (20)
- Produce high-level telemetry
- Filtering of `listen()` HOT 2
- Document how to export the registry as executable and then build a schema from that in prod
- What is the recommended way to validate input?
- Postgraphile@v5 keeps failing in a docker container HOT 3
- How to query a key that has ":" in the dictionary HOT 5
- Development mode warning printed when in test mode HOT 2
- @omit tag does not get emulated correctly in v5
- Allow adding validation rules to Grafserv HOT 2
- Smart tag to shortcut accessing an attribute from a related table
- Current enum value isn't present on GraphQLEnumType_values_value scope HOT 2
- Planned module: @dataplan/graphql HOT 4
- Grafast: garbage collection
- Grafast: hoisting of subroutines
- Exported PgCodec loses polymorphic information HOT 3
- `withPgClient` is intended for mutations - make it clear! HOT 4
- PostGraphile docs: ambiguous example in makeExtendSchemaPlugin docs
- Document grafserv/envelop integration and how to add validation rules
- Graphile Export: detect hasOwn keys set on functions that aren't exportable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crystal.