-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Version 2 RFC #125
Comments
I've also added more powerful exclude abilities // Skip individual calls. Overrides all other configs
app.service('users', { excludeBatch: true });
app.service('users', { excludeBatch: context => true });
// Configure batchClient/batch
batchClient({ batchService: 'batch', excludeBatch: ['users'] });
batchClient({ batchService: 'batch', excludeBatch: context => true });
// Configure services to ignore batching
app.use('users', memory({ excludeBatch: true }));
app.use('users', memory({ excludeBatch: context => true })); |
Some updates I have removed all server changes. I was misguided in my attempt to make this work differently on the server. I have some ideas about a similar feature that is similar to this that would work on the server and benefit loaders, but I don't think this is the right place for that idea. So the // `service` is a class that DUCKS like a regular service, but actually returns JSON args
// Returns Promise.all() like results, but throws with a real error
batchManager.all((service) => {
return [
service('users').get(1),
service('posts').find(),
// Still supports JSON args
['get', 'users', ...]
]
});
// `service` is a class that DUCKS like a regular service, but actually returns JSON args
// Returns Promise.allSettled() like results with real errors
batchManager.allSettled((service) => {
return [
service('users').get(1),
service('posts').find(),
// Still supports JSON args
['get', 'users', ...]
]
}); I have accomplished the following, which are all good things that could be shipped even w/o a major bump.
Problems A video of me rambling about this. I ran out of time again...but you get it. @daffl @marshallswain @fratzinger Any thoughts on this stuff? |
And a fun side note. Technically the This would require a new property of // server.js
..express/koa setup, etc
const exclude = (context) => {
// Maybe you want it to only work on the server
// Maybe you want it to only work on external requests...whatever
if (context.params.provider) {
return true;
}
// Maybe only work on get/find
if (!['get', 'find'].includes(context.method)) {
return true;
}
// Other basic stuff
if (context.path === 'authentication') {
return true;
}
return false;
}
const dedupeFn = (context) => {
return {
query: context.params.query,
user: context.params.user
}
}
app.configure(batchClient({
timeout: 5,
batchService: 'batch',
exclude: exclude,
dedupeFn: dedupeFn,
dedupe: true
})) |
There should also be a |
I have whipped up a new version on this package to add some features and solve some shortcomings of the current version. One of my main motivations in doing so is how well this package can work with the new version of
feathers-dataloader
. There is now good reason to use this package on the server because it allows sharing a dataloader across all batched services.Problem
Server
['create', 'users', ...]
arguments in thecalls
property. This means that to use it serverside, the developer has has to manually convert their calls to this syntax.Client
Solution
Server
1 - The batch service now accepts an array of promises and/or JSON config. This makes it much easier for the developer to use on the server.
2- Two convenience methods have been added that re-parse errors and shorten/familiarize the syntax.
service.all()
andservice.allSettled()
Client
There are 3 new solutions here to offer the developer more control over the batching process. 2 of them use a
BatchManager
. The third does not use theBatchManger
and is a very explicit way to create batches easily.1 - Manually create batches. This
batchMethods
plugin does not attempt to capture batches in aBatchManger
, instead it simply adds two methods to the client side batch service to make it easier to use. This is super low commitment from the developer and they don't have to worry about excluding services, skipping batch calls, timeouts, etc. Just a convenient way to make batches. But I don't love this...the wholeservice
callback thing is weird.2 - Rather than a plugin, the developer can use the
batchHook
directly. This allows them to use differentBatchManager
with different timeouts/configs across multiple services or even multiple methods. This is the most powerful solution, but also the most tedious to setup. Especially because many developers may not "set up" all of their remote services. This does not automatically addbatchMethods
, you would still need to use that plugin if you want those methods. This can be paired withbatchClient
because the hooks will override the batchClient's config, so it's nice to use both.3 - This is a rewrite of the
batchClient
to solve its main issue. Which was that it used anapp.before.all
hook. Instead the plugin now usesapp.mixins
to modify each service's methods to use theBatchManager
. This automatically places the batching mechanism in the right place so that all clientside hooks work as expected. This does not automatically addbatchMethods
, you would still need to use that plugin if you want those methods. This can be paired withbatchHook
. The hooks will override this manager.The text was updated successfully, but these errors were encountered: