Skip to content
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

Make relationships subrequests #1

Closed
Paulmicha opened this issue Jun 27, 2019 · 4 comments
Closed

Make relationships subrequests #1

Paulmicha opened this issue Jun 27, 2019 · 4 comments

Comments

@Paulmicha
Copy link

Paulmicha commented Jun 27, 2019

I haven't looked into devour much yet, but I'm asking in case anyone has given this a thought already :

Would it make sense to extend or replace Devour's relationship feature (see https://github.com/twg/devour#relationships) to use subrequests (see https://github.com/e0ipso/subrequests-express) ?

Edit : context : section Improve performance using subrequests from this article : https://thebrainfiles.wearebrain.com/how-to-quickly-configure-drupal-as-a-decoupled-api-first-system-8730a3623388

@Auspicus
Copy link
Owner

@Paulmicha I don't think devour automatically populates relationships like that. You can do an include using the JSON:API standard ?include={relationship} and the relationships will be populated into their respective properties but AFAIK it doesn't fetch these recursively or in any way that is likely to impact performance.

@Auspicus
Copy link
Owner

Auspicus commented Jun 30, 2019

I'll go check the source to make sure they're not doing anything that might be a performance hit. If they're not I'll close this ticket and if they are maybe we can consider including @e0ipso's library or something similar.

In our higher level API drupal-jsonapi-client we have a .expand function which basically functions as a subrequest. You can use it to fetch a relationship async. If the relationship has been cached from a previous ?include then it will be fetched from cache, otherwise a separate request is made. eg:

const user = await Entity.Load('user', 'user', 'uuid', ['user_picture']) // include user_picture
const picture = await user.expand('user_picture') // fetched from cache

const user2 = await Entity.Load('user', 'user', 'uuid')
const picture2 = await user.expand('user_picture') // fetched as subrequest

@Auspicus
Copy link
Owner

@Paulmicha I read more into subrequests. They definitely have a lot of benefits, bundling multiple HTTP requests into one saves a lot of network latency.

I think this might be better handled in a higher level API. I don't see this library providing more than a binding to the JSON:API exported by Drupal. I've added a ticket to drupal-jsonapi-client to integrate devour-drupal and also look into bundling dependent requests into subrequests.

@e0ipso
Copy link

e0ipso commented Jul 1, 2019

I think this might be better handled in a higher level API. I don't see this library providing more than a binding to the JSON:API exported by Drupal.

I tend to agree with this sentiment. However, I don't think that it would be very disruptive to implement:

client.subrequestsCapture();
client.get(); // Prevents sending during capture mode.
client.post();
client.post();
client.subrequestsSend(); // Sends a single request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants